support tiles in GeoJSON

This commit is contained in:
Maurits van der Schee 2019-07-04 02:39:15 +02:00
commit a258df3604
2 changed files with 20 additions and 6 deletions

View file

@ -32,12 +32,13 @@
updateLayers: function(url, geoData) {
if (geoData.type == 'FeatureCollection'){
for (var i=0;i<geoData.features.length;i++) {
var id = geoData.features[i].id;
if (!this.features[id]) {
this.layer.addData(geoData.features[i]);
this.features[id] = true;
}
geoData = geoData.features;
}
for (var i=0;i<geoData.length;i++) {
var id = geoData[i].id;
if (!this.features[id]) {
this.layer.addData(geoData[i]);
this.features[id] = true;
}
}
if (!this.cache[url]) {
@ -49,9 +50,11 @@
L.GridLayer.prototype.onAdd.call(this, map);
map.addLayer(this.layer);
this.map = map;
map.on('zoomanim', this.onZoomAnim.bind(this));
},
onRemove(map) {
map.off('zoomanim', this.onZoomAnim.bind(this));
this.map = null;
map.removeLayer(this.layer)
L.GridLayer.prototype.onRemove.call(this, map);
@ -74,6 +77,16 @@
return request;
},
onZoomAnim: function (e) {
var zoom = e.zoom;
if ((this.options.maxZoom && zoom > this.options.maxZoom) ||
(this.options.minZoom && zoom < this.options.minZoom)) {
this.map.removeLayer(this.layer);
} else {
this.map.addLayer(this.layer);
}
},
});
L.geoJSONTileLayer = function (url, options) {

View file

@ -28,6 +28,7 @@
}).addTo(mymap);
L.geoJSONTileLayer('http://localhost:8000/src/geojson/countries?filter=id,lt,3&tile={z},{x},{y}', {
minZoom: 3,
maxZoom: 18,
}).addTo(mymap);
</script>