Estoy usando la API de Google para mostrar un mapa, marcadores y polígonos.
Cuando agrego un nuevo marcador, los marcadores anteriores no desaparecen.
Guardo el mapa, los marcadores y los polígonos dentro de mi estado de datos.
data() { return { google: window.google, map: null, activeInfoWindow: null, polygons: [], markers: [] } },Traté de eliminar los marcadores anteriores con marker.setMap(null) antes de mostrar nuevos marcadores
filtersResults: function (filterResults) { // REMOVE PREVIOUS ACTIVE MARKER this.markers.map((marker) => marker.setMap(null)) }, Traté de vaciar la matriz de marcadores también. No pasa nada, los marcadores aún se muestran en el mapa.

El setMap no está indefinido, este es el resultado cuando estoy console.log(marker.setMap)
ƒ (c){try{this.set(a,b(c))}catch(d){_.Pe(_.Oe("set"+_.Bf(a),d))}} data() { return { google: window.google, map: null, activeInfoWindow: null, polygons: [], markers: [] } }, async mounted() { const { LatLng, Map, MapTypeId } = this.google.maps this.map = new Map(document.getElementById('map'), { zoom: 10, center: new LatLng(process.env.INITIAL_LAT, process.env.INITIAL_LNG), mapTypeId: MapTypeId.ROADMAP }) }, watch: { filtersResults: function (filterResults) { // REMOVE PREVIOUS ACTIVE MARKER this.markers.map((marker) => marker.setMap(null)) this.markers = [] }, assets: { handler: function (newValue) { const { map } = this if (isNotNullAndUndefined(newValue) && map) { // ! GENERATE MARKER IN HERE this.markers = newValue.map((value) => { const { location } = value return this.generateMarkers({ latitude: dotFormat(location.lat), longitude: dotFormat(location.lng), details: value }) }) } }, immediate: true } }, methods: { generateMarkers({ latitude, longitude, details }) { const { map, google } = this const { LatLng, Marker } = google.maps const marker = new Marker({ position: new LatLng(latitude, longitude), draggable: false }) marker.setMap(map) return marker }, } }Cuando almacenamos los Markers en la matriz de markers , vue.js 3 los convierte en objetos Proxy .
Eso causa un problema cuando luego llamamos a Proxy.setMap(null) ; A Google Maps de alguna manera no le gusta eso, probablemente porque el objeto Proxy no es === el objeto Marker original agregado al mapa inicialmente.
La solución que encontré fue usar toRaw() antes de usar cualquier objeto de Google Maps que se convirtió en objetos Proxy :
import {toRaw} from 'vue'; this.markers.map((marker) => toRaw(marker).setMap(null))