Browse Source

修改地图bug

wangzeyan
王泽彦 11 months ago
parent
commit
9e99f1336c
  1. 44
      admin/src/components/TencentMapPicker.vue

44
admin/src/components/TencentMapPicker.vue

@ -344,15 +344,34 @@ const initMap = () => {
}
const TMap = (window as any).TMap
const center = new TMap.LatLng(20.029077, 110.366367)
let center
// 使
if (props.modelValue.lat && props.modelValue.lng) {
center = new TMap.LatLng(props.modelValue.lat, props.modelValue.lng)
} else {
// 使
center = new TMap.LatLng(39.90403, 116.407526)
}
//
map = new TMap.Map('container', {
center,
zoom: 12,
})
//
marker = createMarker(map)
//
if (props.modelValue.lat && props.modelValue.lng) {
marker.updateGeometries({
id: 'center',
position: new TMap.LatLng(props.modelValue.lat, props.modelValue.lng),
})
}
//
map.on('click', (evt: any) => {
map.setCenter(evt.latLng)
marker.updateGeometries({
@ -455,16 +474,23 @@ const handleError = (error: any) => {
watch(
() => props.modelValue,
(newVal) => {
if (newVal.lat && newVal.lng && map) {
const latLng = new (window as any).TMap.LatLng(newVal.lat, newVal.lng)
map.setCenter(latLng)
marker?.updateGeometries({
id: 'center',
position: latLng,
})
if (newVal?.lat && newVal?.lng && map) {
try {
const latLng = new (window as any).TMap.LatLng(newVal.lat, newVal.lng)
map.setCenter(latLng)
marker?.updateGeometries({
id: 'center',
position: latLng,
})
} catch (error) {
console.warn('地图更新失败:', error)
}
}
},
{ immediate: true }
{
deep: true,
immediate: true,
}
)
onBeforeUnmount(() => {

Loading…
Cancel
Save