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 +++++++++++---------------------------------- 1 files changed, 23 insertions(+), 68 deletions(-) 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