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

180
Views
Can't click Leaflet imageOverlay because of canvas which is above it

If I add an image to Leaflet map as an overlay with the code

let newOverlay = L.imageOverlay(imageUrl, imageBounds).addTo(mapObj);
newOverlay.addEventListener('click', (e) => {
    let thisImg = e.currentTarget;
    console.log(thisImg);
});

I see my image on the map, but when I click it, the <canvas> element is clicked which is above the image with z-index: 100 and extends to the full width and height of the screen. If I add z-index: 200 to the image, it doesn't help.

Maybe it's more HTML/CSS issue than Leaflet and JS, but I'm not sure and can't resolve.

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

0

You need to set the ImageOverlay interactive, then it is clickable:

var newOverlay = L.imageOverlay(imageUrl, imageBounds, {interactive: true}).addTo(map);
about 4 years ago · Juan Pablo Isaza Report

0

Assuming you don't want to react to a click on any part of the overlying canvas you could set it to have pointer-events: none

Here's a trivial example where the top element does not react to a click:

.under,
.over {
  width: 100vw;
  height: 100vh;
  position: absolute;
}

.under {
  background-color: pink;
}

.over {
  background-color: rgba(0, 0, 255, 0.5);
  pointer-events: none;
}
<div class="under" onclick="alert('under clicked');"></div>
<div class="over" onclick="alert('over clicked');"></div>

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!