2 mar 2009

Przeliczenie pozycji kursora myszy na współrzędne latlng

<img decoding="async" fetchpriority="high" id="maska_img" src="moa.net.pl.jpg" width="300" height="300" onClick="testMaskClick()">
function testMaskClick() {

var IE = document.all ? true : false;
 if (IE) {
  tempX = event.clientX + document.body.scrollLeft;
  tempY = event.clientY + document.body.scrollTop;
 } else {
  tempX = e.pageX;
  tempY = e.pageY;
 }
 if (tempX < 0) tempX = 0;
 if (tempY < 0) tempY = 0;
 
 var point1 = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
var point = map.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(point1.x+tempX-300, point1.y-(650-tempY+20)), map.getZoom());

map.addOverlay(new GMarker(point));
}

300,20 - pozycja mapy na stronie
650 - wysokość mapy