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

70 lines
1.7 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-01 15:28:26 +03:00
this.layerMgr = layerMgr;
this.wsChannel = wsChannel;
2019-01-29 23:07:29 +03:00
2019-02-01 15:28:26 +03:00
this.onLayerChange = this.onLayerChange.bind(this);
2019-02-01 15:46:41 +03:00
this.onMapMove = this.onMapMove.bind(this);
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-01 15:46:41 +03:00
if (full)
this.clearLayers();
//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
if (!full)
this.clearLayers();
console.log(travelnets);
//TODO: attributes, coords
var marker = L.marker([travelnet.z, travelnet.x], {icon: TravelnetIcon});
travelnets.forEach(function(travelnet){
var popup = "<h4>" + travelnet.name + "</h4><hr>" +
"<b>X: </b> " + travelnet.x + "<br>" +
"<b>Y: </b> " + travelnet.y + "<br>" +
"<b>Z: </b> " + travelnet.z + "<br>" +
"<b>Network: </b> " + travelnet.network + "<br>" +
"<b>Owner: </b> " + travelnet.owner + "<br>";
marker.bindPopup(popup).addTo(self);
});
2019-02-01 14:58:26 +03:00
})
2019-02-01 15:46:41 +03:00
},
onAdd: function(map) {
this.layerMgr.addListener(this.onLayerChange);
console.log("TravelnetOverlay.onAdd", map);
2019-02-01 14:58:26 +03:00
},
onRemove: function(map) {
2019-02-01 15:28:26 +03:00
this.layerMgr.removeListener(this.onLayerChange);
2019-02-01 14:58:26 +03:00
console.log("TravelnetOverlay.onRemove");
}
});