简体   繁体   中英

How to set map center on loaded GeoJSON features or what event is sent upon loadGeoJson completion with 3.16 javascript API for Google Maps?

I would like to show newly (optionally) loaded GeoJSON features. For this I need to center somewhere around their bounding box center. I'd like to do that on client side instead of making yet another request to get center coordinates from the server.

For instance if I'm showing the only point feature, it would be reasonable to getFeatureById (as I know id) and get its geometry and corresponding LatLng. However as far as I know Google Maps is using asynchronous loading so I can't do it right away. I recall a question in here that I can't find anymore that mentioned that.

So how would I center on features acquired with loadGeoJson or what event shall I listen to when it is done loading all features?

Do I have to listen to google.maps.Data.AddFeatureEvent ? That would work for a single point that I know ID of, but what shall I do for several features?

I have answered that question on this posting : do centering with the centers of the layers -->

OL3: Zoom to vector layer on map

Hope it works for your case.

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