Skip to content

Commit 6814e29

Browse files
committed
support tiles in GeoJSON
1 parent 14ec222 commit 6814e29

File tree

3 files changed

+20
-227
lines changed

3 files changed

+20
-227
lines changed

examples/clients/leaflet/GeoJSONGridLayer.js

-196
This file was deleted.

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

+12-24
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,31 @@
1818

1919
createTile: function (coords) {
2020
var tile = L.DomUtil.create('div', 'leaflet-tile');
21+
tile.style['box-shadow'] = 'inset 0 0 2px #f00';
2122
var url = L.Util.template(this.url, coords);
2223
this.ajaxRequest('GET', url, false, this.updateLayers.bind(this));
2324
return tile;
2425
},
2526

26-
ajaxRequest: function(method, url, data, callback) {
27-
var request = new XMLHttpRequest();
28-
request.open(method, url, true);
29-
request.onreadystatechange = function() {
30-
if (request.readyState === 4 && request.status === 200) {
31-
callback(JSON.parse(request.responseText));
32-
}
33-
};
34-
if (data) {
35-
request.setRequestHeader('Content-type', 'application/json');
36-
request.send(JSON.stringify(data));
37-
} else {
38-
request.send();
39-
}
40-
return request;
41-
},
42-
4327
updateLayers: function(geoData) {
44-
this.layer.clearLayers();
45-
this.layer.addData(geoData);
28+
if (geoData.type == 'FeatureCollection'){
29+
for (var i=0;i<geoData.features.length;i++) {
30+
var id = geoData.features[i].id;
31+
if (!this.features[id]) {
32+
this.layer.addData(geoData.features[i]);
33+
this.features[id] = true;
34+
}
35+
}
36+
}
4637
},
4738

4839
onAdd(map) {
4940
L.GridLayer.prototype.onAdd.call(this, map);
5041
map.addLayer(this.layer);
5142
this.map = map;
52-
//map.on('moveend zoomend refresh', this.reloadMap, this);
53-
//this.reloadMap();
5443
},
5544

5645
onRemove(map) {
57-
//map.off('moveend zoomend refresh', this.reloadMap, this);
5846
this.map = null;
5947
map.removeLayer(this.layer)
6048
L.GridLayer.prototype.onRemove.call(this, map);
@@ -79,8 +67,8 @@
7967

8068
});
8169

82-
L.geoJSONTileLayer = function (options) {
83-
return new L.GeoJSONTileLayer(options);
70+
L.geoJSONTileLayer = function (url, options) {
71+
return new L.GeoJSONTileLayer(url, options);
8472
};
8573

8674
}).call(this);

examples/clients/leaflet/vanilla.html

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
1313
<script src="geojson-layer.js"></script>
1414
<script src="geojson-tile-layer.js"></script>
15+
<!--<script src="geojson-tile-layer.js"></script>-->
1516
</head>
1617
<body>
1718

1819
<div id="mapid" style="width: 600px; height: 400px;"></div>
1920
<script>
2021
var mymap = L.map('mapid').setView([20, 30], 3);
2122

22-
//L.tileLayer('https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', {
23-
// maxZoom: 18,
24-
//}).addTo(mymap);
23+
L.tileLayer('https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', {
24+
maxZoom: 18,
25+
}).addTo(mymap);
2526

26-
//L.geoJSONLayer('http://localhost:8000/api.php/geojson/countries/1,2?bbox={bbox}', {
27-
// maxZoom: 18,
28-
//}).addTo(mymap);
27+
L.geoJSONLayer('http://localhost:8000/api.php/geojson/users?bbox={bbox}', {
28+
maxZoom: 18,
29+
}).addTo(mymap);
2930

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

0 commit comments

Comments
 (0)