|
@@ -8,11 +8,13 @@
|
8
|
8
|
url: null,
|
9
|
9
|
layer: null,
|
10
|
10
|
features: null,
|
|
11
|
+ cache: null,
|
11
|
12
|
|
12
|
13
|
initialize(url, options) {
|
13
|
14
|
this.url = url;
|
14
|
15
|
this.layer = new L.GeoJSON(null, options);
|
15
|
16
|
this.features = {};
|
|
17
|
+ this.cache = {};
|
16
|
18
|
L.GridLayer.prototype.initialize.call(this, options);
|
17
|
19
|
},
|
18
|
20
|
|
|
@@ -20,11 +22,15 @@
|
20
|
22
|
var tile = L.DomUtil.create('div', 'leaflet-tile');
|
21
|
23
|
tile.style['box-shadow'] = 'inset 0 0 2px #f00';
|
22
|
24
|
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
|
+ }
|
24
|
30
|
return tile;
|
25
|
31
|
},
|
26
|
32
|
|
27
|
|
- updateLayers: function(geoData) {
|
|
33
|
+ updateLayers: function(url, geoData) {
|
28
|
34
|
if (geoData.type == 'FeatureCollection'){
|
29
|
35
|
for (var i=0;i<geoData.features.length;i++) {
|
30
|
36
|
var id = geoData.features[i].id;
|
|
@@ -33,7 +39,10 @@
|
33
|
39
|
this.features[id] = true;
|
34
|
40
|
}
|
35
|
41
|
}
|
36
|
|
- }
|
|
42
|
+ }
|
|
43
|
+ if (!this.cache[url]) {
|
|
44
|
+ this.cache[url] = geoData;
|
|
45
|
+ }
|
37
|
46
|
},
|
38
|
47
|
|
39
|
48
|
onAdd(map) {
|