ajayagarwal1567 / earth-api-samples

Automatically exported from code.google.com/p/earth-api-samples
0 stars 0 forks source link

Allow setXUnits and setYUnits on getClientX calls in a KMLMouseEvent. #209

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What should this feature enhancement do?

Allow setXUnits and setYUnits on getClientX calls on a KML Mouse event.

I can also place screen overlays using UNITS_FRACTION or UNITS_INSET_PIXELS
Now I want to know where I clicked on the screen in relation to this screen
overlay.

For a screenoverlay I code:
screenOverlay.getScreenXY().setXUnits(ge.UNITS_FRACTION);

I would like to be able to code:

function doMouseClick(event){
  event.getClientX().setXUnits(ge.UNITS_FRACTION);
  alert(event.getClientX());
}

and get a number between 0 and 1 back.

Are there any known workarounds that produce the similar results?

None that I am aware of. Fraction and inset_pixels are very easy to place
overlays but they need a wider support in the API to make them useful.

Original issue reported on code.google.com by vandint...@gmail.com on 4 Apr 2009 at 9:43

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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