1
0
forked from MTSR/mapserver
mapserver/server/static/js/overlays/TravelnetOverlay.js

97 lines
2.4 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 20:03:07 +03:00
this.currentObjects = [];
2019-02-02 19:40:52 +03:00
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 20:03:07 +03:00
if (this._map.getZoom() < 10) {
this.clearLayers();
this.currentObjects = [];
return;
}
2019-02-02 19:40:52 +03:00
if (full){
2019-02-01 15:46:41 +03:00
this.clearLayers();
2019-02-02 20:03:07 +03:00
this.currentObjects = [];
2019-02-02 19:40:52 +03:00
}
2019-02-01 15:46:41 +03:00
2019-02-02 20:03:07 +03:00
var mapLayer = this.layerMgr.getCurrentLayer()
var min = this._map.getBounds().getSouthWest();
var max = this._map.getBounds().getNorthEast();
var y1 = parseInt(mapLayer.from/16);
var y2 = parseInt(mapLayer.to/16);
var x1 = parseInt(min.lng);
var x2 = parseInt(max.lng);
var z1 = parseInt(min.lat);
var z2 = parseInt(max.lat);
2019-02-01 15:46:41 +03:00
//TODO: get coords
2019-02-02 20:03:07 +03:00
api.getMapObjects(
x1, y1, y1,
x2, y2, z2,
"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){
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 20:03:07 +03:00
this.clearLayers();
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
}
});