1
0
forked from MTSR/mapserver

dynamic overlay query

This commit is contained in:
Thomas Rudin 2019-02-02 18:03:07 +01:00
parent 481c9477bb
commit c87027931c

View File

@ -15,7 +15,7 @@ var TravelnetOverlay = L.LayerGroup.extend({
this.layerMgr = layerMgr; this.layerMgr = layerMgr;
this.wsChannel = wsChannel; this.wsChannel = wsChannel;
this.currentLayers = []; this.currentObjects = [];
this.onLayerChange = this.onLayerChange.bind(this); this.onLayerChange = this.onLayerChange.bind(this);
this.onMapMove = debounce(this.onMapMove.bind(this), 50); this.onMapMove = debounce(this.onMapMove.bind(this), 50);
@ -32,13 +32,33 @@ var TravelnetOverlay = L.LayerGroup.extend({
reDraw: function(full){ reDraw: function(full){
var self = this; var self = this;
if (full){ if (this._map.getZoom() < 10) {
this.clearLayers(); this.clearLayers();
this.currentLayers = []; this.currentObjects = [];
return;
} }
if (full){
this.clearLayers();
this.currentObjects = [];
}
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);
//TODO: get coords //TODO: get coords
api.getMapObjects(-10,-10,-10,10,10,10,"travelnet") api.getMapObjects(
x1, y1, y1,
x2, y2, z2,
"travelnet")
.then(function(travelnets){ .then(function(travelnets){
//TODO: remove non-existing markers, add new ones //TODO: remove non-existing markers, add new ones
if (!full){ if (!full){
@ -46,9 +66,6 @@ var TravelnetOverlay = L.LayerGroup.extend({
} }
travelnets.forEach(function(travelnet){ travelnets.forEach(function(travelnet){
console.log(travelnet);
var popup = "<h4>" + travelnet.attributes.station_name + "</h4><hr>" + var popup = "<h4>" + travelnet.attributes.station_name + "</h4><hr>" +
"<b>X: </b> " + travelnet.x + "<br>" + "<b>X: </b> " + travelnet.x + "<br>" +
"<b>Y: </b> " + travelnet.y + "<br>" + "<b>Y: </b> " + travelnet.y + "<br>" +
@ -71,6 +88,7 @@ var TravelnetOverlay = L.LayerGroup.extend({
}, },
onRemove: function(map) { onRemove: function(map) {
this.clearLayers();
map.off("zoomend", this.onMapMove); map.off("zoomend", this.onMapMove);
map.off("moveend", this.onMapMove); map.off("moveend", this.onMapMove);
this.layerMgr.removeListener(this.onLayerChange); this.layerMgr.removeListener(this.onLayerChange);