From 4e04b16f7bf497502508101c45ef6ff0209b13e2 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 17 一月 2025 11:07:39 +0800
Subject: [PATCH] 尝试合并配置

---
 src/model/map/OLMap.ts |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/model/map/OLMap.ts b/src/model/map/OLMap.ts
index e6c4630..2385085 100644
--- a/src/model/map/OLMap.ts
+++ b/src/model/map/OLMap.ts
@@ -46,19 +46,23 @@
 	};
 	return urlMap[type];
 };
+type MapConfig = {
+	sourceType: GaoDeSourceType;
+	markerIsVisible: boolean;
+};
 
 type OLEventType = 'blackClick';
 type OLMapOptions = {
 	container: HTMLDivElement;
 
 	view?: ViewOptions;
-};
+} & MapConfig;
 export class OLMap {
 	map: OpenLayerMap;
 	source: XYZ;
 	private eventMap: Map<OLEventType, Function[]>;
 	activeSourceType: Ref<GaoDeSourceType> = ref(GaoDeSourceType.Vector);
-	overlayIsVisible: Ref<boolean> = ref(true);
+	markerIsVisible: Ref<boolean> = ref(true);
 	private emit(eventName: OLEventType, ...args: any[]) {
 		const handlers = this.eventMap?.get(eventName);
 		if (handlers) {
@@ -89,11 +93,13 @@
 	}
 
 	constructor(options: OLMapOptions) {
-		const { container, view } = defaultsDeep(options, {
+		const { container, view, sourceType, markerIsVisible } = 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',
@@ -112,6 +118,8 @@
 			layers: [layer], // 娣诲姞鍥惧眰
 			view: new View(view),
 		});
+		this.activeSourceType.value = sourceType;
+		this.markerIsVisible.value = markerIsVisible;
 		this.setSourceUrl(this.activeSourceType.value);
 		this.listenMapClick();
 		this.addBasicControl();
@@ -146,7 +154,7 @@
 			stopEvent: false,
 			className: 'z-[999]',
 		});
-		eleOverlay.setVisible(this.overlayIsVisible.value);
+		eleOverlay.setVisible(this.markerIsVisible.value);
 
 		return eleOverlay;
 	}
@@ -232,7 +240,21 @@
 				}
 			}
 		});
-		this.overlayIsVisible.value = visible;
+		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.setSourceUrl(this.activeSourceType.value);
+		this.toggleMarkerOverlayVisible(this.markerIsVisible.value);
 	}
 
 	private addBasicControl() {

--
Gitblit v1.9.3