Getting pixel coordinates of an image overlay using leaflet map library on click (right click)

后端 未结 4 1519
后悔当初
后悔当初 2020-12-17 17:18

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

4条回答
  •  旧时难觅i
    2020-12-17 17:39

    You are receiving containerPoint, which contains x and y coordinates placement(container-wise) when you trigger the contextmenu event now.Since you know/can retrieve the dimensions of the Map container, and you know the native dimensions of the image..shouldn't that be enough to do the calculations?

    e.g If you know the map container width is 1000px...and you receive a contextmenu event where the x coordinate is 500...then you know someone clicked directly in the center because 500 / 1000(map container width) = 0.5 and that means the actual position on the image would be native width(2000, as per your variable w) * 0.5 = 1000.

提交回复
热议问题