lazy / demand load KML in google maps or google earth plugin?

ぃ、小莉子 提交于 2019-12-12 10:09:50

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/5683122/lazy-demand-load-kml-in-google-maps-or-google-earth-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!