support clicking on map to set specified geographic location

This commit is contained in:
MaysWind
2025-05-02 00:32:22 +08:00
parent 65a0e48988
commit 381d063295
23 changed files with 191 additions and 24 deletions
+21 -2
View File
@@ -13,7 +13,8 @@ import { ref, computed, useTemplateRef } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import type { MapInstance, MapPosition } from '@/lib/map/base.ts';
import type { MapPosition } from '@/core/map.ts';
import type { MapInstance } from '@/lib/map/base.ts';
import { createMapInstance } from '@/lib/map/index.ts';
const props = defineProps<{
@@ -23,6 +24,10 @@ const props = defineProps<{
geoLocation?: MapPosition;
}>();
const emit = defineEmits<{
(e: 'click', geoLocation: MapPosition): void;
}>();
const { tt, getCurrentLanguageInfo } = useI18n();
const mapContainer = useTemplateRef<HTMLElement>('mapContainer');
@@ -86,6 +91,9 @@ function initMapView(): void {
text: {
zoomIn: tt('Zoom in'),
zoomOut: tt('Zoom out'),
},
onClick: (geoLocation: MapPosition) => {
emit('click', geoLocation);
}
});
@@ -105,7 +113,18 @@ function initMapView(): void {
}
}
function setMarkerPosition(geoLocation?: MapPosition): void {
if (!mapInstance.value) {
return;
}
if (geoLocation) {
mapInstance.value.setMapCenterMarker(geoLocation);
}
}
defineExpose({
initMapView
initMapView,
setMarkerPosition
});
</script>