Skip to content

Commit 8daaf21

Browse files
committed
support tiles in GeoJSON
1 parent b6efffe commit 8daaf21

File tree

3 files changed

+71
-185
lines changed

3 files changed

+71
-185
lines changed

examples/clients/leaflet/geojson-layer.js

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,79 @@
33

44
L.GeoJSONLayer = L.GeoJSON.extend({
55

6-
includes: L.Evented.prototype,
6+
includes: L.Evented.prototype,
77

8-
map: null,
8+
map: null,
99

10-
options: {
11-
},
10+
options: {
11+
},
1212

13-
initialize(extraOptions, options) {
14-
L.GeoJSON.prototype.initialize.call(this, [], options);
15-
L.Util.setOptions(this, extraOptions);
16-
},
13+
initialize(extraOptions, options) {
14+
L.GeoJSON.prototype.initialize.call(this, [], options);
15+
L.Util.setOptions(this, extraOptions);
16+
},
1717

18-
_reload: function() {
19-
if (this.map) {
20-
var url = this._expand(this.options.url);
21-
this._ajax('GET', url, false, this._update.bind(this));
22-
}
23-
},
18+
_reload: function() {
19+
if (this.map) {
20+
var url = this._expand(this.options.url);
21+
this._ajax('GET', url, false, this._update.bind(this));
22+
}
23+
},
2424

25-
_update: function(geoData) {
26-
this.clearLayers();
27-
this.addData(geoData);
28-
},
25+
_update: function(geoData) {
26+
this.clearLayers();
27+
this.addData(geoData);
28+
},
2929

30-
onAdd: function(map) {
31-
L.GeoJSON.prototype.onAdd.call(this, map);
32-
this.map = map;
33-
map.on('moveend zoomend refresh', this._reload, this);
34-
this._reload();
35-
},
30+
onAdd: function(map) {
31+
L.GeoJSON.prototype.onAdd.call(this, map);
32+
this.map = map;
33+
map.on('moveend zoomend refresh', this._reload, this);
34+
this._reload();
35+
},
3636

37-
onRemove: function(map) {
38-
map.off('moveend zoomend refresh', this._reload, this);
39-
this.map = null;
40-
L.GeoJSON.prototype.onRemove.call(this, map);
41-
},
37+
onRemove: function(map) {
38+
map.off('moveend zoomend refresh', this._reload, this);
39+
this.map = null;
40+
L.GeoJSON.prototype.onRemove.call(this, map);
41+
},
4242

43-
_expand: function(template) {
44-
var bbox = this._map.getBounds();
45-
var southWest = bbox.getSouthWest();
46-
var northEast = bbox.getNorthEast();
47-
var bboxStr = bbox.toBBoxString();
48-
var coords = {
49-
lat1: southWest.lat,
50-
lon1: southWest.lng,
51-
lat2: northEast.lat,
52-
lon2: northEast.lng,
53-
bbox: bboxStr
54-
};
55-
return L.Util.template(template, coords);
56-
},
43+
_expand: function(template) {
44+
var bbox = this._map.getBounds();
45+
var southWest = bbox.getSouthWest();
46+
var northEast = bbox.getNorthEast();
47+
var bboxStr = bbox.toBBoxString();
48+
var coords = {
49+
lat1: southWest.lat,
50+
lon1: southWest.lng,
51+
lat2: northEast.lat,
52+
lon2: northEast.lng,
53+
bbox: bboxStr
54+
};
55+
return L.Util.template(template, coords);
56+
},
5757

58-
_ajax: function(method, url, data, callback) {
59-
var request = new XMLHttpRequest();
60-
request.open(method, url, true);
61-
request.onreadystatechange = function() {
62-
if (request.readyState === 4 && request.status === 200) {
63-
callback(JSON.parse(request.responseText));
64-
}
65-
};
66-
if (data) {
67-
request.setRequestHeader('Content-type', 'application/json');
68-
request.send(JSON.stringify(data));
69-
} else {
70-
request.send();
71-
}
72-
return request;
73-
},
58+
_ajax: function(method, url, data, callback) {
59+
var request = new XMLHttpRequest();
60+
request.open(method, url, true);
61+
request.onreadystatechange = function() {
62+
if (request.readyState === 4 && request.status === 200) {
63+
callback(JSON.parse(request.responseText));
64+
}
65+
};
66+
if (data) {
67+
request.setRequestHeader('Content-type', 'application/json');
68+
request.send(JSON.stringify(data));
69+
} else {
70+
request.send();
71+
}
72+
return request;
73+
},
7474

75-
});
75+
});
7676

77-
L.geoJSONLayer = function (options) {
78-
return new L.GeoJSONLayer(options);
79-
};
77+
L.geoJSONLayer = function (options) {
78+
return new L.GeoJSONLayer(options);
79+
};
8080

81-
}).call(this);
81+
})();

examples/clients/leaflet/vanilla.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"/>
1212
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
1313
<script src="geojson-layer.js"></script>
14-
<!--<script src="vector-tile-layer.js"></script>-->
14+
<script src="geojson-tile-layer.js"></script>
1515
</head>
1616
<body>
1717

@@ -23,13 +23,13 @@
2323
maxZoom: 18,
2424
}).addTo(mymap);
2525

26-
L.geoJSONLayer({
27-
url: "http://localhost:8000/api.php/geojson/countries/1,2?bbox={bbox}",
28-
}).addTo(mymap);
26+
//L.geoJSONLayer({
27+
// url: "http://localhost:8000/api.php/geojson/countries/1,2?bbox={bbox}",
28+
//}).addTo(mymap);
2929

30-
// L.vectorTileLayer('http://localhost:8000/api.php/geojson/countries/1,2?tile={z},{y},{x}', {
31-
// maxZoom: 18,
32-
// }).addTo(mymap);
30+
L.geoJSONTileLayer('http://localhost:8000/api.php/geojson/countries/1,2?tile={z},{y},{x}', {
31+
maxZoom: 18,
32+
}).addTo(mymap);
3333
</script>
3434

3535
</body>

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

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)