0

If I run the following code in OpenLayers 3...

console.log(map.getView().calculateExtent(map.getSize()));
map.getView().fit(map.getView().calculateExtent(map.getSize()), map.getSize());
console.log(map.getView().calculateExtent(map.getSize()));

I get the following output logged...

453350.0260566147,5335322.150098615,551079.8960333853,5508792.669307384
404485.0910682294,5248586.890494232,599944.8310217706,5595527.928911767

In my project, I would like to be able to store the current extent, so that I can reuse it later and go back to exactly the same extent. But it doesn't work as I expect it to.

It appears to be zooming out an entire zoom level.

Why is it behaving this way, and how can it get it to go back to the same extent that I had before?

1 Answer 1

1

Pass in options to the fit function, specifically constrainResolution false

3
  • I’ll give this a try when I get the chance. The documentation on this option merely says “constrain the resolution”. What does this option actually do? Could you please provide some more explanation in your answer. Commented Jul 31, 2018 at 1:23
  • It will match to one of the resolutions of the view, which will mean that your extent will not exactly match the given extent
    – bartvde
    Commented Jul 31, 2018 at 6:30
  • This is now working correctly for me. Thank you. What's embarrassing is that I should have thought of this. The 'constrainResolution' option was introduced for the 'PinchZoom' handler explicitly in response to my first OL question on this site (and on Stack Overflow)! See: gis.stackexchange.com/questions/220354/… Commented Jul 31, 2018 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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