Open GoogleCodeExporter opened 9 years ago
By the way, the documentation for the KMLMouseEvent (
http://code.google.com/apis/earth/documentation/reference/interface_kml_mouse_ev
ent.html
) is incorrect.
The description for getScreenX() should not be the same as for getClientX().
getScreenX() gives you the coordinates relative to the desktop and not relative
to
the ge window.
Original comment by vandint...@gmail.com
on 4 Apr 2009 at 9:49
In the mean-time I did find a workaround for the main issue.
I can obtain the ge window width via:
document.getElementById("map3d_container").offsetWidth and use that to calculate
fraction or insert_pixel values myself.
Original comment by vandint...@gmail.com
on 4 Apr 2009 at 10:04
Add ca call to resizeWindow in the html body:
<div onresize="resizeWindow();">
This will call the resizeWindow function every time the size of the browser
window
changes.
You can also write an event handler for the
var windowWidth = 1;
var windowHeight = 1;
var screenAspect = 1;
function resizeWindow(){
var container = document.getElementById('map3d');
windowWidth = container.offsetWidth;
windowHeight = container.offsetHeight;
screenAspect = windowWidth / windowHeight;
}
I recommend to keep global variables around like:
var mouseInsetX;
var mouseInsetY;
var mouseFractionsX;
var mouseFractionsY;
update those in your mouse event handlers like:
mouseInsetX = windowWidth - event.getClientX();
mouseInsetY = windowHeight - event.getClientY();
mouseFractionsX = event.getClientX()/windowWidth;
mouseFractionsY = 1 - (event.getClientY()/windowHeight);
Now you can use these variables whenever you need.
Notice I also calculate the screenAspect
That comes in handy when you want to display a screen overlay bitmap undistorted
using fractional sizing.
eg: a square bitmap
overlay.getSize().setX(0.1);
overlay.getSize().setY(0.1 * screenAspect);
You need those variables for any serious application you want to write in
Google Earth.
Note: The whole thing collapses when you zoom in on a browser. The API simply
needs
to support various units for mouse events or at least give us a real window
dimension
via the KMLWindow object. (I am logging this as a separate issue)
Original comment by vandint...@gmail.com
on 9 May 2010 at 11:10
Original issue reported on code.google.com by
vandint...@gmail.com
on 4 Apr 2009 at 9:43