how to zoom/pan automatically to all features in a vector layer?

Refresh

1 weeks ago

Views

1.6k time

1

Using Openlayers, I would like to initialize the map in a position where it shows all the features in a vector layer. How to do that?

2 answers

4

This is a little sharp/rough

map.zoomToExtent(yourVectorLayer.getDataExtent());

This may be smoother

map.panTo(yourVectorLayer.getDataExtent().getCenterLonLat());
map.zoomTo(yourVectorLayer.getDataExtent().getZoomExtent());
4

Это немного острый / грубый

map.zoomToExtent(yourVectorLayer.getDataExtent());

Это может быть гладким

map.panTo(yourVectorLayer.getDataExtent().getCenterLonLat());
map.zoomTo(yourVectorLayer.getDataExtent().getZoomExtent());