Detect click on Buidings not on placemark !

7 views
Skip to first unread message

sseb.blanc

unread,
Dec 18, 2009, 10:28:57 AM12/18/09
to KML Developer Support - KML Server Side Scripting
Hello all,

i'm trying to add an eventlistener on one of my buidings loaded in GE
with

my code is :
google.earth.addEventListener(my, 'click', traceok);

but it's not working and i don't understand why !

i saw in the doc that click dbclick exist on KmlFolder or KmlDocument
but never works on buildings! only working on placemark.
Is that normal ?

thx

sseb.blanc

unread,
Dec 18, 2009, 11:44:55 AM12/18/09
to KML Developer Support - KML Server Side Scripting
means BuiLdings ... sorry

api.ss

unread,
Jan 7, 2010, 2:09:48 PM1/7/10
to KML Developer Support - KML Server Side Scripting
The 'my' in your event listener should refer to your building. Refer
to this Ajax playground for testing your code:

http://code.google.com/apis/ajax/playground/?exp=earth#hello,_earth

-ss

api.ss

unread,
Jan 7, 2010, 2:36:12 PM1/7/10
to KML Developer Support - KML Server Side Scripting
Below is how to set up an event on a polygon (Polygon Click Event).
Try it in the Ajax Playground.


----------------------
var ge;

google.load("earth", "1");

function init() {
google.earth.createInstance('map3d', initCallback, failureCallback);

addSampleButton('Create a Polygon!', buttonClick);
}

function initCallback(instance) {
ge = instance;
ge.getWindow().setVisibility(true);

// add a navigation control
ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

// add some layers
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
la.setRange(50000);
ge.getView().setAbstractView(la);

createPolygon();

document.getElementById('installed-plugin-version').innerHTML =
ge.getPluginVersion().toString();
}

function failureCallback(errorCode) {
}

function createPolygon() {
var polygonPlacemark = ge.createPlacemark('');
var polygon = ge.createPolygon('');
polygonPlacemark.setGeometry(polygon);
var outer = ge.createLinearRing('');
polygon.setOuterBoundary(outer);

// Square outer boundary.
var center = ge.getView().copyAsLookAt
(ge.ALTITUDE_RELATIVE_TO_GROUND);
var coords = outer.getCoordinates();
var lat = center.getLatitude();
var lon = center.getLongitude();
coords.pushLatLngAlt(lat - .05, lon - .05, 0);
coords.pushLatLngAlt(lat - .05, lon + .05, 0);
coords.pushLatLngAlt(lat + .05, lon + .05, 0);
coords.pushLatLngAlt(lat + .05, lon - .05, 0);

// Another square as the inner boundary. Note that we can create
// any number of inner boundaries.
var innerBoundary = ge.createLinearRing('');
polygon.getInnerBoundaries().appendChild(innerBoundary);
coords = innerBoundary.getCoordinates();
coords.pushLatLngAlt(lat - .02, lon - .02, 0);
coords.pushLatLngAlt(lat - .02, lon + .02, 0);
coords.pushLatLngAlt(lat + .02, lon + .02, 0);
coords.pushLatLngAlt(lat + .02, lon - .02, 0);

ge.getFeatures().appendChild(polygonPlacemark);

google.earth.addEventListener(polygonPlacemark, 'click', function
(event) {
alert("Polygon Click Event");
});
}

function buttonClick() {
createPolygon();
Reply all
Reply to author
Forward
0 new messages