Browse Source

support tiles in GeoJSON

Maurits van der Schee 6 years ago
parent
commit
4063d3be0f

+ 12
- 3
examples/clients/leaflet/geojson-tile-layer.js View File

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

+ 0
- 1
examples/clients/leaflet/vanilla.html View File

12
     <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script>
12
     <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script>
13
 	<script src="geojson-layer.js"></script>
13
 	<script src="geojson-layer.js"></script>
14
 	<script src="geojson-tile-layer.js"></script>
14
 	<script src="geojson-tile-layer.js"></script>
15
-	<!--<script src="geojson-tile-layer.js"></script>-->
16
 </head>
15
 </head>
17
 <body>
16
 <body>
18
 
17
 

Loading…
Cancel
Save