[GIS] How to turn off OpenLayers 4 smooth zooming

openlayerszoom

After upgrading from OpenLayers3 to OpenLayers4, the zooming has changed. Now the user can zoom to zoomlevels between integers. It does not look okay for some raster layers.

Good (same as source raster map):

source raster map

Little bit zoomed by OpenLayers (looks blurred):

enter image description here

How can I turn off this zoom option?

Best Answer

Check constrainResolution option on ol.interaction.PinchZoom http://openlayers.org/en/latest/apidoc/module-ol_interaction_PinchZoom.html

var map = new ol.Map({
    interactions: ol.interaction.defaults({}).extend([
        new ol.interaction.PinchZoom({
            constrainResolution: true
        })
    ]),
    .....
});

If you want to set for mouseWheelZoom, just change ol.interaction.PinchZoom to ol.interaction.MouseWheelZoom. plus, zoomDuration: 0 makes it no animation.

Related Question