Skip to content

fix: properly handle centerMarker removal logic #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/runtime/components/ScriptGoogleMaps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const props = withDefaults(defineProps<{
trigger: ['mouseenter', 'mouseover', 'mousedown'],
width: 640,
height: 400,
centerMarker: true
})

const emits = defineEmits<{
Expand Down Expand Up @@ -306,7 +307,7 @@ onMounted(() => {
// do a diff of next and prev
const centerHash = hash({ position: options.value.center })
for (const key of toRemove) {
if (key === centerHash) {
if (props.centerMarker && key === centerHash) {
continue
}
const marker = await mapMarkers.value.get(key)
Expand Down Expand Up @@ -335,7 +336,7 @@ onMounted(() => {
center = await resolveQueryToLatLang(center as string)
}
map.value!.setCenter(center as google.maps.LatLng)
if (typeof props.centerMarker === 'undefined' || props.centerMarker) {
if (props.centerMarker) {
if (options.value.mapId) {
// not allowed to use advanced markers with styles
return
Expand Down Expand Up @@ -418,7 +419,7 @@ const placeholder = computed(() => {
style: props.mapOptions?.styles ? transformMapStyles(props.mapOptions.styles) : undefined,
markers: [
...(props.markers || []),
(typeof props.centerMarker === 'undefined' || props.centerMarker) && center,
props.centerMarker && center,
]
.filter(Boolean)
.map((m) => {
Expand Down