Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda