|
|
@ -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(() => { |
|
|
|