From e50196bff10f0196307b2567ed6c0829eadd8ff6 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期一, 10 二月 2025 12:12:25 +0800 Subject: [PATCH] 设备显示隐藏 --- src/model/map/OLMap.ts | 67 ++++++++++++++++++++++++++++----- 1 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/model/map/OLMap.ts b/src/model/map/OLMap.ts index 783d561..c9cbde8 100644 --- a/src/model/map/OLMap.ts +++ b/src/model/map/OLMap.ts @@ -61,7 +61,6 @@ }; type MapConfig = { sourceType: GaoDeSourceType; - markerIsVisible: boolean; }; type OLEventType = 'blackClick' | 'featureChange' | 'featureHoverChange'; @@ -91,7 +90,6 @@ themeInfo = ref([] as any[]); activeSourceType: Ref<GaoDeSourceType> = ref(GaoDeSourceType.Vector); - markerIsVisible: Ref<boolean> = ref(true); interactLayer: VectorLayer<VectorSource<Feature<Geometry>>, Feature<Geometry>> = null; /** @description 褰撳墠婵�娲荤姸鎬� feature */ @@ -126,13 +124,12 @@ } constructor(options: OLMapOptions) { - const { container, view, sourceType, markerIsVisible } = defaultsDeep(options, { + const { container, view, sourceType } = defaultsDeep(options, { view: { center: [13247019.404399557, 4721671.572580107], zoom: 8, }, sourceType: GaoDeSourceType.Vector, - markerIsVisible: true, } as OLMapOptions) as OLMapOptions; this.source = new XYZ({ crossOrigin: 'anonymous', @@ -153,7 +150,6 @@ interactions: olDefaults({ doubleClickZoom: false }), }); this.activeSourceType.value = sourceType; - this.markerIsVisible.value = markerIsVisible; this.applySourceType(this.activeSourceType.value); this.listenMapClick(); this.addBasicControl(); @@ -356,6 +352,24 @@ this.adjustViewToOverlays(markers); } + + checkEquipIsShow() { + for (const item of this.layerInfo.value) { + if (item.id === 'equip') { + return item.isVisible; + } + } + return false; + } + + getEquipOverlay() { + for (const item of this.layerInfo.value) { + if (item.type === 'equip') { + return item; + } + + } + } createEleOverlay(dom: string | HTMLElement, position = [0, 0]) { const ele = typeof dom === 'string' ? (document.querySelector(dom) as HTMLElement) : dom; if (!ele) return; @@ -366,7 +380,7 @@ stopEvent: false, className: 'z-[999]', }); - eleOverlay.setVisible(this.markerIsVisible.value); + eleOverlay.setVisible(this.checkEquipIsShow()); return eleOverlay; } @@ -475,6 +489,27 @@ this.themeInfo.value = themeInfo; } + getAllLayers() { + const allLayers = this.layerInfo.value.reduce((preVal, curVal) => { + if (preVal.children && preVal.children.length > 0) { + return preVal.concat(curVal.children.map((item) => item)); + } else { + return preVal; + } + }, []); + return allLayers; + } + + getAllLayerModels() { + return this.layerInfo.value.reduce((preVal, curVal) => { + if (preVal.children && preVal.children.length > 0) { + return preVal.concat(curVal.children.map((item) => item.model)); + } else { + return preVal; + } + }, []); + } + /** @description 璁板綍鎵�鏈夊浘灞� */ setAllLayers(layerModels: Layer[], layers: any[], layerGroup: any[]) { // this.layerInfo.value = layerModels.map((layer, index) => { @@ -525,6 +560,22 @@ mapGroupItem.children.push(data); return preVal; }, []); + const that = this; + this.layerInfo.value.push({ + id: 'equip', + title: '鐩戞祴璁惧', + children: [], + _isVisible: true, + get isVisible() { + return this._isVisible; + }, + set isVisible(val) { + console.log("馃殌 ~ val:", val) + this._isVisible = val; + that.toggleMarkerOverlayVisible(val); + }, + type: 'equip', + }); } /** @@ -553,21 +604,17 @@ } } }); - this.markerIsVisible.value = visible; } getConfig(): MapConfig { return { sourceType: this.activeSourceType.value, - markerIsVisible: this.markerIsVisible.value, }; } setConfig(config: MapConfig) { this.activeSourceType.value = config.sourceType; - this.markerIsVisible.value = config.markerIsVisible; this.applySourceType(this.activeSourceType.value); - this.toggleMarkerOverlayVisible(this.markerIsVisible.value); } private addBasicControl() { -- Gitblit v1.9.3