网址中的kml气球中的动态内容 [英] dynamic content in kml balloon from url

查看:107
本文介绍了网址中的kml气球中的动态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a server that is serving up an xhtml page with all of the content I want displayed in my google earth (or worldwind) balloon. I would like the placemark balloon to fetch the html page when it is clicked on the map. To make it simple, I want my balloon to be www.yahoo.com when you click it from the map.

任何在线搜索都会将我发送到可以挂接到Google Earth API的Java代码中.我真的希望有一种客户端KML方式可以做到这一点.我可以使用扩展数据标签或描述标签来使它起作用吗?我什至尝试使用embed标签,该标签对您的视频非常有用,但是没有用于html页面的插件.非常感谢您的帮助.

Any searching online sends me to java code that can hook into the google earth api. I am really hoping there is a client side kml way to do this. Is there an extended data tag or description tag I can use to get this to work? I have even tried to use the embed tag which works great for a you tube video but there is no plugin for an html page. Any help is much appreciated.

这也可以,但是iframe很难看-

This works too but an iframe is pretty ugly -

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

推荐答案

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

you could try the getBalloonHtmlUnsafe() and the HtmlDivBalloon? https://developers.google.com/earth/documentation/balloons#getballoonhtmlunsafe

不过,您要将kml添加到页面中,然后可以将click函数绑定到这些地标.

However you are adding the kml to the page you could then bind a click function to those placemarks.

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.

If that still doesn't work, remember that google earth scrubs a lot of balloon data so you might try using jquery to inject the 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);

这篇关于网址中的kml气球中的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆