@@ -166,27 +166,38 @@ function resetMapMarkerMap(_marker: google.maps.marker.AdvancedMarkerElement | P
166
166
})
167
167
}
168
168
169
+ function normalizeAdvancedMapMarkerOptions(_options ? : google .maps .marker .AdvancedMarkerElementOptions | ` ${string },${string } ` ) {
170
+ const opts = typeof _options === ' string'
171
+ ? {
172
+ position: {
173
+ lat: Number .parseFloat (_options .split (' ,' )[0 ] || ' 0' ),
174
+ lng: Number .parseFloat (_options .split (' ,' )[1 ] || ' 0' ),
175
+ },
176
+ }
177
+ : _options
178
+ if (! opts .position ) {
179
+ // set default
180
+ opts .position = {
181
+ lat: 0 ,
182
+ lng: 0 ,
183
+ }
184
+ }
185
+ }
186
+
169
187
async function createAdvancedMapMarker(_options ? : google .maps .marker .AdvancedMarkerElementOptions | ` ${string },${string } ` ) {
170
188
if (! _options )
171
189
return
172
- const key = hash (_options )
190
+ const normalizedOptions = normalizeAdvancedMapMarkerOptions (_options )
191
+ const key = hash ({ position: normalizedOptions .position })
173
192
if (mapMarkers .value .has (key ))
174
193
return mapMarkers .value .get (key )
175
194
// eslint-disable-next-line no-async-promise-executor
176
195
const p = new Promise <google .maps .marker .AdvancedMarkerElement >(async (resolve ) => {
177
196
const lib = await importLibrary (' marker' )
178
- const options = typeof _options === ' string'
179
- ? {
180
- position: {
181
- lat: Number .parseFloat (_options .split (' ,' )[0 ] || ' 0' ),
182
- lng: Number .parseFloat (_options .split (' ,' )[1 ] || ' 0' ),
183
- },
184
- }
185
- : _options
186
- const mapMarkerOptions = defu (toRaw (options ), {
197
+ const mapMarkerOptions = defu (toRaw (normalizedOptions ), {
187
198
map: toRaw (map .value ! ),
188
199
// @ts-expect-error unified API for maps and markers
189
- position: options .location ,
200
+ position: normalizedOptions .location ,
190
201
})
191
202
resolve (new lib .AdvancedMarkerElement (mapMarkerOptions ))
192
203
})
@@ -284,7 +295,7 @@ onMounted(() => {
284
295
}
285
296
// mapMarkers is a map where we hash the next array entry as the map key
286
297
// we need to do a diff to see what we remove or add
287
- const nextMap = new Map ((props .markers || []).map (m => [hash (m ), m ]))
298
+ const nextMap = new Map ((props .markers || []).map (m => [hash ({ position: normalizeAdvancedMapMarkerOptions ( m ). position } ), m ]))
288
299
// compare idsToMatch in nextMap, if we're missing an id, we need to remove it
289
300
const toRemove = new Set ([
290
301
... mapMarkers .value .keys (),
0 commit comments