0

I'm using the following to initialize my view for the map in openlayers 4.

var olview = new ol.View({
    center: ol.proj.fromLonLat(coords),
    resolution: resolution,
    minResolution: 0.025,
    maxResolution: 2500,
    projection: 'EPSG:3857'
});

The coords and resolution are passed as arguments to the function that creates the view. When zooming with the mouse the center of the map goes to [NaN, NaN]. Using the or the plus/minus buttons or animate function on the view works as expected, and after animating the view the zoom functionality works as expected.

0

The cause was that the resolution was being passed as a string. Openlayers doesn't check types or convert them, so passing types that aren't the expected type in the documentation can cause things to break (here's an issue discussing it). Setting resolution to parseFloat(resolution) fixed the problem.

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.