سؤال

I created a placemark in kml with a name and ID = 'campania'

I uploaded it using the method google.earth.fetchKml(ge, href, function())

and I see a placemark on the map I would like to add placemarks can be clicked, I found this method to get the ID of the placemark placemark=ge.getElementByUrl('http://web.uniparthenope.it/~0124000489/tw-2013/place.kml#campania');

To make it clickable using the method

google.earth.addEventListener(placemark, 'click',playTour);

It does not work makes me appear a speech bubble with the name of the placemark when it should start the tour and gives me this error

"Uncaught TypeError: Cannot call method 'getEventHandlersId' of null

Can you help? Perhaps kml you can not do? I have to create the placemark with google API to make them clickable? Thanks

هل كانت مفيدة؟

المحلول

Your placemark variable is null when you are trying to add the event handler.

At a guess either the url or id is wrong in the line

var placemark = ge.getElementByUrl('http://web.uniparthenope.it/~0124000489/tw-2013/place.kml#campania');

or else you are calling it before the kml dom has actually loaded and so the placemark can't be found.

To fix, try calling the placemark accessor and adding the event listener from within the event callback for the fetchKml operation.

Something like so.

var href = 'http://web.uniparthenope.it/~0124000489/tw-2013/place.kml'
google.earth.fetchKml(ge, href, fetchKmlCallback);

function fetchKmlCallback(kml) {
  if(kml) {
     ge.getFeatures().appendChild(kml);
     var placemark = ge.getElementByUrl(href + '#campania');
     google.earth.addEventListener(placemark, 'click', playTour);
  }
}

function playTour() { /* handle playing here */ }

Looking at the KML in the link you provided there doesn't seem to be a <gx:Tour> defined or linked to. So it is impossible to say how you should handle the playing part. It sounds like you want to load a complex tour (i.e. there will be more in the KML document than just a single <gx:Tour> feature) so perhaps it would be best to read through the touring documentation for the the Api it clearly shows how to handle all this.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top