If I dynamically render a polygon (for example the border of a district in the UK) on a map, with OpenLayers 3, is it possible somehow to zoom in on the polygon, until it exactly fits the view?

1 Answer 1


You can't ever guarantee to exactly fit the view as in general your district may have a different aspect ratio (width/height) than your view.

OpenLayers 3 provides the useful fit method on the view to allow you to do this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.