inside my webgis application with Ol3 I've to zoom to a single feature.
Obviusly I want to see the whole feature when I zoom. I tried this dirty workaround:
map.getView().fit(feature.getGeometry(), map.getSize()); var geom_centre = map.getView().getCenter(); var lon = geom_centre - 50; var north_centre = [geom_centre,lon]; map.getView().setCenter(north_centre); map.getView().setZoom(map.getView().getZoom() - 1);
Essentially I made the "classical" zoom and then I move to north the centre of the view and go back of one zoom level. It doesn't work well because the features have different dimensions and I move them to north of arbitrary length (50) and the smallest features are pushed outside view to north.
How can I zoom to a feature and move it to north without push it outside the view?