Skip to content

Commit

Permalink
Merge pull request #2443 from tonio/tile-vector
Browse files Browse the repository at this point in the history
More data in tile-vector examples
  • Loading branch information
tonio committed Aug 18, 2014
2 parents b92a033 + 49299df commit 344452b
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
16 changes: 16 additions & 0 deletions examples/tile-vector.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
<title>Tile vector example</title>
<style>
#map {
max-width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>

Expand Down Expand Up @@ -36,6 +42,16 @@ <h4 id="title">Tile vector example</h4>
<div id="docs">
<p>See the <a href="tile-vector.js" target="_blank">tile-vector.js source</a> to see how this is done.</p>
</div>
<div class="alert">
<strong>Warning</strong> Map is becoming unresponsive with too many layers.
</div>
<fieldset>
<legend>Layers</legend>
<label class="checkbox"><input type="checkbox" id="landuse"/> Landuse</label>
<label class="checkbox"><input type="checkbox" id="buildings"/> Buildings</label>
<label class="checkbox"><input type="checkbox" id="water" checked/> Water</label>
<label class="checkbox"><input type="checkbox" id="roads" checked/> Roads</label>
</fieldset>
<div id="tags">tile-vector, openstreetmap</div>
</div>

Expand Down
92 changes: 90 additions & 2 deletions examples/tile-vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,101 @@ var roadLayer = new ol.layer.Vector({
}
});

var buildingStyle = [
new ol.style.Style({
fill: new ol.style.Fill({
color: '#666',
opacity: 0.4
}),
stroke: new ol.style.Stroke({
color: '#444',
width: 1
})
})
];
var buildingLayer = new ol.layer.Vector({
source: new ol.source.TileVector({
format: new ol.format.TopoJSON({
defaultProjection: 'EPSG:4326'
}),
projection: 'EPSG:3857',
tileGrid: new ol.tilegrid.XYZ({
maxZoom: 19
}),
url: 'http://{a-c}.tile.openstreetmap.us/' +
'vectiles-buildings/{z}/{x}/{y}.topojson'
}),
visible: false,
style: function(f, resolution) {
return (resolution < 10) ? buildingStyle : [];
}
});

var landuseStyleCache = {};
var landuseLayer = new ol.layer.Vector({
source: new ol.source.TileVector({
format: new ol.format.TopoJSON({
defaultProjection: 'EPSG:4326'
}),
projection: 'EPSG:3857',
tileGrid: new ol.tilegrid.XYZ({
maxZoom: 19
}),
url: 'http://{a-c}.tile.openstreetmap.us/' +
'vectiles-land-usages/{z}/{x}/{y}.topojson'
}),
visible: false,
style: function(feature, resolution) {
var kind = feature.get('kind');
var styleKey = kind;
var styleArray = landuseStyleCache[styleKey];
if (!styleArray) {
var color, width;
color = {
'parking': '#ddd',
'industrial': '#aaa',
'urban area': '#aaa',
'park': '#76C759',
'school': '#DA10E7',
'garden': '#76C759',
'pitch': '#D58F8D',
'scrub': '#3E7D28',
'residential': '#4C9ED9'
}[kind];
width = kind == 'highway' ? 1.5 : 1;
styleArray = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: color,
width: width
}),
fill: new ol.style.Fill({
color: color,
opacity: 0.5
})
})];
landuseStyleCache[styleKey] = styleArray;
}
return styleArray;
}
});

var map = new ol.Map({
layers: [waterLayer, roadLayer],
layers: [landuseLayer, buildingLayer, waterLayer, roadLayer],
renderer: 'canvas',
target: document.getElementById('map'),
view: new ol.View({
center: ol.proj.transform([-74.0064, 40.7142], 'EPSG:4326', 'EPSG:3857'),
maxZoom: 19,
zoom: 14
zoom: 15
})
});

$('input[type=checkbox]').on('change', function() {
var layer = {
landuse: landuseLayer,
buildings: buildingLayer,
water: waterLayer,
roads: roadLayer
}[$(this).attr('id')];
layer.setVisible(!layer.getVisible());
});

0 comments on commit 344452b

Please sign in to comment.