From 6a71c216a24a6623e4aa0b45d7c3240562c09c96 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 17 二月 2025 10:38:17 +0800
Subject: [PATCH] 定位高亮

---
 src/model/map/OLMap.ts                                                                   |   91 +++++++++++----------------------------------
 src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/Search.vue   |   26 +++++++------
 src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/BasicMap.vue |    3 -
 3 files changed, 37 insertions(+), 83 deletions(-)

diff --git a/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/BasicMap.vue b/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/BasicMap.vue
index 72e514a..4ae9332 100644
--- a/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/BasicMap.vue
+++ b/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/BasicMap.vue
@@ -49,9 +49,6 @@
 		></PanelTool>
 
 		<Search class="absolute top-3 left-4 z-14 w-fit" :olMap="olMap"/>
-		<!-- <el-button type="primary" class="absolute top-20 left-4 z-14 w-fit" @click="locationCurrent"/> -->
-		
-		<!-- <el-button class="absolute top-3 right-4" @click="changeTheme" type="primary">鍒囨崲涓婚</el-button> -->
 	</div>
 </template>
 
diff --git a/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/Search.vue b/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/Search.vue
index 3358ee4..cdc8e52 100644
--- a/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/Search.vue
+++ b/src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/Search.vue
@@ -3,7 +3,7 @@
 		<div class="search flex-items-center">
 			<el-input class="w-[320px]" v-model="searchText" clearable placeholder="鏌ユ壘瀵硅薄" @input="searchInput" @clear="clearSearch">
 				<template #prefix>
-					<el-switch v-model="isSearchObj" inline-prompt active-text="瀵硅薄" inactive-text="閬撹矾" />
+					<el-switch v-model="isSearchObj" inline-prompt active-text="瀵硅薄" inactive-text="閬撹矾" @change="changeSearchType" />
 				</template>
 			</el-input>
 			<div
@@ -52,20 +52,21 @@
 const searchInput = (e) => {
 	debounceSearch(e);
 };
+const changeSearchType = () => {
+	clearSearch(!isSearchObj.value);
+	searchClick(searchText.value);
+};
 
 const searchResultList = ref([]);
 const searchResultClick = (item) => {
 	if (item.isSearchObj) {
-		props.olMap.displaySearchResult([item.model]);
+		props.olMap.displaySearchResult(item.model);
 	} else {
-		// props.olMap.displaySearchResult([item.model]);
 		if (!item.location) return;
 		const [lon, lat] = item.location.split(',').map(Number);
 		const point = fromLonLat([lon, lat]);
-		const circleFeature = new Feature({
-			geometry: new Circle(point, 100),
-		});
-		props.olMap.highlightFeature(circleFeature);
+		const WKT = `SRID=3857;POINT(${point[0]} ${point[1]})`;
+		props.olMap.displaySearchResult({ WKT });
 	}
 };
 const debounceSearch = debounce((text) => {
@@ -73,7 +74,7 @@
 }, 500);
 const searchClick = async (text) => {
 	if (!text.trim()) {
-		clearSearch();
+		clearSearch(isSearchObj.value);
 		return;
 	}
 	if (isSearchObj.value) {
@@ -108,13 +109,14 @@
 					};
 				})
 				?.slice(0, 5) ?? [];
-		console.log('馃殌 ~ searchResultList.value:', searchResultList.value);
 	}
 };
-const clearSearch = () => {
+const clearSearch = (isSearchObj = true) => {
 	searchResultList.value = [];
-	if (isSearchObj.value) {
-		props.olMap.displaySearchResult([]);
+	if (isSearchObj) {
+		props.olMap.clearObjectSearch();
+	}else{
+		props.olMap.clearObjectSearch();
 	}
 };
 </script>
diff --git a/src/model/map/OLMap.ts b/src/model/map/OLMap.ts
index 1b5525b..a586b7c 100644
--- a/src/model/map/OLMap.ts
+++ b/src/model/map/OLMap.ts
@@ -166,7 +166,7 @@
 		const position = await getCurrentPosition();
 		if (!position) return;
 		const { latitude, longitude } = position;
-		
+
 		return;
 		const url = `https://restapi.amap.com/v5/ip/location?key=${this.gaodeApiKey}`;
 		const response = await axios.get(url);
@@ -184,73 +184,28 @@
 		return response.data;
 	}
 
-	displaySearchResult(resultList) {
-		// resultList = [
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: 'd7513894-38d2-48b5-884a-f9a16fe1298a',
-		// 		WKT: 'SRID=3857;POINT(13280607.09109455 3009899.678848996)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: 'f2cbc0f8-de84-449e-9996-8b9425ea8438',
-		// 		WKT: 'SRID=3857;POINT(13274453.007984176 3006699.498741431)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: '2a08d246-639e-4169-862f-38bda3e98677',
-		// 		WKT: 'SRID=3857;POINT(13285466.77807223 3016023.513009545)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: '1bd4ea12-3a4c-4908-a73c-c5a8e14d20eb',
-		// 		WKT: 'SRID=3857;POINT(13282712.61192139 3016897.156892525)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: 'e6d0c5cb-00f5-47aa-846f-0705de983364',
-		// 		WKT: 'SRID=3857;POINT(13288425.224571886 3006456.3830214837)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: '6f83eff7-9e7b-46f8-8b1e-f18a69a98587_A',
-		// 		WKT: 'SRID=3857;POINT(13287645.018084045 3006696.595101201)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: 'acc43afb-7c59-44f2-a36d-0d22eb1b4594_A',
-		// 		WKT: 'SRID=3857;POINT(13286166.586277477 3009094.237136173)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: '8b449ce6-26ba-4c10-b18c-366ded424ec4',
-		// 		WKT: 'SRID=3857;POINT(13282290.543926762 3016028.715200386)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: 'a668fe7e-0d08-4cff-9045-1c27d14b9b61',
-		// 		WKT: 'SRID=3857;POINT(13278933.218610007 3014782.279195062)',
-		// 	},
-		// 	{
-		// 		OTYPE: 'WDM_JUNCTIONS',
-		// 		ONAME: '6ccacce7-c65d-42b8-b5be-4c15ff648f99',
-		// 		WKT: 'SRID=3857;POINT(13275888.24189473 3002108.7952906396)',
-		// 	},
-		// ];
-		const first = resultList[0];
-		let features = [];
-		if (first) {
-			const firstWktStr = first.WKT;
-			const srid = firstWktStr.match(/SRID=(\d+);/)?.[1];
-			const standardWktStrList = resultList.map((item) => item.WKT.replace(/SRID=\d+;/, ''));
-			features = standardWktStrList.map((wktStr) => {
-				return new WKT().readFeature(wktStr, {
-					dataProjection: `EPSG:${srid}`,
-					// featureProjection: `EPSG:${srid}`,
-				});
-			});
-		}
-		this.highlightSearch(features);
+	readWKT(wktStr) {
+		const srid = wktStr.match(/SRID=(\d+);/)?.[1];
+		const standardWktStr = wktStr.replace(/SRID=\d+;/, '');
+		const feature = new WKT().readFeature(standardWktStr, {
+			dataProjection: `EPSG:${srid}`,
+		});
+		return feature;
+	}
+
+	clearObjectSearch() {
+		this.highlightSearch([]);
+	}
+
+	displaySearchResult(searchItem) {
+		if (!searchItem?.WKT) return;
+		const feature = this.readWKT(searchItem.WKT);
+		this.highlightSearch(feature);
+		const geometry = feature.getGeometry();
+	
+		const center = geometry.getCoordinates();
+		this.map.getView().setCenter(center);
+		this.map.getView().setZoom(16);
 	}
 
 	initEvent() {

--
Gitblit v1.9.3