如何使用 NetworkLinkControl 和 Java API for KML (JAK) 正确更新 Google 地球 KML?

发布于 2024-12-01 23:05:09 字数 2895 浏览 1 评论 0 原文

我正在构建一个向独立的 Google 地球客户端提供数据的应用程序。我想发送一组初始数据,然后随着服务器上的情况发生变化,使用 标签动态更新它。我正在使用 Java API for KML (JAK) 库生成 KML。不幸的是,虽然我可以确认 GE 正在刷新我的 NetworkLink 并拉下我发送的更新,但我的任何更新都没有显示在 GE 中。经过大量阅读后,似乎更新的 可能是问题所在,但我 99.9% 确定我正在发送相同的字符串。

让我感到困惑的部分原因是,我看到了关于 元素的值是否需要附加到 的冲突信息。当我从静态服务器 URL 提供手写的测试 KML 文件时,我确实看到了一个早期原型的更新,所以我怀疑它不是。实际上,这就是目前令人沮丧的地方:我已经在自己的计算机上看到了更新工作,但现在无法使用看起来有效且正确的 KML 来工作。

当前设置如下所示(为了清晰起见,删除了无关的 XML 命名空间;“$CLIENT_ID”是一个类似 GUID 的字符串):

http://server/kml/${CLIENT_ID}:

<kml  xmlns="http://www.opengis.net/kml/2.2" 
      xmlns:gx="http://www.google.com/kml/ext/2.2" 
      xmlns:atom="http://www.w3.org/2005/Atom"     
      xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><NetworkLink>
  <Link>
    <href>http://server/kmlupdates/${CLIENT_ID}</href>
    <refreshMode>onInterval</refreshMode>
    <refreshInterval>1.0</refreshInterval>
    <viewRefreshTime>0.0</viewRefreshTime>
    <viewBoundScale>0.0</viewBoundScale>
  </Link>
</NetworkLink></kml>

http://server/kmlupdates/${CLIENT_ID}:

<kml><NetworkLinkControl>
    <minRefreshPeriod>0.0</minRefreshPeriod>
    <maxSessionLength>-1.0</maxSessionLength>
    <cookie>cookie=0|kmlRequestType=updates|projectID=6|lastUpdateSeenIndex=-1</cookie>
  </NetworkLinkControl>
  <Document id="myProject">
    <name>My ProjectProject</name>
    <Placemark id="pm1"><name>point1</name>
        <Point><coordinates>-117.0,35.0</coordinates></Point>
    </Placemark>
</Document></kml>

稍后更新从 http: 提供的 KML: //server/kmlupdates/${CLIENT_ID}:

<kml><NetworkLinkControl>
    <minRefreshPeriod>0.0</minRefreshPeriod>
    <maxSessionLength>-1.0</maxSessionLength>
    <cookie>cookie=0|kmlRequestType=updates|projectID=6|lastUpdateSeenIndex=0</cookie>
    <Update>
        <targetHref>http://server/kmlupdates/${CLIENT_ID}</targetHref>
        <Change>
            <Placemark targetId="pm1">
                <name>Name changed by Update Change</name>
            </Placemark>
        </Change>
    </Update>
</NetworkLinkControl></kml>

如果有人对我在这里缺少的内容有任何建议,我将不胜感激。谢谢!

I'm building an application that serves up data to a standalone Google Earth client. I want to send over an initial set of data, then update it dynamically using <NetworkLinkControl> and <Update><cookie> tags as things change on the server. I'm generating the KML using the Java API for KML (JAK) library. Unfortunately, while I can confirm that GE is refreshing my NetworkLink and pulling down the Updates I'm sending, none of my updates are showing up in GE. After lots of reading, it seems like it might be that the Update's <targetHref> might be the issue, but I'm 99.9% sure I'm sending over the same string.

Part of what has me confused is that I've seen conflicting info on whether or not the <cookie> element's value needs to be appended to <targetHref>. I did actually see one early prototype updating when I was serving up hand-written test KML files from a static server URL, so I suspect it's not. Actually, that's what's frustrating at the moment: I've seen updating work on my own machine, but can't get it working now with what looks like valid and correct KML.

The current setup looks like this (extraneous XML namespaces stripped for clarity; "$CLIENT_ID" is a GUID-like string):

Root KML file served from http://server/kml/${CLIENT_ID}:

<kml  xmlns="http://www.opengis.net/kml/2.2" 
      xmlns:gx="http://www.google.com/kml/ext/2.2" 
      xmlns:atom="http://www.w3.org/2005/Atom"     
      xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><NetworkLink>
  <Link>
    <href>http://server/kmlupdates/${CLIENT_ID}</href>
    <refreshMode>onInterval</refreshMode>
    <refreshInterval>1.0</refreshInterval>
    <viewRefreshTime>0.0</viewRefreshTime>
    <viewBoundScale>0.0</viewBoundScale>
  </Link>
</NetworkLink></kml>

Initial content KML served from http://server/kmlupdates/${CLIENT_ID}:

<kml><NetworkLinkControl>
    <minRefreshPeriod>0.0</minRefreshPeriod>
    <maxSessionLength>-1.0</maxSessionLength>
    <cookie>cookie=0|kmlRequestType=updates|projectID=6|lastUpdateSeenIndex=-1</cookie>
  </NetworkLinkControl>
  <Document id="myProject">
    <name>My ProjectProject</name>
    <Placemark id="pm1"><name>point1</name>
        <Point><coordinates>-117.0,35.0</coordinates></Point>
    </Placemark>
</Document></kml>

Later update KML served from http://server/kmlupdates/${CLIENT_ID}:

<kml><NetworkLinkControl>
    <minRefreshPeriod>0.0</minRefreshPeriod>
    <maxSessionLength>-1.0</maxSessionLength>
    <cookie>cookie=0|kmlRequestType=updates|projectID=6|lastUpdateSeenIndex=0</cookie>
    <Update>
        <targetHref>http://server/kmlupdates/${CLIENT_ID}</targetHref>
        <Change>
            <Placemark targetId="pm1">
                <name>Name changed by Update Change</name>
            </Placemark>
        </Change>
    </Update>
</NetworkLinkControl></kml>

If anyone has any suggestions on what I'm missing here, I'd greatly appreciate it. Thanks!

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

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

发布评论

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

评论(3

任谁 2024-12-08 23:05:09

我的问题的原始版本遗漏了两个相关事实:1)我使用 KML 的 Java API 来生成它,2) 内的 XML 命名空间。在阅读这篇 Google KML 群组帖子<后,我终于弄清楚了这一点/a> 第无数次了。

问题出在最后一个 XML 命名空间“xmlns:xal”。由于某种原因,从 KML 中删除它可以让 标签实际更改 Google 地球中的项目。 JAK 不允许您更改名称空间,但您可以手动将其从封送字符串中删除。

绝对奇怪,但至少我找到了解决方案。

My original version of the question left out two facts that turned out to be relevant: 1) I'm using the Java API for KML to generate this, and 2) the XML namespaces inside <kml>. I finally figured this out after reading this Google KML Group post for the umpteenth time.

The problem is the last XML namespace, "xmlns:xal". For some reason, removing that from the KML allows the <Update> tags to actually change the items in Google Earth. JAK doesn't let you change the namespaces, but you can strip it manually from the marshaled string.

Absolutely bizarre, but at least I found a solution.

暗恋未遂 2024-12-08 23:05:09

根据https://developers.google.com/kml/documentation/kmlreference

<xal:AddressDetails> is used by KML for geocoding in Google Maps only.
Currently, Google Earth does not use this element; use <address> instead.

As per https://developers.google.com/kml/documentation/kmlreference:

<xal:AddressDetails> is used by KML for geocoding in Google Maps only.
Currently, Google Earth does not use this element; use <address> instead.
梅倚清风 2024-12-08 23:05:09

我有一些示例使用不同的方法来做其他可能与您相关的事情(因为您的目的“发送一组初始数据,然后使用标签动态更新它”):

https://sites.google.com/site/canadadennischen888/home/kml/auto-refresh-3d-tracking

做法是所有更改均来自服务器 Restful 服务。希望有帮助。详细信息为:

如何进行动态自动刷新 3D 跟踪:

  1. 准备 RestFul 服务从数据库生成 KML 文件(KML 示例如上面链接内)

  2. 我的其他 jsp 代码将生成一个 KMZ 文件,其中包含指向我的 Restful 服务的链接。 KMZ 文件有 onInterval (如底部所示)

  3. Jsp 网页允许用户下载 KMZ 文件。

  4. 当 Google 地球打开 KMZ 文件时,Google 地球将自动刷新以从该 Restful 服务获取新数据

  5. 每次刷新时,服务器都会向GE发送最新更新的KML数据和新数据。

KMZ 样本:

    <?xml version="1.0" encoding="UTF-8"?>
     <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" 
     xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
     <NetworkLink> 
     <name>[email protected]</name> 
     <open>1</open> 
     <Link> 
     <href>http://localhost:9080/google-earth-project/rest/kml/10001/20002</href> 
     <refreshMode>onInterval</refreshMode> 
     </Link>
     </NetworkLink>
     </kml>

I have some sample using different approach to do something else here maybe related to yours (as your purpose "send over an initial set of data, then update it dynamically using tags") :

https://sites.google.com/site/canadadennischen888/home/kml/auto-refresh-3d-tracking

Approach is that all changes are from server Restful service. Hope it helps. Details as :

How to make a dynamic Auto refresh 3D Tracking :

  1. prepare a RestFul service to generate KML file from DB (KML sample as inside above link)

  2. My other jsp code will generate a KMZ file which has a link to my Restful service. KMZ file has onInterval ( as in the bottom)

  3. Jsp web page allow user to download KMZ file.

  4. When Google Earth open KMZ file, Google Earth will auto refresh to get new data from that Restful service

  5. Everytime refreshing, server will send the latest update KML data with new data to GE.

KMZ sample:

    <?xml version="1.0" encoding="UTF-8"?>
     <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" 
     xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
     <NetworkLink> 
     <name>[email protected]</name> 
     <open>1</open> 
     <Link> 
     <href>http://localhost:9080/google-earth-project/rest/kml/10001/20002</href> 
     <refreshMode>onInterval</refreshMode> 
     </Link>
     </NetworkLink>
     </kml>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文