吉安感知网项目-前端
张含笑
2026-01-13 62c4f89a5db2f5594c782ef2b2bbb8941f63454f
feat:地图搜索
2 files modified
1 files added
71 ■■■■ changed files
applications/mobile-web-view/src/api/map/address.js 16 ●●●●● patch | view | raw | blame | history
applications/mobile-web-view/src/appComponents/LeafletMap/index.vue 4 ●●●● patch | view | raw | blame | history
applications/mobile-web-view/src/appPages/Map/searchBar.vue 51 ●●●● patch | view | raw | blame | history
applications/mobile-web-view/src/api/map/address.js
New file
@@ -0,0 +1,16 @@
import request from '@/axios'
/**
 * @description: 获取地址搜索结果
 * @param {*} data :{
 *  keyworld:string 搜索关键词
 * }
 * @return {*} Promise
 */
export const getPlace = (data) => {
  return request({
    url: `/webservice/address/getPlace`,
    method: 'post',
    data
  })
}
applications/mobile-web-view/src/appComponents/LeafletMap/index.vue
@@ -84,13 +84,13 @@
const layers = [
    {
        src: sl,
        name: '天地图电子',
        name: '矢量',
        key: 1,
        map: basemap0,
    },
    {
        src: yx,
        name: '天地图影像',
        name: '影像',
        key: 2,
        map: basemap1,
    },
applications/mobile-web-view/src/appPages/Map/searchBar.vue
@@ -33,7 +33,7 @@
        <van-list v-else :finished="finished" :finished-text="finishedText">
            <van-cell v-for="item in list" :key="item" @click="flyToAddress(item)">
                <template #title>{{ item.name }}</template>
                <template #value>{{ item.district }}</template>
                <template #value>{{ item?.pname }}{{ item?.cityname }}{{ item?.adname }}</template>
            </van-cell>
        </van-list>
    </van-floating-panel>
@@ -44,6 +44,7 @@
import { showToast } from 'vant'
import _ from 'lodash'
import { searchWithPlugin } from '@/utils/util'
import { getPlace } from '@/api/map/address'
import { useStore } from 'vuex'
import EventBus from '@/utils/eventBus'
import { gcj02ToWgs84 } from '@/utils/coordinateTransformation'
@@ -62,8 +63,8 @@
const height = ref(anchors[0])
const curSearchType = ref(1) // 固定为地址搜索
// 获取地址搜索结果
const getAddressList = () => {
// 使用插件搜索地址
const searchWithPluginAPI = () => {
    searchWithPlugin(searchVal.value, selectedAreaCode.value, (err, data) => {
        if (data && data.length > 0) {
            list.value = data
@@ -77,6 +78,36 @@
            loadingTest.value = false
        }, 800)
    })
}
// 使用新接口搜索地址
const searchWithNewAPI = () => {
    getPlace({ keyworld: searchVal.value }).then(res => {
        const data = res.data.data.pois || []
        if (data && data.length > 0) {
            list.value = data
            finishedText.value = ''
        } else {
            finishedText.value = '暂无数据'
        }
        setTimeout(() => {
            finished.value = true
            loadingTest.value = false
        }, 800)
    }).catch(err => {
        console.error('地址搜索失败:', err)
        finishedText.value = '搜索失败'
        setTimeout(() => {
            finished.value = true
            loadingTest.value = false
        }, 800)
    })
}
// 获取地址搜索结果
const getAddressList = () => {
    searchWithNewAPI()
}
const tooltipText = computed(() => {
@@ -122,13 +153,14 @@
        showToast('当前地址无坐标信息')
        return
    }
    const [longitude, latitude] = gcj02ToWgs84(item.location.lng, item.location.lat)
    const location = typeof item.location === 'string'
        ? item.location.split(',').map(Number)
        : [item.location.lng, item.location.lat];
    const [longitude, latitude] = gcj02ToWgs84(location[0], location[1])
    height.value = anchors[0]
    searchVal.value = item.name
    inputSelect()
    EventBus.emit('mapAddMarker', {
        lat: latitude,
@@ -136,13 +168,6 @@
        name: searchVal.value,
        customClassName: 'address-marker',
    })
}
const scanCode = () => {
    const transmitData = { data: { type: 'scanCode' } }
    wx.miniProgram.navigateTo({ url: "/subPackages/qrCode/index" })
    wx.miniProgram.postMessage(transmitData)
    uni.postMessage(transmitData)
}
watch(