diff --git a/server/static/index.html b/server/static/index.html index 2616f63..a2b1458 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -11,15 +11,25 @@
+ + + + + + + + + + diff --git a/server/static/js/main.js b/server/static/js/main.js index 1704b4b..699c3a2 100644 --- a/server/static/js/main.js +++ b/server/static/js/main.js @@ -18,7 +18,7 @@ api.getConfig().then(function(cfg){ crs: SimpleCRS }); - map.attributionControl.addAttribution('Mapserver'); + map.attributionControl.addAttribution('Minetest Mapserver'); var layers = {}; var overlays = {} diff --git a/server/static/js/overlays/TravelnetOverlay.js b/server/static/js/overlays/TravelnetOverlay.js index d1335b6..0e8235b 100644 --- a/server/static/js/overlays/TravelnetOverlay.js +++ b/server/static/js/overlays/TravelnetOverlay.js @@ -10,11 +10,13 @@ var TravelnetIcon = L.icon({ var TravelnetOverlay = L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr) { + L.LayerGroup.prototype.initialize.call(this); + this.layerMgr = layerMgr; this.wsChannel = wsChannel; this.onLayerChange = this.onLayerChange.bind(this); - this.onMapMove = this.onMapMove.bind(this); + this.onMapMove = debounce(this.onMapMove.bind(this), 50); }, onLayerChange: function(layer){ @@ -36,21 +38,20 @@ var TravelnetOverlay = L.LayerGroup.extend({ .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}); + self.clearLayers(); travelnets.forEach(function(travelnet){ - var popup = "

" + travelnet.name + "


" + + + console.log(travelnet); + + var popup = "

" + travelnet.attributes.station_name + "


" + "X: " + travelnet.x + "
" + "Y: " + travelnet.y + "
" + "Z: " + travelnet.z + "
" + - "Network: " + travelnet.network + "
" + - "Owner: " + travelnet.owner + "
"; + "Network: " + travelnet.attributes.station_network + "
" + + "Owner: " + travelnet.attributes.owner + "
"; + var marker = L.marker([travelnet.z, travelnet.x], {icon: TravelnetIcon}); marker.bindPopup(popup).addTo(self); }); }) @@ -58,12 +59,15 @@ var TravelnetOverlay = L.LayerGroup.extend({ }, onAdd: function(map) { + map.on("zoomend", this.onMapMove); + map.on("moveend", this.onMapMove); this.layerMgr.addListener(this.onLayerChange); - console.log("TravelnetOverlay.onAdd", map); + this.reDraw(true) }, onRemove: function(map) { + map.off("zoomend", this.onMapMove); + map.off("moveend", this.onMapMove); this.layerMgr.removeListener(this.onLayerChange); - console.log("TravelnetOverlay.onRemove"); } }); diff --git a/server/static/js/util/debounce.js b/server/static/js/util/debounce.js new file mode 100644 index 0000000..8985c23 --- /dev/null +++ b/server/static/js/util/debounce.js @@ -0,0 +1,14 @@ +function debounce(func, wait, immediate) { + var timeout; + return function() { + var context = this, args = arguments; + var later = function() { + timeout = null; + if (!immediate) func.apply(context, args); + }; + var callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) func.apply(context, args); + }; +};