这个问题已经困扰我大约 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/