From 3c4b2218ad705c9e1fdf84644bb6006bdb4fef87 Mon Sep 17 00:00:00 2001 From: qiwei Date: Fri, 1 Sep 2023 18:42:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=88=87=E6=8D=A2map=E6=8A=A5=E9=94=99?= =?UTF-8?q?=20review=20by=20songym?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/web-map/WebMapBase.ts | 3 +++ src/mapboxgl/web-map/WebMapViewModel.ts | 16 +++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/common/web-map/WebMapBase.ts b/src/common/web-map/WebMapBase.ts index 16411a62..10001fc6 100644 --- a/src/common/web-map/WebMapBase.ts +++ b/src/common/web-map/WebMapBase.ts @@ -130,6 +130,9 @@ export default abstract class WebMapBase extends Events { this.webMapInfo = mapId; } this.webMapService.setMapId(mapId); + if (!mapId) { + return; + } setTimeout(() => { this._initWebMap(); }, 0); diff --git a/src/mapboxgl/web-map/WebMapViewModel.ts b/src/mapboxgl/web-map/WebMapViewModel.ts index ebf1b930..2e55dfef 100644 --- a/src/mapboxgl/web-map/WebMapViewModel.ts +++ b/src/mapboxgl/web-map/WebMapViewModel.ts @@ -219,17 +219,15 @@ export default class WebMapViewModel extends WebMapBase { public setStyle(style): void { if (this.map) { - if (style && style.layers && style.layers.length > 0) { - setTimeout(() => { - this.triggerEvent('addlayerssucceeded', { - map: this.map, - mapparams: {}, - layers: [] - }); - }, 0); - } this.mapOptions.style = style; style && this.map.setStyle(style); + if (style && style.layers && style.layers.length > 0) { + this.triggerEvent('addlayerssucceeded', { + map: this.map, + mapparams: {}, + layers: [] + }); + } } }