kml - Google 地球 KML 无法正确渲染气球样式

标签 kml google-earth-plugin

这个问题已经困扰我大约 2 天了,Google 没有帮助我解决这个问题。基本上,下面的代码应该定义气球内的文本。不幸的是,它不是这样工作的。如果 GE 无法处理 KML 中定义的样式,我们最终会采取后备措施。

这是我尝试将 KML 直接注入(inject) GE 插件进行渲染的一种(多种)方法。

var kmlString = '' +
'<?xml version="1.0" encoding="UTF-8"?>' +
'<kml xmlns="http://www.opengis.net/kml/2.2">' +
'  <Document>' +
'    <Style id="sitegeom">' +
'      <BalloonStyle>' +
'       <text>' +
'           <![CDATA[' +
'           this is<br>a test' +
'           ]]>' +          
'       </text>' +
'      </BalloonStyle>' +
'    </Style>' +
'  </Document>' +
'</kml>';

var kmlObject = $wnd.ge.parseKml(kmlString);
$wnd.ge.getFeatures().appendChild(kmlObject);

此代码片段所基于的代码直接来自 GE 文档。去搞清楚。大家有什么想法吗?

最佳答案

您稍后添加的 KML 文档可能无法访问您在单独的 KML 文档中开始时定义的 #sitegeom ID,它不在范围内。

尝试按照 Google 地球文档 instructions re: this 进行操作,通过将样式定义放在单独的文件中:

If the Style definition is within the same file, precede the Style ID with a # sign. If the Style definition is in an external file, include the complete URL in the element.

例如:

<styleUrl>http://www.example.com/path/to/your/style.kml#sitegeom</styleUrl>

关于kml - Google 地球 KML 无法正确渲染气球样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5913325/

相关文章:

windows - Google 地球插件 - 添加多点触控手势

Python 从包含多个地标的 KML 文件中提取数据

iphone - 通过目的地的 Google map KML 输出或带有 MKMapkit 的 Google Direction API

javascript - GEPlugin 不会从 JSON 加载所有数据

javascript - 如何获取地标上点击点的经度、纬度和海拔高度?

javascript - 如何让可拖动的 jQuery UI 对话框出现在 Google 地球插件顶部?

javascript - 使用 Google Earth API 捕获相机 View

delphi - 如何在Delphi上对图像进行地理配准?

iphone - 将 KML 或 URL 映射添加到 iPhone 应用程序

ruby - 使用正则表达式找到一个字符串,然后使用正则表达式找到一个新的字符串来替换它