Tengo 2 íconos de marcador greenIcon y redIcon, cómo hacerlo para que cuando el marcador esté activo, se aplique redIcon. Tengo varios marcadores en el mapa. Es decir, es necesario que cambie el icono del marcador activo y cuando se selecciona otro marcador, el anterior vuelve a su estado original, es decir, se vuelve a mostrar greenIcon si se selecciona otro marcador.
// Latitude, longitude, Zoom Level var map = L.map('map__riot').setView([0,0], 1.7); // TileLayer L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}.png', { attribution: '', minZoom: 0, maxZoom: 20, ext: 'png' }).addTo(map); var greenIcon = L.icon({ iconUrl: 'map-pin@2x.png', iconSize: [64, 64], // size of the icon iconAnchor: [32, 64], popupAnchor: [0, -25] }); var redIcon = L.icon({ iconUrl: 'map-pin-dark@2x.png', iconSize: [64, 64], // size of the icon iconAnchor: [32, 64], popupAnchor: [0, -25] }); for (const site of sites) { marker = new L.marker([site.lat, site.lng],{icon: greenIcon}) .on('click', function (e) { document.getElementById('titler').textContent = site.address }) .addTo(map); }