Browse Source

修改地图bug

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

32
admin/src/components/TencentMapPicker.vue

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

Loading…
Cancel
Save