From bed38277ce5e0e7d92c3ca5c35ea4f5c7321f791 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Wed, 8 Jul 2020 11:33:31 +0200 Subject: [PATCH] Layer visibility --- src/renderer/components/EditBar.vue | 2 +- src/renderer/components/FlightgearMap.vue | 19 +++++++++++++------ src/renderer/components/ThresholdLayer.vue | 15 +++++++++++---- src/renderer/loaders/groundnet_loader.js | 2 +- src/renderer/loaders/pavement_loader.js | 20 ++++++++++---------- src/renderer/loaders/threshold_loader.js | 2 +- 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/renderer/components/EditBar.vue b/src/renderer/components/EditBar.vue index 5b8fc48..5254980 100644 --- a/src/renderer/components/EditBar.vue +++ b/src/renderer/components/EditBar.vue @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with FG - + diff --git a/src/renderer/components/FlightgearMap.vue b/src/renderer/components/FlightgearMap.vue index 5170fa9..5e73aaa 100644 --- a/src/renderer/components/FlightgearMap.vue +++ b/src/renderer/components/FlightgearMap.vue @@ -14,6 +14,7 @@ You should have received a copy of the GNU General Public License along with FG :zoom="zoom" :center="center" :options="options" + @ready="ready" @update:zoom="zoomUpdated" @update:center="centerUpdated" @update:bounds="boundsUpdated" @@ -76,8 +77,6 @@ You should have received a copy of the GNU General Public License along with FG components: { LMap, LTileLayer, LMarker, LCircle, LeafletSidebar, AiLayer, EditBar, ToolBar, EditLayer, PavementLayer, LLayerGroup, LControl, ThresholdLayer, ToolLayer }, props: [], mounted () { - this.$refs.map.mapObject.on('layeradd', this.onLayerAdd) - this.$store.dispatch('getAirports') this.$store.subscribe((mutation, state) => { if (mutation.type === 'CENTER' || mutation.type === 'SET_AIRPORTS' || mutation.type === 'ZOOM') { @@ -87,11 +86,9 @@ You should have received a copy of the GNU General Public License along with FG .filter(feature => this.visible(feature)) .map(feature => feature.properties.icao) if (airportsToLoad.length > 0 && airportsToLoad[0] !== this.editingAirport && this.zoom > 12) { - this.$refs.editLayer.load(airportsToLoad[0]) this.$refs.pavementLayer.load(airportsToLoad[0]) - /* + this.$refs.editLayer.load(airportsToLoad[0]) this.$refs.thresholdLayer.load(airportsToLoad[0]) - */ this.editingAirport = airportsToLoad[0] } if (this.$refs.editLayer) { @@ -119,11 +116,14 @@ You should have received a copy of the GNU General Public License along with FG } }, methods: { + ready (e) { + console.log(e) + e.on('layeradd', this.onLayerAdd) + }, onLayerAdd (e) { if (this.layersControl === null) { this.layersControl = L.control.layers({}, {}, {position: 'topleft'}) this.layersControl.addTo(this.$refs.map.mapObject) - debugger var icon = this.layersControl._container.ownerDocument.createElement('I') icon.className = 'fas fa-layer-group' icon.style = 'padding-top: 9px; height: 30px; width: 30px; text-align: center; vertical-align: sub;' @@ -131,11 +131,18 @@ You should have received a copy of the GNU General Public License along with FG // this.layersControl.addOverlay(this.$refs.thresholdLayer, 'Threshold Layer') } if (this.$refs.pavementLayer.getLayer() === e.layer) { + // debugger var l = this.layersControl._layers.filter(l => l.name === 'APT Layer') if (l.length === 0) { this.layersControl.addOverlay(this.$refs.pavementLayer.getLayer(), 'APT Layer') } } + if (this.$refs.thresholdLayer.getLayer() === e.layer) { + l = this.layersControl._layers.filter(l => l.name === 'Threshold Layer') + if (l.length === 0) { + this.layersControl.addOverlay(this.$refs.thresholdLayer.getLayer(), 'Threshold Layer') + } + } }, onSelectedPolygon (ring) { var parkings = this.$refs.editLayer.getParkings(ring) diff --git a/src/renderer/components/ThresholdLayer.vue b/src/renderer/components/ThresholdLayer.vue index 53c702a..a6f75e7 100644 --- a/src/renderer/components/ThresholdLayer.vue +++ b/src/renderer/components/ThresholdLayer.vue @@ -25,10 +25,14 @@ } }, methods: { + getLayer () { + return this.layerGroup + }, load (icao) { // Callback for add this.layerGroup = readThresholdXML(this.$store.state.Settings.settings.airportsDirectory, icao, this.read) this.layerGroup.addTo(this.$parent.mapObject) + this.visible = true this.icao = icao }, deferredMountedTo (parent) { @@ -45,10 +49,13 @@ }, setVisible (visible) { if (this.layerGroup !== undefined) { - if (visible) { - this.layerGroup.addTo(this.$parent.mapObject) - } else { - this.layerGroup.removeFrom(this.$parent.mapObject) + if (visible !== this.visible) { + if (visible) { + this.layerGroup.addTo(this.$parent.mapObject) + } else { + this.layerGroup.removeFrom(this.$parent.mapObject) + } + this.visible = visible } } } diff --git a/src/renderer/loaders/groundnet_loader.js b/src/renderer/loaders/groundnet_loader.js index 3ed2721..6def3e1 100644 --- a/src/renderer/loaders/groundnet_loader.js +++ b/src/renderer/loaders/groundnet_loader.js @@ -34,7 +34,7 @@ exports.addFeature = function (feature) { exports.readGroundnetXML = function (fDir, icao, force) { try { - layerGroup = L.layerGroup(); + var layerGroup = L.layerGroup(); layerGroup.maxId = 0; var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.xml'); var fNew = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.new.xml'); diff --git a/src/renderer/loaders/pavement_loader.js b/src/renderer/loaders/pavement_loader.js index 44ae814..d7a9c72 100644 --- a/src/renderer/loaders/pavement_loader.js +++ b/src/renderer/loaders/pavement_loader.js @@ -209,7 +209,7 @@ function deCasteljau(pointArray) { return intermediates; } -function createPoly(currentFeature) { +function createPoly(currentFeature, layerGroup) { switch (module.exports.type) { case 110: var taxiwayPoly = new L.Polygon(currentFeature); @@ -231,7 +231,7 @@ function createPoly(currentFeature) { } } -function createLineString(currentFeature) { +function createLineString(currentFeature, layerGroup) { switch (module.exports.type) { case 110: var taxiwayPoly = new L.Polyline(currentFeature); @@ -255,7 +255,7 @@ function createLineString(currentFeature) { module.exports.readPavement = function (f, icao, cb) { console.log(f); - layerGroup = L.layerGroup(); + var pavementLayerGroup = L.layerGroup(); var currentFeature; lineReader.createInterface({ @@ -267,7 +267,7 @@ module.exports.readPavement = function (f, icao, cb) { return; var scanMethod = scanMethods[fields[0]]; if (scanMethod != null) { - currentFeature = scanMethod(fields, icao, layerGroup, currentFeature); + currentFeature = scanMethod(fields, icao, pavementLayerGroup, currentFeature); } else { if (fields[0] == '99') { @@ -280,7 +280,7 @@ module.exports.readPavement = function (f, icao, cb) { lr.close(); }).on('close', function () { console.log("End"); - cb(layerGroup); + cb(pavementLayerGroup); }); } @@ -381,7 +381,7 @@ var scanMethods = { if (!module.exports.isScanning) return undefined; if (typeof currentFeature !== 'undefined') { - createPoly(currentFeature); + createPoly(currentFeature, layerGroup); } module.exports.colour = 'grey'; module.exports.type = 110; @@ -391,7 +391,7 @@ var scanMethods = { if (!module.exports.isScanning) return undefined; if (typeof currentFeature !== 'undefined') { - createPoly(currentFeature); + createPoly(currentFeature, layerGroup); } module.exports.colour = 'yellow'; module.exports.type = 120; @@ -401,7 +401,7 @@ var scanMethods = { if (!module.exports.isScanning) return undefined; if (typeof currentFeature !== 'undefined') { - createPoly(currentFeature); + createPoly(currentFeatur, layerGroup); } module.exports.colour = 'black'; module.exports.type = 130; @@ -463,7 +463,7 @@ var scanMethods = { else { currentFeature.slice(-1)[0].push([line[1], line[2]]); } - createLineString(currentFeature); + createLineString(currentFeature, layerGroup); exports.bezierPoint = null; }, // End with Bezier @@ -472,7 +472,7 @@ var scanMethods = { return; console.debug(line); currentFeature = bezier(line, icao, layerGroup, currentFeature); - createLineString(currentFeature); + createLineString(currentFeature, layerGroup); exports.bezierPoint = null; // taxiwayLine.addTo(layerGroup); }, diff --git a/src/renderer/loaders/threshold_loader.js b/src/renderer/loaders/threshold_loader.js index 332a851..9b6b5da 100644 --- a/src/renderer/loaders/threshold_loader.js +++ b/src/renderer/loaders/threshold_loader.js @@ -15,7 +15,7 @@ var $ = require('jquery'); exports.readThresholdXML = function (fDir, icao, force) { try { - layerGroup = L.layerGroup(); + var layerGroup = L.layerGroup(); layerGroup.maxId = 0; var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.threshold.xml'); var fNew = path.join(fDir, icao[0], icao[1], icao[2], icao + '.threshold.new.xml');