Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Mostrar marcadores de mapa al pasar el mouse

Tengo una lista de enlaces a varios lugares. Me gustaría agregar un marcador de mapa a mi mapa OSM y eliminarlo cuando pase el mouse por encima, mientras agrego uno nuevo sobre el que pase el mouse, etc. Pude agregar un marcador al mapa al pasar el mouse pero no puedo eliminarlo a ellos.

HTML

 <a href="/..." onmouseover="mkron(this)" onmouseout="mkroff()">...</a>

JS

 function mkron(x) { // some code to get lat lon L.marker([lat, lon]).addTo(map); } function mkroff() { markers.clearLayers(); }

¿Qué me estoy perdiendo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su problema es que agrega el marcador directamente al mapa en lugar de agregarlo a los markers LayerGroup / FeatureGroup.

No sé el resto de su código, pero debería verse así:

 var markers = L.featureGroup().addTo(map); function mkron(x) { // some code to get lat lon L.marker([lat, lon]).addTo(markers); } function mkroff() { markers.clearLayers(); }

La otra variante sería almacenar la capa en una variable global y luego eliminarla del mapa:

 var marker; function mkron(x) { // some code to get lat lon marker = L.marker([lat, lon]).addTo(map); } function mkroff() { if(marker){ map.removeLayer(marker) marker = null; } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!