2019-02-07 09:56:52 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var AbstractGeoJsonOverlay = L.LayerGroup.extend({
|
|
|
|
initialize: function(wsChannel, layerMgr, type) {
|
|
|
|
L.LayerGroup.prototype.initialize.call(this);
|
|
|
|
|
|
|
|
this.layerMgr = layerMgr;
|
|
|
|
this.wsChannel = wsChannel;
|
|
|
|
this.type = type;
|
|
|
|
|
|
|
|
this.onLayerChange = this.onLayerChange.bind(this);
|
|
|
|
this.onMapMove = debounce(this.onMapMove.bind(this), 50);
|
|
|
|
},
|
|
|
|
|
|
|
|
onLayerChange: function(layer){
|
|
|
|
this.reDraw();
|
|
|
|
},
|
|
|
|
|
|
|
|
onMapMove: function(){
|
|
|
|
this.reDraw();
|
|
|
|
},
|
|
|
|
|
2019-02-25 15:01:15 +03:00
|
|
|
createStyle: function(feature){
|
2019-04-02 16:00:42 +03:00
|
|
|
//TODO: default style
|
2019-02-25 15:01:15 +03:00
|
|
|
},
|
|
|
|
|
2019-02-07 09:56:52 +03:00
|
|
|
createGeoJson: function(objects){
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var geoJsonLayer = L.geoJSON([], {
|
|
|
|
onEachFeature: function(feature, layer){
|
|
|
|
if (feature.properties && feature.properties.popupContent) {
|
2019-02-08 13:05:22 +03:00
|
|
|
layer.bindPopup(feature.properties.popupContent);
|
|
|
|
}
|
2019-02-25 15:01:15 +03:00
|
|
|
},
|
2019-04-02 16:00:42 +03:00
|
|
|
style: self.createStyle.bind(self)
|
2019-02-07 09:56:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
objects.forEach(function(obj){
|
|
|
|
geoJsonLayer.addData(self.createFeature(obj));
|
|
|
|
});
|
|
|
|
|
|
|
|
return geoJsonLayer;
|
|
|
|
},
|
|
|
|
|
|
|
|
reDraw: function(){
|
|
|
|
var self = this;
|
|
|
|
|
2019-02-08 13:05:22 +03:00
|
|
|
if (this.map.getZoom() < 10) {
|
2019-02-07 09:56:52 +03:00
|
|
|
this.clearLayers();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:05:22 +03:00
|
|
|
var mapLayer = this.layerMgr.getCurrentLayer();
|
2019-02-07 09:56:52 +03:00
|
|
|
var min = this._map.getBounds().getSouthWest();
|
|
|
|
var max = this._map.getBounds().getNorthEast();
|
|
|
|
|
2019-03-29 21:21:27 +03:00
|
|
|
var y1 = parseInt(mapLayer.from);
|
|
|
|
var y2 = parseInt(mapLayer.to);
|
2019-02-22 20:30:38 +03:00
|
|
|
var x1 = parseInt(min.lng/16);
|
|
|
|
var x2 = parseInt(max.lng/16);
|
|
|
|
var z1 = parseInt(min.lat/16);
|
|
|
|
var z2 = parseInt(max.lat/16);
|
2019-02-07 09:56:52 +03:00
|
|
|
|
2019-02-22 16:57:40 +03:00
|
|
|
api.getMapObjects({
|
|
|
|
pos1: { x:x1, y:y1, z:z1 },
|
|
|
|
pos2: { x:x2, y:y2, z:z2 },
|
|
|
|
type: this.type
|
|
|
|
})
|
2019-02-07 09:56:52 +03:00
|
|
|
.then(function(objects){
|
|
|
|
self.clearLayers();
|
|
|
|
|
2019-02-08 23:00:39 +03:00
|
|
|
var geoJsonLayer = self.createGeoJson(objects);
|
2019-02-07 09:56:52 +03:00
|
|
|
geoJsonLayer.addTo(self);
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onAdd: function(map) {
|
2019-02-08 13:05:22 +03:00
|
|
|
this.map = map;
|
2019-02-07 09:56:52 +03:00
|
|
|
map.on("zoomend", this.onMapMove);
|
|
|
|
map.on("moveend", this.onMapMove);
|
|
|
|
this.layerMgr.addListener(this.onLayerChange);
|
|
|
|
this.reDraw(true)
|
|
|
|
},
|
|
|
|
|
|
|
|
onRemove: function(map) {
|
|
|
|
this.clearLayers();
|
|
|
|
map.off("zoomend", this.onMapMove);
|
|
|
|
map.off("moveend", this.onMapMove);
|
|
|
|
this.layerMgr.removeListener(this.onLayerChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|