From c87027931cd6dcbebdbb43bf435d56ef499f7819 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Sat, 2 Feb 2019 18:03:07 +0100 Subject: [PATCH] dynamic overlay query --- server/static/js/overlays/TravelnetOverlay.js | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/server/static/js/overlays/TravelnetOverlay.js b/server/static/js/overlays/TravelnetOverlay.js index a9ede83..1b3cf30 100644 --- a/server/static/js/overlays/TravelnetOverlay.js +++ b/server/static/js/overlays/TravelnetOverlay.js @@ -15,7 +15,7 @@ var TravelnetOverlay = L.LayerGroup.extend({ this.layerMgr = layerMgr; this.wsChannel = wsChannel; - this.currentLayers = []; + this.currentObjects = []; this.onLayerChange = this.onLayerChange.bind(this); this.onMapMove = debounce(this.onMapMove.bind(this), 50); @@ -32,13 +32,33 @@ var TravelnetOverlay = L.LayerGroup.extend({ reDraw: function(full){ var self = this; - if (full){ + if (this._map.getZoom() < 10) { 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 - api.getMapObjects(-10,-10,-10,10,10,10,"travelnet") + api.getMapObjects( + x1, y1, y1, + x2, y2, z2, + "travelnet") .then(function(travelnets){ //TODO: remove non-existing markers, add new ones if (!full){ @@ -46,9 +66,6 @@ var TravelnetOverlay = L.LayerGroup.extend({ } travelnets.forEach(function(travelnet){ - - console.log(travelnet); - var popup = "

" + travelnet.attributes.station_name + "


" + "X: " + travelnet.x + "
" + "Y: " + travelnet.y + "
" + @@ -71,6 +88,7 @@ var TravelnetOverlay = L.LayerGroup.extend({ }, onRemove: function(map) { + this.clearLayers(); map.off("zoomend", this.onMapMove); map.off("moveend", this.onMapMove); this.layerMgr.removeListener(this.onLayerChange);