1

In Openlayers 3 I've been unable to get my attempts at overriding the ol.interation.PinchZoom's handleUpEvent to work. I've tried a few different ways, but but below is a basic example of what I've tried.

This is an attempt to replace the standard PinchZoom's handleUpEvent with a custom one, and set this as the only interaction for the map. However, the event function is never called (never logs anything).

function handleUpEvent(evt) {
    console.log("Up event handler");
    return true; //  Stop drag
}

map = new ol.Map({
    layers: [],
    target: 'map',
    controls: controls,
    interactions: [new ol.interaction.PinchZoom({handleEvent: handleUpEvent})],
    view: new ol.View({projection: projCode})
});
0

Having posted a similar question on Stack Overflow, I eventually received an answer there. It seems that PinchZoom does not provide an option for overriding the handleUpEvent. I had incorrectly assumed that it inherited this option from its Pointer parent class.

It was recommended to me that I would need to use a custom build of Openlayers with modified source code. Hopefully this may be included in a future version of Openlayers itself. An example of the modified Openlayers is available there for anybody that's interested:

https://stackoverflow.com/questions/40882212/openlayers3-fractional-zoom-on-touch-device-using-pinch-gesture

In my case, I was wanting to use fractional zoom and avoid the final zoom-to-nearest-native-resolution that happens at the end of a PinchZoom. The example custom build does not provide the option to override handleUpEvent as such, but rather provides an option to use fractional zoom, and if this option is enabled, the modified built-in handleUpEvent will skip the final animated zoom-to-nearest-native-resolution.

UPDATE: OpenLayers 3.20 includes the PinchZoom behaviour I want by default now. The old behaviour is now only available by specifying the constrainResolution option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.