TDesjardins / gwt-ol

GWT wrapper for OpenLayers 3+ using JSInterop
Apache License 2.0
70 stars 33 forks source link

constrainResolution does not work #193

Closed edigonzales closed 7 months ago

edigonzales commented 7 months ago

I'm trying to prevent having intermediate zoom levels when zooming with the mousewheel:

DefaultInteractionsOptions interactionOptions = new ol.interaction.DefaultInteractionsOptions();
interactionOptions.setConstrainResolution(true);
interactionOptions.setDoubleClickZoom(false);
mapOptions.setInteractions(Interaction.defaults(interactionOptions));

olMap = new ol.Map(mapOptions);

It seems that this does not work. It is still possible to zoom with the mousewheel to any desired intermediate zoom level.

Tried also this, which does not work:

MouseWheelZoom mwz = new MouseWheelZoom();
mwz.set("constrainResolution", true);
olMap = new ol.Map(mapOptions);
olMap.addInteraction(mwz);
TDesjardins commented 7 months ago

Hi, I will have a look into this. Which Open Layers version are you using?

edigonzales commented 7 months ago

v6.6.1

Thanks.

TDesjardins commented 7 months ago

Yep, I can confirm this. Your first code snippet doesn't work because there is no such option in default interaction options: https://openlayers.org/en/v6.6.1/apidoc/module-ol_interaction.html#~DefaultsOptions I suppose this is a copy and paste bug in gwt-ol. The param has to be removed.

Second code doesn't work because the param is needed on object instantiation. So there is a need to introduce a constructor with options for mousewheel. I tested it and it works.

I am going to create a fix.

TDesjardins commented 7 months ago

@edigonzales I committed a fix. Could you check if this works for you?