Skip to content

Commit 4063d3b

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

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@
88
url: null,
99
layer: null,
1010
features: null,
11+
cache: null,
1112

1213
initialize(url, options) {
1314
this.url = url;
1415
this.layer = new L.GeoJSON(null, options);
1516
this.features = {};
17+
this.cache = {};
1618
L.GridLayer.prototype.initialize.call(this, options);
1719
},
1820

1921
createTile: function (coords) {
2022
var tile = L.DomUtil.create('div', 'leaflet-tile');
2123
tile.style['box-shadow'] = 'inset 0 0 2px #f00';
2224
var url = L.Util.template(this.url, coords);
23-
this.ajaxRequest('GET', url, false, this.updateLayers.bind(this));
25+
if (this.cache[url]) {
26+
this.updateLayers(url, this.cache[url]);
27+
} else {
28+
this.ajaxRequest('GET', url, false, this.updateLayers.bind(this, url));
29+
}
2430
return tile;
2531
},
2632

27-
updateLayers: function(geoData) {
33+
updateLayers: function(url, geoData) {
2834
if (geoData.type == 'FeatureCollection'){
2935
for (var i=0;i<geoData.features.length;i++) {
3036
var id = geoData.features[i].id;
@@ -33,7 +39,10 @@
3339
this.features[id] = true;
3440
}
3541
}
36-
}
42+
}
43+
if (!this.cache[url]) {
44+
this.cache[url] = geoData;
45+
}
3746
},
3847

3948
onAdd(map) {

examples/clients/leaflet/vanilla.html

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
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>-->
1615
</head>
1716
<body>
1817

0 commit comments

Comments
 (0)