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

发布于 2024-11-05 16:09:03 字数 777 浏览 3 评论 0原文

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

以下是我尝试将 KML 直接注入 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 文档。去算算吧。有人有主意吗?

This issue has been plaguing me for about 2 days Google isn't helping me figure this one out. Basically, the code below should be defining the text within the balloon. Unfortunately, it's not working that way. We're ending up with what seems to be the fallback if GE can't handle the style defined in the KML.

Here's one (of many) ways I've tried injecting the KML straight into the GE plugin for rendering.

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);

The code on which this snippet is based came directly from the GE docs. Go figure. Anyone have an idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清晰传感 2024-11-12 16:09:03

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

尝试按照 Google 地球文档有关此内容的说明,将样式定义在单独的文件中:

如果样式定义位于同一文件中,请在样式 ID 前添加 # 号。如果样式定义位于外部文件中,请在元素中包含完整的 URL。

例如:

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

The KML document you're adding later likely can't access the #sitegeom ID you defined at the start in a separate KML document, it's not in-scope.

Try following the Google Earth doc instructions re: this, by placing the style definition in a separate file:

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.

e.g.:

<styleUrl>http://www.example.com/path/to/your/style.kml#sitegeom</styleUrl>
§对你不离不弃 2024-11-12 16:09:03

也许问题对我来说不太清楚,但我认为,您需要在 KML 中描述 Placemark 并在 styleUrl 中定义您的样式
就像这样:

<?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>
    <Placemark>
        <Point>
            <coordinates>104.30000001,52.283333343333</coordinates>
        </Point>
        <styleUrl>#sitegeom</styleUrl>
    </Placemark>
  </Document>
</kml>

这是正确的想法吗?

Maybe question not so clear for me, but i think, you need to describe Placemark in your KML and define your style in styleUrl
Like this:

<?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>
    <Placemark>
        <Point>
            <coordinates>104.30000001,52.283333343333</coordinates>
        </Point>
        <styleUrl>#sitegeom</styleUrl>
    </Placemark>
  </Document>
</kml>

Is it right idea?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文