活动点击Kml Placemark

时间:2013-06-08 11:57:41

标签: javascript kml google-earth-plugin

我用kml创建了一个地标,名字和ID ='campania'

我使用方法google.earth.fetchKml(ge, href, function())

上传了它

我在地图上看到了一个地标 我想添加地标可以点击,我发现这个方法获取地标的ID placemark=ge.getElementByUrl('http://web.uniparthenope.it/~0124000489/tw-2013/place.kml#campania');

使用方法

使其可点击

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

它不起作用使我在应该开始巡演时出现带有地标名称的气泡 并给我这个错误

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

你能帮忙吗?也许kml你做不到?我必须使用谷歌API创建地标才能使它们可点击? 感谢

1 个答案:

答案 0 :(得分:1)

当您尝试添加事件处理程序时,placemark变量为空。

猜测行中的url或id是错误的

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

或者你在kml dom实际加载之前调用它,因此无法找到地标。

要修复,请尝试调用地标访问器并在fetchKml操作的事件回调中添加事件侦听器。

像这样。

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 */ }

查看您提供的链接中的KML似乎没有定义或链接到<gx:Tour>。所以不可能说你应该如何处理比赛部分。听起来你想要加载一个复杂的游览(即KML文档中会有更多而不仅仅是单个<gx:Tour>特征)所以也许最好通读touring documentation for the the Api它清楚地显示了如何处理所有这些。

相关问题