From e67da64e383745314f8db1f63a393b145f858709 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 4 Apr 2019 08:45:42 +0200 Subject: [PATCH] border overlay stub --- .../js/overlays/AbstractGeoJsonOverlay.js | 7 +- server/static/js/overlays/BorderOverlay.js | 66 +++++++++++++++++++ server/static/manifest.js | 1 + 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 server/static/js/overlays/BorderOverlay.js diff --git a/server/static/js/overlays/AbstractGeoJsonOverlay.js b/server/static/js/overlays/AbstractGeoJsonOverlay.js index f8052c0..ee15c00 100644 --- a/server/static/js/overlays/AbstractGeoJsonOverlay.js +++ b/server/static/js/overlays/AbstractGeoJsonOverlay.js @@ -47,10 +47,15 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({ return 7; }, + getMinDisplayedZoom: function(){ + return 13; + }, + reDraw: function(){ var self = this; + var zoom = this.map.getZoom(); - if (this.map.getZoom() < this.getMaxDisplayedZoom()) { + if (zoom < this.getMaxDisplayedZoom() || zoom > this.getMinDisplayedZoom()) { this.clearLayers(); return; } diff --git a/server/static/js/overlays/BorderOverlay.js b/server/static/js/overlays/BorderOverlay.js new file mode 100644 index 0000000..58188f4 --- /dev/null +++ b/server/static/js/overlays/BorderOverlay.js @@ -0,0 +1,66 @@ +'use strict'; + +var BorderOverlay = AbstractGeoJsonOverlay.extend({ + initialize: function(wsChannel, layerMgr) { + AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "border"); + }, + + createGeoJson: function(objects){ + var self = this; + + var geoJsonLayer = L.geoJSON([], { + onEachFeature: function(feature, layer){ + if (feature.properties && feature.properties.popupContent) { + layer.bindPopup(feature.properties.popupContent); + } + } + }); + + var borders = []; + + objects.forEach(function(obj){ + if (!obj.attributes.name) + return + + var border = borders[obj.attributes.name]; + if (!border){ + border = []; + borders[obj.attributes.name] = border; + } + + border.push(obj); + }); + + //Order by index and display + Object.keys(borders).forEach(function(bordername){ + borders[bordername].sort(function(a,b){ + return parseInt(a.attributes.index) - parseInt(b.attributes.index); + }); + + var coords = []; + + //Add stations + borders[bordername].forEach(function(entry){ + coords.push([entry.x, entry.z]); + }); + + var feature = { + "type":"Feature", + "geometry": { + "type":"LineString", + "coordinates":coords + }, + "properties":{ + "name": linename, + "popupContent": "Border (" + bordername + ")" + } + } + + //line-points + geoJsonLayer.addData(feature); + }); + + return geoJsonLayer; + } + +}); diff --git a/server/static/manifest.js b/server/static/manifest.js index 9f31430..f816e39 100644 --- a/server/static/manifest.js +++ b/server/static/manifest.js @@ -18,6 +18,7 @@ "/js/overlays/PlayerOverlay.js", "/js/overlays/TrainOverlay.js", "/js/overlays/TrainlineOverlay.js", + "/js/overlays/BorderOverlay.js", "/js/overlays/ProtectorOverlay.js", "/js/overlays/XPProtectorOverlay.js", "/js/overlays/PrivProtectorOverlay.js",