| | |
| | | }; |
| | | type MapConfig = { |
| | | sourceType: GaoDeSourceType; |
| | | markerIsVisible: boolean; |
| | | }; |
| | | |
| | | type OLEventType = 'blackClick' | 'featureChange' | 'featureHoverChange'; |
| | |
| | | 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 */ |
| | |
| | | } |
| | | |
| | | 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', |
| | |
| | | interactions: olDefaults({ doubleClickZoom: false }), |
| | | }); |
| | | this.activeSourceType.value = sourceType; |
| | | this.markerIsVisible.value = markerIsVisible; |
| | | this.applySourceType(this.activeSourceType.value); |
| | | this.listenMapClick(); |
| | | this.addBasicControl(); |
| | |
| | | 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; |
| | |
| | | stopEvent: false, |
| | | className: 'z-[999]', |
| | | }); |
| | | eleOverlay.setVisible(this.markerIsVisible.value); |
| | | eleOverlay.setVisible(this.checkEquipIsShow()); |
| | | |
| | | return eleOverlay; |
| | | } |
| | |
| | | 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) => { |
| | |
| | | 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', |
| | | }); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | }); |
| | | 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() { |