我有许多大型的KML数据集,它们使用基于区域的网络链接层次结构进行服务;如KML reference描述:谷歌地球API中基于地区的网络链接
使用区域与NetworkLink一起配合,您可以创建指针层次结构,每个指向一个特定子区域。如以下KML文件所示,
<viewRefreshMode>
具有onRegion选项,该选项指定仅在区域处于活动状态时加载区域数据。如果您提供具有多个细节级别的嵌套区域,则只有当用户的视点触发下一个加载时才加载更大量的数据。
这在加载到Google地球中时效果很好。
我现在希望在使用Google Earth plug-in的应用程序中加载这些文件。 我需要通过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);
}
}
这可能吗?
我在思考中转弯了吗?我相信我遵循了管理大型KML数据集的推荐做法,但我不确定如何通过API使用这些数据集。
附录:
由于问题我试图解决这个类型的例子: 想象一下你正在建设使用谷歌地球插件的Web应用程序,并且你要显示每一组地标世界上的交通灯。地标应该只显示在适当的详细程度上(例如,当相机在5公里高度时)。当用户点击地标时,我们希望网络应用程序为该组交通灯加载统计信息,并将其显示在侧栏中。
你会如何设计这个?
你说得对。通过设置'全局'级别的事件处理程序,我可以过滤目标ID以确定如何处理事件。谢谢! – 2012-08-27 07:01:24
不用担心,很高兴有帮助。 – Fraser 2012-08-28 16:31:45