简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM