I want to draw a square around a marker. if I draw a large square the map should zoom out automatically so that we can see the square completely. If I draw a small square the map should zoom in automatically to show the square completely.
In this image I have drawn small square so we can see the square completely
See ol.View in the openlayers 3 documentation. There is a function setZoom(zoom)
.
So if your map variable is map
, to zoom in use map.getView().setZoom(map.getView().getZoom() + 1);
and to zoom out use map.getView().setZoom(map.getView().getZoom() - 1);
If you want a smooth zoom:
map.getView().animate({
zoom: map.getView().getZoom() + 1,
duration: 250
})
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.