From 95a14f596c8559eeecfd041bcc32e6bd25a1e5df Mon Sep 17 00:00:00 2001 From: helen Date: Fri, 27 Dec 2024 11:39:30 +0800 Subject: [PATCH] map --- src/components/Map/index.vue | 102 +++++++++++++++++++------- src/views/manage/hotel/index.vue | 84 ++++++++++++++++----- src/views/manage/noteManage/index.vue | 7 +- src/views/manage/scenic/index.vue | 4 +- vite.config.ts | 4 +- 5 files changed, 150 insertions(+), 51 deletions(-) diff --git a/src/components/Map/index.vue b/src/components/Map/index.vue index 378b0fb..0ce92da 100644 --- a/src/components/Map/index.vue +++ b/src/components/Map/index.vue @@ -2,17 +2,25 @@
- - - + + + + + + + + + + + +
@@ -73,7 +90,39 @@ const form = ref( regionCode: '' } ); +const searchLocation = ref(props.datas.address||''); // 搜索地点 + +const locationOptions = ref([]); //腾讯地图返回的搜索地址列表 watch(() => props.modelValue); +// 地理位置 输入实时搜索 +const remoteMethod = (query: string) => { + if (query !== '') { + // 调用腾讯地图API进行搜索,并展示在地图上 + // geocoder(query).then((result) => { + // console.log(result); + // }); + console.log(query); + // jsonp(`https://apis.map.qq.com/ws/place/v1/search?key=${'6XFBZ-SAVLT-JGIX2-VOLMK-6S2H3-XUBGO'}&keyword=${encodeURI(query)}&boundary=nearby(20.018883,110.348801,1000)&output=jsonp`, {}).then((res) => { + jsonp( + `https://apis.map.qq.com/ws/place/v1/suggestion?key=${'6XFBZ-SAVLT-JGIX2-VOLMK-6S2H3-XUBGO'}&keyword=${encodeURI(query)}®ion=三亚市®ion_fix=0&output=jsonp`, + {} + ).then((res) => { + // if (res.region.title!=='海南省') { + // proxy?.$modal.msgError('仅支持海南省地理位置'); + // return + // } + if (res.status == 0) { + locationOptions.value = res.data; + } + }); + } +}; +// 选择地理位置 下拉框值变化 +const selectChnange = (val: string) => { + if (val) { + debouncedSearch(searchLocation.value); + } +}; // 点击地点,获取经纬度及地址信息 const onClick = (e: any) => { jsonp( @@ -82,15 +131,15 @@ const onClick = (e: any) => { ).then((data) => { if (data.status == 0) { if (form.value) { - // form.value.address = - // data.result.address_component.province + - // data.result.address_component.city + - // data.result.address_component.district + - // data.result.address_component.street + - // data.result.address_component.street_number; + form.value.address = + data.result.address_component.province + + data.result.address_component.city + + data.result.address_component.district + + data.result.address_component.street + + data.result.address_component.street_number +data.result.title; form.value.latitude = data.result.location.lat; form.value.longitude = data.result.location.lng; - form.value.address = data.result.formatted_addresses.recommend; + // form.value.address = data.result.formatted_addresses.recommend; // form.value.city = data.result.address_component.city; // form.value.region = data.result.ad_info.adcode; //行政区划编码 form.value.regionCode = data.result.ad_info.adcode; //行政区划编码 @@ -119,18 +168,18 @@ const performSearch = async (text) => { jsonp(`https://apis.map.qq.com/ws/geocoder/v1/?address=${text}&key=${'6XFBZ-SAVLT-JGIX2-VOLMK-6S2H3-XUBGO'}&output=jsonp`, {}).then((data) => { console.log(data); if (data.status == 0) { - // form.value.address = - // data.result.address_components.province + - // data.result.address_components.city + - // data.result.address_components.district + - // data.result.address_components.street + - // data.result.address_components.street_number; + form.value.address = + data.result.address_components.province + + data.result.address_components.city + + data.result.address_components.district + + data.result.address_components.street + + data.result.address_components.street_number + data.result.title; form.value.latitude = data.result.location.lat; form.value.longitude = data.result.location.lng; // form.value.region = data.result.ad_info.adcode; //行政区划编码 // form.value.regionCode = data.result.ad_info.adcode; //行政区划编码 - form.value.address = text; + // form.value.address = text; // form.value.city = data.result.address_components.city; center.value = { lat: data.result.location.lat, lng: data.result.location.lng }; geometries.value = [{ styleId: 'marker', position: { lat: data.result.location.lat, lng: data.result.location.lng } }]; @@ -147,16 +196,15 @@ const performSearch = async (text) => { const debouncedSearch = debounce(performSearch, 300); // 创建防抖后的搜索函数,延迟设为300毫秒 const map = ref(null); -const center = ref({ lat: form.value.latitude || 39.145902, lng: form.value.longitude || 117.17546 }); -const zoom = ref(20); +const center = ref({ lat: form.value.latitude || 20.018883, lng: form.value.longitude || 110.348801 }); +const zoom = ref(147); const control = reactive({ scale: {}, zoom: { position: 'topLeft' } }); -const searchLocation = ref(''); // 搜索地点 -const geometries = ref([{ styleId: 'marker', position: { lat: form.value.latitude || 39.145902, lng: form.value.longitude || 117.17546 } }]); +const geometries = ref([{ styleId: 'marker', position: { lat: form.value.latitude || 20.018883, lng: form.value.longitude || 110.348801 } }]); const styles = reactive({ marker: { width: 20, diff --git a/src/views/manage/hotel/index.vue b/src/views/manage/hotel/index.vue index 738d4ad..4fa5113 100644 --- a/src/views/manage/hotel/index.vue +++ b/src/views/manage/hotel/index.vue @@ -24,7 +24,7 @@ - +