@@ -135,6 +135,18 @@ function isLocationQuery(s: string | any) {
135
135
return typeof s === ' string' && (s .split (' ,' ).length > 2 || s .includes (' +' ))
136
136
}
137
137
138
+ function resetMapMarkerMap(_marker : google .maps .marker .AdvancedMarkerElement | Promise <google .maps .marker .AdvancedMarkerElement >) {
139
+ // eslint-disable-next-line no-async-promise-executor
140
+ return new Promise <void >(async (resolve ) => {
141
+ const marker = _marker instanceof Promise ? await _marker : _marker
142
+ if (marker ) {
143
+ // @ts-expect-error broken type
144
+ marker .setMap (null )
145
+ }
146
+ resolve ()
147
+ })
148
+ }
149
+
138
150
async function createAdvancedMapMarker(_options : google .maps .marker .AdvancedMarkerElementOptions | ` ${string },${string } ` ) {
139
151
const key = hash (_options )
140
152
if (mapMarkers .value .has (key ))
@@ -266,10 +278,10 @@ onMounted(() => {
266
278
}
267
279
const marker = await mapMarkers .value .get (key )
268
280
if (marker ) {
269
- // @ts-expect-error broken type
270
- marker . setMap ( null )
271
- // make sure it gets removed from map
272
- mapMarkers . value . delete ( key )
281
+ resetMapMarkerMap ( marker )
282
+ . then (() => {
283
+ mapMarkers . value . delete ( key )
284
+ } )
273
285
}
274
286
}
275
287
for (const k of toAdd ) {
@@ -298,9 +310,12 @@ onMounted(() => {
298
310
}
299
311
if (prev [0 ]) {
300
312
const prevCenterHash = hash ({ position: prev [0 ] })
301
- // @ts-expect-error broken upstream type
302
- mapMarkers .value .get (prevCenterHash )?.setMap (null )
303
- mapMarkers .value .delete (prevCenterHash )
313
+ if (mapMarkers .value .has (prevCenterHash )) {
314
+ resetMapMarkerMap (mapMarkers .value .get (prevCenterHash )! )
315
+ .then (() => {
316
+ mapMarkers .value .delete (prevCenterHash )
317
+ })
318
+ }
304
319
}
305
320
createAdvancedMapMarker ({ position: center })
306
321
}
@@ -427,13 +442,7 @@ const rootAttrs = computed(() => {
427
442
const ScriptLoadingIndicator = resolveComponent (' ScriptLoadingIndicator' )
428
443
429
444
onBeforeUnmount (async () => {
430
- await Promise .all ([... mapMarkers .value .entries ()].map (async (_marker ) => {
431
- const marker = await _marker
432
- if (marker ) {
433
- // @ts-expect-error broken type
434
- marker .setMap (null )
435
- }
436
- }))
445
+ await Promise .all ([... mapMarkers .value .entries ()].map (([,marker ]) => resetMapMarkerMap (marker )))
437
446
mapMarkers .value .clear ()
438
447
map .value ?.unbindAll ()
439
448
map .value = undefined
0 commit comments