在谷歌地图或谷歌地球插件中惰性/需求加载KML?
一旦 Google 地图或 Google 地球插件实例启动,是否可以延迟加载 KML 文件?也许有一个“边界框”事件,我可以用它来排队所需的 KML 文件?
编辑 =>找到了答案:
找到了这个小窍门(http://code. google.com/apis/maps/documentation/javascript/events.html ):
注意:如果您尝试检测 改变视口,一定要使用 特定的bounds_changed事件 而不是组成部分zoom_changed 和 center_changed 事件。因为 地图 API 会触发后面这些事件 独立地, getBounds() 可能不会 报告有用的结果,直到 视口已发生权威性更改。 如果你想在这样之后 getBounds() 一个事件,一定要听 相反,bounds_changed 事件。
...这使我进入此页面上的“视口标记管理”:http ://code.google.com/apis/maps/articles/tooomymarkers.html#viewportmarkermanagement
建议这个基本想法:
google.maps.event.addLisener(map, 'idle', showMarkers);
function showMarkers() {
var bounds = map.getBounds();
// Call you server with ajax passing it the bounds
// In the ajax callback delete the current markers and add new markers
}
同样,对于 GEP,有这样的:
GEView.getViewportGlobeBounds()
返回一个完全的边界框 包含地球上的区域 目前可见。退回的盒子 会比严格意义上的要大 可见,如果有必要的话 包括所有可见的内容。返回一个对应的KmlLatLonBox 到当前的边界框 视口或 null 如果没有部分 地球仪可见
Is it possible to lazy load KML files once a Google Map or Google Earth Plugin instance is started? Maybe there is there a "bounding box" event that I can use to queue needed KML files?
Edit => Found an answer:
Found this little tid-bit ( http://code.google.com/apis/maps/documentation/javascript/events.html ):
Note: If you are trying to detect a
change in the viewport, be sure to use
the specific bounds_changed event
rather than constituent zoom_changed
and center_changed events. Because the
Maps API fires these latter events
independently, getBounds() may not
report useful results until after the
viewport has authoritatively changed.
If you wish to getBounds() after such
an event, be sure to listen to the
bounds_changed event instead.
...which led me to "Viewport Marker Management" on this page: http://code.google.com/apis/maps/articles/toomanymarkers.html#viewportmarkermanagement
Suggesting this basic idea:
google.maps.event.addLisener(map, 'idle', showMarkers);
function showMarkers() {
var bounds = map.getBounds();
// Call you server with ajax passing it the bounds
// In the ajax callback delete the current markers and add new markers
}
Similarly, for GEP, there is this:
GEView.getViewportGlobeBounds()
Returns a bounding box that completely
contains the region of the globe that
is currently visible. The returned box
will be larger than what is strictly
visible, if that is necessary to
include everything that is visible.Returns a KmlLatLonBox corresponding
to the bounding box of the current
viewport or null if no part of the
globe is visible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,KML 区域仅当数据位于用户视图内并占据屏幕的特定部分时才允许加载和绘制数据。因此,如果您在 Google 地球插件或 Google 地图 API 中使用 KML,则无需自己编写...
请参阅有关使用 Kml 区域的精彩文档:
http://code.google.com/apis/kml/documentation/regions.html
连同kmlRegion接口参考
http://code.google.com/apis/kml/documentation/kmlreference .html#region
Yes, KML regions allow data to be loaded and drawn only when it falls within the user's view and occupies a certain portion of the screen. So there is no need to cook your own if you are using KML in the Google Earth Plugin or Google Maps Apis...
See this great document on using Kml regions:
http://code.google.com/apis/kml/documentation/regions.html
Along with the kmlRegion interface reference
http://code.google.com/apis/kml/documentation/kmlreference.html#region