【问题标题】:Event Click Kml Placemark事件点击 Kml 地标
【发布时间】:2013-06-04 15:47:08
【问题描述】:

我在 kml 中创建了一个地标,其名称和 ID = 'campania'

我用google.earth.fetchKml(ge, href, function())的方法上传了

我在地图上看到了一个地标 我想添加地标可以点击,我找到了这个方法来获取地标的ID placemark=ge.getElementByUrl('@987654321@');

使用方法使其可点击

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

它不起作用让我在应该开始游览时出现带有地标名称的对话气泡 并给我这个错误

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

你能帮忙吗?也许你不能做kml?我必须使用谷歌 API 创建地标以使其可点击? 谢谢

【问题讨论】:

    标签: javascript kml google-earth-plugin


    【解决方案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 它清楚地显示了如何处理所有这些.

    【讨论】:

    • 函数完成(object) { if (object) { ge.getFeatures().appendChild(object); } 地标 = ge.getElementByUrl(url + '#campania'); google.earth.addEventListener(placemark, 'click', playTour); }​ 感谢您的回复,我尝试过这种方式但它不起作用,当我点击地标时我地标的名称并没有开始游览
    • 您的问题是关于使加载的地标可点击和Uncaught TypeError - 而不是玩旅游。那你是什么意思它不起作用?你期望它做什么?要进行巡回演出,您需要添加代码才能完成!见:developers.google.com/earth/documentation/touring
    猜你喜欢
    • 2013-02-04
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多