Google Earth API中基于地区的网络链接

MJ *_*son 6 kml google-earth-plugin

我有许多大型KML数据集,它们使用基于区域的网络链接层次结构来提供服务; 如KML参考中所述:

将Regions与NetworkLinks结合使用,可以创建指针层次结构,每个指针指向一个特定的子区域.如<viewRefreshMode>以下KML文件所示,具有onRegion选项,该选项指定仅在Region处于活动状态时加载Region数据.如果为嵌套区域提供多个详细级别,则仅当用户的视点触发下一个加载时才会加载更大量的数据.

这在Google地球中加载时效果很好.

我现在希望使用Google Earth插件在应用程序中加载这些内容. 我需要通过Google Earth API访问加载的内容 ; (即附加单击事件,更改样式)以将内容集成到应用程序中.

问题是,我没有找到任何关于网络链接的"有载"事件的参考.在我看来,这将起作用的方式是:

  • 通过API加载顶级网络链接,附加一个回调函数,该函数将在加载网络链接时调用.
  • 在回调函数中,解析网络链接返回的KML.对于区域层次结构中的中间级别,此KML将仅包含指向下一个区域级别的网络链接.通过API将它们加载到插件中,再次指定相同的回调函数,当加载它们时(即当它们的区域变得可见时)将调用它.
  • 最终,返回的KML将包含实际的"内容".在此阶段,我们在执行任何所需的修改(例如附加事件监听器,设置样式等)之后将实际内容(即地标)加载到插件中.

我认为javascript看起来像下面这样.
请注意:这只是一个草图,可能有助于理解我的问题.不是问为什么这段代码不起作用.

//create network link
var networkLink = ge.createNetworkLink("");
networkLink.setName("Regionated hierarchy root");

// create a Link object
//the network-links contained in the kml that will be returned in this file
//are region-based; they will only be loaded when the user zooms into the relevant
//region. 
var link = ge.createLink("");
link.setHref("http://foo.com/regionatedRoot.kml");

// attach the Link to the NetworkLink
networkLink.setLink(link);

//specify the callback function to be invoked when the network link is loaded
//this is is the part that doesn't actually exist; pure fiction...
networkLink.onLoad = networkLinkLoaded;

// add the NetworkLink feature to Earth
ge.getFeatures().appendChild(networkLink);

// function which will be invoked when a network-link is loaded
// i.e. when its region becomes active
function networkLinkLoaded(kml) {

   //parse the kml returned for child network links,
   //this will create the network link KmlObject, with a 
   //region specified on it.
   for (childNetworkLink in parseNetworkLinks(kml)) {
      //and append them, again hooking up the call-back
      childNetworkLink.onLoad = networkLinkLoaded;
      ge.getFeatures().appendChild(childNetworkLink);
   }

   //if the user has zoomed in far enough, then the kml returned will
   //contain the actual content (i.e. placemarks).
   //parse the kml returned for content (in this case placemarks)
   for (placemark in parsePlacemarks(kml)) {
      //here we would attach event-listeners to the placemark
      ge.getFeatures().appendChild(placemark);
   }
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?
我的思维错误了吗?我相信我已经遵循了管理大型KML数据集的推荐做法,但我不确定如何通过API使用这些数据集.

附录:

作为我想要解决的问题类型的一个示例:想象一下,您正在使用Google地球插件构建Web应用程序,并且您想要为世界上的每组交通灯显示地标.地标应仅以适当的细节水平显示(例如,当摄像机处于5公里高度时).当用户点击地标时,我们希望网络应用加载该组交通信号灯的统计信息,并将其显示在侧边栏中.

你会如何设计这个?

Fra*_*ser 1

您无需直接访问对象数据即可提供所需的功能。您将使用基于区域的网络链接层次结构来处理数据加载,就像您所做的那样。然后,如果您的使用场景类似于您在附录中列出的场景,那么您只需使用点击事件中的目标数据来根据需要加载基于地标的统计数据即可。

例如,您可以简单地在窗口对象上设置一个通用的 mousedown 事件处理程序,然后测试目标是否是地标。您可以在加载任何数据之前添加此通用侦听器,当您单击动态加载的地标时,它仍然会被触发。根本不需要将单独的事件侦听器附加到地标。

例如

window.google.earth.addEventListener(ge.getWindow(), 'mousedown', onWindowMouseDown);

var onWindowMouseDown = function(event) {
  if (event.getTarget().getType() == 'KmlPlacemark') {
    // get the placemark that was clicked
    var placemark = event.getTarget();

    // do something with it, or one of its relative objects...
    var document = placemark.getOwnerDocument();
    var parent = placemark.getParentNode();

    // etc...
  }
}
Run Code Online (Sandbox Code Playgroud)