mapserver/server/static/js/overlays/TravelnetOverlay.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-02-01 14:58:26 +03:00
'use strict';
2019-01-29 20:08:54 +03:00
2019-02-01 14:58:26 +03:00
var TravelnetIcon = L.icon({
iconUrl: 'pics/travelnet_inv.png',
2019-01-29 20:08:54 +03:00
2019-02-01 14:58:26 +03:00
iconSize: [64, 64],
iconAnchor: [32, 32],
popupAnchor: [0, -32]
});
2019-01-29 20:08:54 +03:00
2019-02-01 14:58:26 +03:00
var TravelnetOverlay = L.LayerGroup.extend({
2019-02-01 15:20:50 +03:00
initialize: function(wsChannel, layerMgr) {
2019-02-02 19:28:35 +03:00
L.LayerGroup.prototype.initialize.call(this);
2019-02-01 15:28:26 +03:00
this.layerMgr = layerMgr;
this.wsChannel = wsChannel;
2019-01-29 23:07:29 +03:00
2019-02-02 19:40:52 +03:00
this.currentLayers = [];
2019-02-01 15:28:26 +03:00
this.onLayerChange = this.onLayerChange.bind(this);
2019-02-02 19:28:35 +03:00
this.onMapMove = debounce(this.onMapMove.bind(this), 50);
2019-02-01 15:28:26 +03:00
},
onLayerChange: function(layer){
2019-02-01 15:46:41 +03:00
this.reDraw(true);
2019-02-01 14:58:26 +03:00
},
2019-01-29 23:07:29 +03:00
2019-02-01 15:46:41 +03:00
onMapMove: function(){
this.reDraw(false);
},
2019-02-01 15:28:26 +03:00
2019-02-01 15:46:41 +03:00
reDraw: function(full){
var self = this;
2019-01-29 20:08:54 +03:00
2019-02-02 19:40:52 +03:00
if (full){
2019-02-01 15:46:41 +03:00
this.clearLayers();
2019-02-02 19:40:52 +03:00
this.currentLayers = [];
}
2019-02-01 15:46:41 +03:00
//TODO: get coords
2019-02-01 14:58:26 +03:00
api.getMapObjects(-10,-10,-10,10,10,10,"travelnet")
2019-02-01 15:46:41 +03:00
.then(function(travelnets){
//TODO: remove non-existing markers, add new ones
2019-02-02 19:40:52 +03:00
if (!full){
2019-02-02 19:28:35 +03:00
self.clearLayers();
2019-02-02 19:40:52 +03:00
}
2019-02-01 15:46:41 +03:00
2019-02-02 19:28:35 +03:00
travelnets.forEach(function(travelnet){
2019-02-01 15:46:41 +03:00
2019-02-02 19:28:35 +03:00
console.log(travelnet);
2019-02-01 15:46:41 +03:00
2019-02-02 19:28:35 +03:00
var popup = "<h4>" + travelnet.attributes.station_name + "</h4><hr>" +
2019-02-01 15:46:41 +03:00
"<b>X: </b> " + travelnet.x + "<br>" +
"<b>Y: </b> " + travelnet.y + "<br>" +
"<b>Z: </b> " + travelnet.z + "<br>" +
2019-02-02 19:28:35 +03:00
"<b>Network: </b> " + travelnet.attributes.station_network + "<br>" +
"<b>Owner: </b> " + travelnet.attributes.owner + "<br>";
2019-02-01 15:46:41 +03:00
2019-02-02 19:28:35 +03:00
var marker = L.marker([travelnet.z, travelnet.x], {icon: TravelnetIcon});
2019-02-01 15:46:41 +03:00
marker.bindPopup(popup).addTo(self);
});
2019-02-01 14:58:26 +03:00
})
2019-02-01 15:46:41 +03:00
},
onAdd: function(map) {
2019-02-02 19:28:35 +03:00
map.on("zoomend", this.onMapMove);
map.on("moveend", this.onMapMove);
2019-02-01 15:46:41 +03:00
this.layerMgr.addListener(this.onLayerChange);
2019-02-02 19:28:35 +03:00
this.reDraw(true)
2019-02-01 14:58:26 +03:00
},
onRemove: function(map) {
2019-02-02 19:28:35 +03:00
map.off("zoomend", this.onMapMove);
map.off("moveend", this.onMapMove);
2019-02-01 15:28:26 +03:00
this.layerMgr.removeListener(this.onLayerChange);
2019-02-01 14:58:26 +03:00
}
});