2
votes

Is it possible to have interactive elements (e.g. polygon responding to drag and click events) in Google Earth (I specifically need Google Earth, not Google Earth Plugin!) The documentation doesn't seem to be helpful as most of the activity has moved towards the plugin, but the project in question is using Google Earth. I know I have full access to JavaScript and WebKit inside the balloons, but can I use JavaScript to access KML elements and assign event listeners to them?

UPDATE: Let's say I want to use Google Earth to control a web cam. The KML would show the region of the field of view of the camera. I would like to be able to drag that region, have JavaScript handle that dragging and invoke a web service which would rotate the webcam accordingly.

1
Can you elaborate on other interactive behavior you want to respond to besides responding to click or drag events in Google Earth? - JasonM1

1 Answers

1
votes

Directly responding to polygon click and drag events in Google Earth (outside of using the GE API and Plugin) doesn't offer you much options. Using GE API it's easy but in the Google Earth client you cannot directly respond to moving or dragging a placemark. Also, once a placemark is sent to the client, its location if moved cannot be accessed via client-side JavaScript and sent back to the server.

There are a number interactive techniques to use in KML and Google Earth, some of which might work with what you're trying to do.

  • You can provide controls or configuration options in HTML forms in the description balloons to customize the display or change location of web camera :

    For camera control you could show up, down, left, right buttons (maybe even zoom or tilt) in the balloon description and clicking any of those buttons which calls your backend controller to move the camera. The output of the action could use NetworkLinkControl to update the KML already loaded in Google Earth.

  • You can consider NetworkLinks which specify a viewFormat via a backend KML generation service. You can specify a NetworkLink to refresh and report back to the backend service with the view/camera information and/or other client-side parameters if the view changes. You could respond to view changes (zoom in/out, pan, tilt, etc.) and change state accordingly. If you further constrain NetworkLink updates with onStop then you can prevent incremental updates when user is in process of moving and only send refresh updates after user has stopped moving, which presumably user is looking at something.

The viewFormat would give you access to the following client properties of Google Earth:

 [lookatLon], [lookatLat], [lookatRange], [lookatTilt], [lookatHeading]
 [lookatTerrainLon], [lookatTerrainLat], [lookatTerrainAlt]
 [cameraLon], [cameraLat], [cameraAlt]
 [horizFov], [vertFov]
 [horizPixels], [vertPixels]
 [terrainEnabled]