forked from brandonxiang/vtgeojson-heatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (44 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
L.VtGeojsonHeat = L.GridLayer.extend({
initialize: function (map, options) {
this.initFeatureCollection();
this._heat = L.heatLayer([]).addTo(map);
this._zoom = map.getZoom();
L.setOptions(this, options);
},
createTile: function (coords, done) {
var tile = [coords.x, coords.y, coords.z]
this.vt2geojson(tile)
return L.DomUtil.create("div");
},
initFeatureCollection:function(){
this._featurecollection = {
type: 'FeatureCollection',
features: []
}
},
getFeatureCollection:function(){
return this._featurecollection;
},
vt2geojson: function (tile) {
if(this._zoom !== tile[2]){
this._zoom = tile[2];
this.initFeatureCollection();
this._heat._latlngs= [];
}
var that = this;
var layers = 'poi_label'
var tiles = "tilejson+http://localhost:8000/tilejson.json"
vtgeojson(tiles, {
tiles: [tile],
layers: layers ? layers.split(',') : undefined
})
.on('data', function (data) {
that._featurecollection.features.push(data)
var coord = [data.geometry.coordinates[1], data.geometry.coordinates[0]];
that._heat.addLatLng(coord);
})
}
});
L.vtGeojsonHeat = function (map, options) {
return new L.VtGeojsonHeat(map, options);
}