Skip to content

Commit a258df3

Browse files
committed
support tiles in GeoJSON
1 parent 4063d3b commit a258df3

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

examples/clients/leaflet/geojson-tile-layer.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232

3333
updateLayers: function(url, geoData) {
3434
if (geoData.type == 'FeatureCollection'){
35-
for (var i=0;i<geoData.features.length;i++) {
36-
var id = geoData.features[i].id;
37-
if (!this.features[id]) {
38-
this.layer.addData(geoData.features[i]);
39-
this.features[id] = true;
40-
}
35+
geoData = geoData.features;
36+
}
37+
for (var i=0;i<geoData.length;i++) {
38+
var id = geoData[i].id;
39+
if (!this.features[id]) {
40+
this.layer.addData(geoData[i]);
41+
this.features[id] = true;
4142
}
4243
}
4344
if (!this.cache[url]) {
@@ -49,9 +50,11 @@
4950
L.GridLayer.prototype.onAdd.call(this, map);
5051
map.addLayer(this.layer);
5152
this.map = map;
53+
map.on('zoomanim', this.onZoomAnim.bind(this));
5254
},
5355

5456
onRemove(map) {
57+
map.off('zoomanim', this.onZoomAnim.bind(this));
5558
this.map = null;
5659
map.removeLayer(this.layer)
5760
L.GridLayer.prototype.onRemove.call(this, map);
@@ -74,6 +77,16 @@
7477
return request;
7578
},
7679

80+
onZoomAnim: function (e) {
81+
var zoom = e.zoom;
82+
if ((this.options.maxZoom && zoom > this.options.maxZoom) ||
83+
(this.options.minZoom && zoom < this.options.minZoom)) {
84+
this.map.removeLayer(this.layer);
85+
} else {
86+
this.map.addLayer(this.layer);
87+
}
88+
},
89+
7790
});
7891

7992
L.geoJSONTileLayer = function (url, options) {

examples/clients/leaflet/vanilla.html

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
}).addTo(mymap);
2929

3030
L.geoJSONTileLayer('http://localhost:8000/src/geojson/countries?filter=id,lt,3&tile={z},{x},{y}', {
31+
minZoom: 3,
3132
maxZoom: 18,
3233
}).addTo(mymap);
3334
</script>

0 commit comments

Comments
 (0)