1
This commit is contained in:
+7
-1
@@ -270,7 +270,13 @@ watch(city, (val, oldVal) => {
|
||||
centerLat.value = 0
|
||||
centerLng.value = 0
|
||||
mapRef.value.clearRadiusCircle()
|
||||
mapRef.value.flyTo(coord[0], coord[1], 12)
|
||||
})
|
||||
|
||||
// 范围变更时只重绘圆圈大小,不改变地图视角
|
||||
watch(radius, (val) => {
|
||||
if (centerLng.value && centerLat.value && mapRef.value) {
|
||||
mapRef.value.updateRadiusCircle(val)
|
||||
}
|
||||
})
|
||||
|
||||
async function doSearch() {
|
||||
|
||||
@@ -57,7 +57,6 @@ function addMarkers(pois) {
|
||||
clearMarkers()
|
||||
if (!map || !pois.length) return
|
||||
|
||||
const bounds = L.latLngBounds()
|
||||
const pinIcon = L.divIcon({
|
||||
className: '',
|
||||
html: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 42" width="32" height="42">
|
||||
@@ -92,12 +91,6 @@ function addMarkers(pois) {
|
||||
bounds.extend([lat, lng])
|
||||
})
|
||||
|
||||
// 自动调整视野
|
||||
if (pois.length === 1) {
|
||||
map.setView(bounds.getCenter(), 15)
|
||||
} else {
|
||||
map.fitBounds(bounds, { padding: [40, 40], maxZoom: 16 })
|
||||
}
|
||||
}
|
||||
|
||||
function focusMarker(poi) {
|
||||
@@ -105,7 +98,6 @@ function focusMarker(poi) {
|
||||
const lng = parseFloat(poi.longitude)
|
||||
if (isNaN(lat) || isNaN(lng)) return
|
||||
|
||||
map.setView([lat, lng], 16)
|
||||
for (const marker of currentMarkers) {
|
||||
const pos = marker.getLatLng()
|
||||
if (Math.abs(pos.lat - lat) < 0.001 && Math.abs(pos.lng - lng) < 0.001) {
|
||||
@@ -133,7 +125,6 @@ function drawRadiusCircle(lat, lng, radiusMeters) {
|
||||
weight: 2,
|
||||
dashArray: '6, 6',
|
||||
}).addTo(map)
|
||||
map.fitBounds(radiusCircle.getBounds(), { padding: [40, 40] })
|
||||
}
|
||||
|
||||
function clearRadiusCircle() {
|
||||
@@ -143,7 +134,14 @@ function clearRadiusCircle() {
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ addMarkers, clearMarkers, focusMarker, drawRadiusCircle, clearRadiusCircle, flyTo })
|
||||
// 只更新已有圆圈的大小,不改变地图视角
|
||||
function updateRadiusCircle(radiusMeters) {
|
||||
if (radiusCircle) {
|
||||
radiusCircle.setRadius(radiusMeters)
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ addMarkers, clearMarkers, focusMarker, drawRadiusCircle, clearRadiusCircle, updateRadiusCircle, flyTo })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user