From 0bb3021e3c68d2f75775f7094a2111dc854c7091 Mon Sep 17 00:00:00 2001 From: Keith Paterson Date: Mon, 21 Dec 2020 16:35:31 +0100 Subject: [PATCH] Undefined layer if not found --- src/renderer/components/FlightgearMap.vue | 17 ++++++++------- src/renderer/components/ThresholdLayer.vue | 12 ++++++----- src/renderer/components/TowerLayer.vue | 24 +++++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/renderer/components/FlightgearMap.vue b/src/renderer/components/FlightgearMap.vue index ca6eade..2d7cefa 100644 --- a/src/renderer/components/FlightgearMap.vue +++ b/src/renderer/components/FlightgearMap.vue @@ -196,7 +196,6 @@ 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) { @@ -220,7 +219,7 @@ You should have received a copy of the GNU General Public License along with FG this.layersControl.addOverlay(this.$refs.pavementLayer.getLayer(), 'APT Layer') } } - if (this.$refs.thresholdLayer.getLayer() === e.layer) { + if (this.$refs.thresholdLayer !== undefined && this.$refs.thresholdLayer.getLayer() === e.layer) { l = this.layersControl._layers.filter(l => l.name === 'Threshold Layer') if (l.length > 0 && l[0].layer !== this.$refs.thresholdLayer.getLayer()) { this.layersControl.removeLayer(l[0].layer) @@ -229,6 +228,7 @@ You should have received a copy of the GNU General Public License along with FG if (l.length === 0) { this.layersControl.addOverlay(this.$refs.thresholdLayer.getLayer(), 'Threshold Layer') } + this.$refs.thresholdLayer.zoomUpdated() } if (this.$refs.towerLayer !== undefined && this.$refs.towerLayer.getLayer() === e.layer) { l = this.layersControl._layers.filter(l => l.name === 'Tower Layer') @@ -239,6 +239,7 @@ You should have received a copy of the GNU General Public License along with FG if (l.length === 0) { this.layersControl.addOverlay(this.$refs.towerLayer.getLayer(), 'Tower Layer') } + this.$refs.towerLayer.zoomUpdated() } }, onSelectedPolygon (ring) { @@ -348,11 +349,13 @@ You should have received a copy of the GNU General Public License along with FG } this.$refs.pavementLayer.setVisible(zoom >= 12) } - this.$refs.editLayer.groundnetLayerGroup.eachLayer(function (layer) { - if (layer.updateArrows !== undefined) { - layer.updateArrows(zoom) - } - }) + if (this.$refs.editLayer.groundnetLayerGroup) { + this.$refs.editLayer.groundnetLayerGroup.eachLayer(function (layer) { + if (layer.updateArrows !== undefined) { + layer.updateArrows(zoom) + } + }) + } if (this.$refs.thresholdLayer) { this.$refs.thresholdLayer.zoomUpdated() } diff --git a/src/renderer/components/ThresholdLayer.vue b/src/renderer/components/ThresholdLayer.vue index 545186a..1bdd105 100644 --- a/src/renderer/components/ThresholdLayer.vue +++ b/src/renderer/components/ThresholdLayer.vue @@ -64,11 +64,13 @@ } }, zoomUpdated () { - this.layerGroup.eachLayer(l => { - if (l instanceof L.Threshold) { - l.updateIcon(this.$parent.mapObject) - } - }) + if (this.layerGroup) { + this.layerGroup.eachLayer(l => { + if (l instanceof L.Threshold) { + l.updateIcon(this.$parent.mapObject) + } + }) + } } }, diff --git a/src/renderer/components/TowerLayer.vue b/src/renderer/components/TowerLayer.vue index 3718b94..5fccdd2 100644 --- a/src/renderer/components/TowerLayer.vue +++ b/src/renderer/components/TowerLayer.vue @@ -60,11 +60,13 @@ You should have received a copy of the GNU General Public License along with FG } }, enableEdit () { - this.layerGroup.eachLayer(l => { - if (l instanceof L.TowerMarker) { - l.enableEdit(this.$parent.mapObject) - } - }) + if (this.layerGroup) { + this.layerGroup.eachLayer(l => { + if (l instanceof L.TowerMarker) { + l.enableEdit(this.$parent.mapObject) + } + }) + } }, save () { }, @@ -82,11 +84,13 @@ You should have received a copy of the GNU General Public License along with FG } }, zoomUpdated () { - this.layerGroup.eachLayer(l => { - if (l instanceof L.TowerMarker) { - l.updateIcon(this.$parent.mapObject) - } - }) + if (this.layerGroup) { + this.layerGroup.eachLayer(l => { + if (l instanceof L.TowerMarker) { + l.updateIcon(this.$parent.mapObject) + } + }) + } } }, computed: {