allow users to set coordinate display type (#141)

This commit is contained in:
MaysWind
2025-05-27 01:01:55 +08:00
parent e338c7190d
commit 626d3895aa
36 changed files with 516 additions and 144 deletions
+6 -6
View File
@@ -13,7 +13,7 @@ import { ref, computed, useTemplateRef } from 'vue';
import { useI18n } from '@/locales/helpers.ts';
import type { MapPosition } from '@/core/map.ts';
import type { Coordinate } from '@/core/coordinate.ts';
import type { MapInstance } from '@/lib/map/base.ts';
import { createMapInstance } from '@/lib/map/index.ts';
@@ -21,18 +21,18 @@ const props = defineProps<{
height?: string;
mapClass?: string;
mapStyle?: Record<string, string>;
geoLocation?: MapPosition;
geoLocation?: Coordinate;
}>();
const emit = defineEmits<{
(e: 'click', geoLocation: MapPosition): void;
(e: 'click', geoLocation: Coordinate): void;
}>();
const { tt, getCurrentLanguageInfo } = useI18n();
const mapContainer = useTemplateRef<HTMLElement>('mapContainer');
const mapInstance = ref<MapInstance | null>(createMapInstance());
const initCenter = ref<MapPosition>({
const initCenter = ref<Coordinate>({
latitude: 0,
longitude: 0
});
@@ -92,7 +92,7 @@ function initMapView(): void {
zoomIn: tt('Zoom in'),
zoomOut: tt('Zoom out'),
},
onClick: (geoLocation: MapPosition) => {
onClick: (geoLocation: Coordinate) => {
emit('click', geoLocation);
}
});
@@ -113,7 +113,7 @@ function initMapView(): void {
}
}
function setMarkerPosition(geoLocation?: MapPosition): void {
function setMarkerPosition(geoLocation?: Coordinate): void {
if (!mapInstance.value) {
return;
}
+7 -7
View File
@@ -39,20 +39,20 @@ import MapView from '@/components/common/MapView.vue';
import { useI18n } from '@/locales/helpers.ts';
import type { MapPosition } from '@/core/map.ts';
import type { Coordinate } from '@/core/coordinate.ts';
import { isSupportGetGeoLocationByClick } from '@/lib/map/index.ts';
type MapViewType = InstanceType<typeof MapView>;
const props = defineProps<{
modelValue?: MapPosition;
modelValue?: Coordinate;
setGeoLocationByClickMap?: boolean;
show: boolean;
}>();
const emit = defineEmits<{
(e: 'update:modelValue', value: MapPosition | undefined): void;
(e: 'update:modelValue', value: Coordinate | undefined): void;
(e: 'update:setGeoLocationByClickMap', value: boolean): void;
(e: 'update:show', value: boolean): void;
}>();
@@ -61,7 +61,7 @@ const { tt } = useI18n();
const map = useTemplateRef<MapViewType>('map');
const geoLocation = computed<MapPosition | undefined>({
const geoLocation = computed<Coordinate | undefined>({
get: () => {
return props.modelValue;
},
@@ -70,10 +70,10 @@ const geoLocation = computed<MapPosition | undefined>({
}
});
function updateSpecifiedGeoLocation(mapPosition: MapPosition): void {
function updateSpecifiedGeoLocation(coordinate: Coordinate): void {
if (isSupportGetGeoLocationByClick() && props.setGeoLocationByClickMap) {
geoLocation.value = mapPosition;
map.value?.setMarkerPosition(mapPosition);
geoLocation.value = coordinate;
map.value?.setMarkerPosition(coordinate);
}
}