Update Map Objects in Place (0.14.x)
mainIn 0.14.0, add* methods (like addMarker) function as 'add or update' operations. If you provide an id that already exists on the map, the existing object is updated with the new properties instead of creating a duplicate. This allows for easier state management using custom IDs.
// Create a marker with a custom ID
const marker = await mapViewController.addMarker({
id: 'user-location',
position: { lat: 37.7749, lng: -122.4194 },
title: 'Current Location',
});
// Update the same marker using the same custom ID
const updatedMarker = await mapViewController.addMarker({
id: 'user-location',
position: { lat: 37.7849, lng: -122.4294 },
title: 'Updated Location',
});
console.log(updatedMarker.id === marker.id); // true