I have a leaflet map which consists of a tile layer and above an imageOverlay which is semi transparently showing temperature distribution as colored areas. The Overlay is placed at certain bounds within the tile layer. When I click somewhere on the the overlay, I want to figure out what color the pixel at that point has.
My problem is to project the clicked position onto the imageOverlay respecting the offset of the imageOverlay to the visible map and the zoom level. Eventually I want to get the pixel coordinates at the image (at it's natural resolution)
The code roughly looks like this:
var imgUrl = 'https://somewhere.somewhere/myImage.png';
var tilesUrl = 'https://somewhere.somewhere/{z}/{x}/{y}.png';
var tilesBounds = [...];
var imgBounds = [...];
var latlng = [...];
var mymap = L.map('mapid').setView(latlng, 9);
L.tileLayer(tilesUrl, {
attribution: 'TILES',
maxZoom: 12,
minZoom: 7,
id: 'tiles',
tms: true,
maxBounds: tilesBounds
}).addTo(mymap);
var imgOverlay = L.imageOverlay(imgUrl, imgBounds {
attribution: 'dataimg',
opacity: '0.4',
id: 'dataImg',
interactive: true
}).addTo(mymap);
imgOverlay.on('click',
(e) => {
var x = ???;
var y = ???;
var color = getColorAt(x, y);
}
)