Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
How to set a different icon for the active marker in the Leaflet map?

I have 2 marker icons greenIcon and redIcon, how to make it so that when the marker is active, redIcon is applied. I have several markers on the map. That is, it is necessary that the icon of the active marker changes and when another marker is selected, the previous one returns to its original state, i.e. greenIcon is displayed back if another marker is selected

    // 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);
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda