【问题标题】:dynamic content in kml balloon from url来自 url 的 kml 气球中的动态内容
【发布时间】:2012-06-30 13:14:58
【问题描述】:

我有一个服务器正在提供一个 xhtml 页面,其中包含我想要在我的 google earth(或 worldwind)气球中显示的所有内容。我希望地标气球在地图上单击时获取 html 页面。为简单起见,当您从地图上单击它时,我希望我的气球是 www.yahoo.com。

任何在线搜索都会将我发送到可以连接到 google earth api 的 java 代码。我真的希望有一种客户端 kml 方式来做到这一点。我可以使用扩展数据标签或描述标签来使其工作吗?我什至尝试使用 embed 标签,它非常适用于你的视频,但没有适用于 html 页面的插件。非常感谢任何帮助。

这也可以,但 iframe 很丑 -

<Placemark> 
  <name>Test Placemark</name> 
    <description> 
      <![CDATA[ 
        <iframe src="http://www.yahoo.com" frameborder="0" 
           scrolling="auto" height="500" width="600"></iframe> 
      ]]> 
    </description> 
...

【问题讨论】:

    标签: kml google-earth google-earth-plugin balloon


    【解决方案1】:

    你可以试试 getBalloonHtmlUnsafe() 和 HtmlDivBalloon 吗? https://developers.google.com/earth/documentation/balloons#getballoonhtmlunsafe

    但是,您将 kml 添加到页面,然后您可以将点击功能绑定到这些地标。

    google.earth.fetchKml(ge, url, function(kmlObject){
       if(kmlObject){
          ge.getFeatures().appendChild(kmlObject);
    
          if(kmlObject.getType() === 'KmlPlacemark'){
              google.earth.addEventListener(kmlObject, 'click', function(event){
                   event.preventDefault();
    
                   var balloon = ge.createHtmlDivBalloon('');
                   var content = kmlObject.getBalloonHtmlUnsafe();
                   balloon.setFeature(kmlObject);
                   var div = document.createElement('div');
                   div.innerHTML = content;
                   balloon.setContentDiv(div);
    
                   ge.setBalloon(balloon);
              });
          }
       }
    });
    

    如果这仍然不起作用,请记住 google earth 会清除大量气球数据,因此您可以尝试使用 jquery 来注入 html。

    var balloon = ge.createHtmlDivBalloon('');
    var content = kmlObject.getBalloonHtmlUnsafe();
    balloon.setFeature(kmlObject);
    var div = document.createElement('div');
    balloon.setContentDiv(div);
    
    ge.setBalloon(balloon);
    $(div).html(content);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      相关资源
      最近更新 更多