I\'m trying to get the pixel coordinates of an image overlay on click (right click/contextmenu) using the leaflet map library. Essentially when a user clicks on the image, I
The leaflet is giving you the x,y coordinates along the "image-map" div which resizes with the zoom in and out. The event coordinates do not scale to your image size.
In order to get x,y relative to actual picture size, you need to multiply the coordinates against the ratio of current div dimensions and full sized image dimensions.
I calculated your x,y by taking the events coordinates, multiplying them by your var w
and var h
and dividing them by the maps height and width:
function onMapClick(e) {
var mapWidth=map._container.offsetWidth;
var mapHeight=map._container.offsetHeight;
console.log(e.containerPoint.x * w / mapWidth);
console.log(e.containerPoint.y * h / mapHeight);
console.log(e);
}