|
@@ -6,10 +6,14 @@
|
6
|
6
|
includes: L.Evented.prototype,
|
7
|
7
|
|
8
|
8
|
url: null,
|
|
9
|
+ map: null,
|
9
|
10
|
layer: null,
|
10
|
11
|
features: null,
|
11
|
12
|
cache: null,
|
12
|
13
|
|
|
14
|
+ //
|
|
15
|
+ // Leaflet layer methods
|
|
16
|
+ //
|
13
|
17
|
initialize(url, options) {
|
14
|
18
|
this.url = url;
|
15
|
19
|
this.layer = new L.GeoJSON(null, options);
|
|
@@ -23,14 +27,31 @@
|
23
|
27
|
tile.style['box-shadow'] = 'inset 0 0 2px #f00';
|
24
|
28
|
var url = L.Util.template(this.url, coords);
|
25
|
29
|
if (this.cache[url]) {
|
26
|
|
- this.updateLayers(url, this.cache[url]);
|
|
30
|
+ this._updateLayers(url, this.cache[url]);
|
27
|
31
|
} else {
|
28
|
|
- this.ajaxRequest('GET', url, false, this.updateLayers.bind(this, url));
|
|
32
|
+ this._ajaxRequest('GET', url, false, this._updateLayers.bind(this, url));
|
29
|
33
|
}
|
30
|
34
|
return tile;
|
31
|
35
|
},
|
32
|
36
|
|
33
|
|
- updateLayers: function(url, geoData) {
|
|
37
|
+ onAdd(map) {
|
|
38
|
+ L.GridLayer.prototype.onAdd.call(this, map);
|
|
39
|
+ map.addLayer(this.layer);
|
|
40
|
+ this.map = map;
|
|
41
|
+ map.on('zoomanim', this._onZoomAnim.bind(this));
|
|
42
|
+ },
|
|
43
|
+
|
|
44
|
+ onRemove(map) {
|
|
45
|
+ map.off('zoomanim', this._onZoomAnim.bind(this));
|
|
46
|
+ this.map = null;
|
|
47
|
+ map.removeLayer(this.layer)
|
|
48
|
+ L.GridLayer.prototype.onRemove.call(this, map);
|
|
49
|
+ },
|
|
50
|
+
|
|
51
|
+ //
|
|
52
|
+ // Custom methods
|
|
53
|
+ //
|
|
54
|
+ _updateLayers: function(url, geoData) {
|
34
|
55
|
if (geoData.type == 'FeatureCollection'){
|
35
|
56
|
geoData = geoData.features;
|
36
|
57
|
}
|
|
@@ -46,21 +67,7 @@
|
46
|
67
|
}
|
47
|
68
|
},
|
48
|
69
|
|
49
|
|
- onAdd(map) {
|
50
|
|
- L.GridLayer.prototype.onAdd.call(this, map);
|
51
|
|
- map.addLayer(this.layer);
|
52
|
|
- this.map = map;
|
53
|
|
- map.on('zoomanim', this.onZoomAnim.bind(this));
|
54
|
|
- },
|
55
|
|
-
|
56
|
|
- onRemove(map) {
|
57
|
|
- map.off('zoomanim', this.onZoomAnim.bind(this));
|
58
|
|
- this.map = null;
|
59
|
|
- map.removeLayer(this.layer)
|
60
|
|
- L.GridLayer.prototype.onRemove.call(this, map);
|
61
|
|
- },
|
62
|
|
-
|
63
|
|
- ajaxRequest: function(method, url, data, callback) {
|
|
70
|
+ _ajaxRequest: function(method, url, data, callback) {
|
64
|
71
|
var request = new XMLHttpRequest();
|
65
|
72
|
request.open(method, url, true);
|
66
|
73
|
request.onreadystatechange = function() {
|
|
@@ -77,7 +84,7 @@
|
77
|
84
|
return request;
|
78
|
85
|
},
|
79
|
86
|
|
80
|
|
- onZoomAnim: function (e) {
|
|
87
|
+ _onZoomAnim: function (e) {
|
81
|
88
|
var zoom = e.zoom;
|
82
|
89
|
if ((this.options.maxZoom && zoom > this.options.maxZoom) ||
|
83
|
90
|
(this.options.minZoom && zoom < this.options.minZoom)) {
|
|
@@ -85,12 +92,11 @@
|
85
|
92
|
} else {
|
86
|
93
|
this.map.addLayer(this.layer);
|
87
|
94
|
}
|
88
|
|
- },
|
89
|
|
-
|
|
95
|
+ }
|
90
|
96
|
});
|
91
|
97
|
|
92
|
98
|
L.geoJSONTileLayer = function (url, options) {
|
93
|
99
|
return new L.GeoJSONTileLayer(url, options);
|
94
|
100
|
};
|
95
|
101
|
|
96
|
|
-}).call(this);
|
|
102
|
+})();
|