Zoom in/out on click in OpenLayers 3?

How to zoom in map in OpenLayerss 3 on click of button?

I want to zoom in and zoom out the map on custom buttons instead of + and - buttons which are on default map.

I tried with:


But it's not working, though it was working in OpenLayers 2.

If you want to zoom in if you click on the map the following should work:

map.on('click', function() { map.getView().setZoom(map.getView().getZoom()+1); });

If you want a smooth zoom:

map.getView().animate({ zoom: map.getView().getZoom() + 1, duration: 250 })

Watch the video: Web Map Service WMS With QGIS (October 2021).