Google Earth application framework. W-A-S-D to move the view. See code and comments for further details.
The demo code shows how Google Earth is initialised from the HTML page. As a bonus it already implements a fullscreen toggle.
All the code is run from the "Frameend" event handler. Make sure to lookup "handleFrame" in framework.js. All other event handlers do little more than setting global variables representing key and mouse button states and cursor position.
The FrameEnd handler keeps track of the amount of time that has past since the last frame was drawn. This deltaTime is then used everywhere to scale animations to the frame rate so all animation is independent of the computer performance.
The earth is round and as such you can not treat latitude and longitude as a linear x and y axis like you do in a flat grid. 1 degree latitude change always represents 360 Nuatical miles but 1 degree longitude change is different dependon on which latitude you are. For example. At the equator 1 degree longitude change is also 360 nautical miles but at the north pole it will be zero! The relationship between latitude and longitude is the cosine of the latitude.
All of this stuff is handled in the globals.js unit. Here global conversion variables are maintained that enable you to easily convert meters into latitude and longitude change. See this demo for more details
Finally, note the ge.getWindow().blur(); statement in the mouseup event handler. Here the focus is pushed back to the page when a mouse button is released. This is a hack to ensure we keep receiving keyboard events.
©2009 All Rights Reserved • by PlanetInAction.com