3

When I load the map without any extent in my view, then the HTML page opens properly, without bounds



      var myview = new ol.View({
            projection: 'EPSG:4326',
            center: [77, 24],
            zoom: 4.5, 
            maxZoom: 8,
            minZoom: 3,
            smoothResolutionConstraint:true,
            //extent: [60, 6, 100, 40],
      });

but once I set the bounds in my view, it doesn't follow the given zoom level and opens differently with bounds

      var myview = new ol.View({
            projection: 'EPSG:4326',
            center: [77, 24],
            zoom: 4.5, 
            maxZoom: 8,
            minZoom: 3,
            smoothResolutionConstraint:true,
            extent: [60, 6, 100, 40],
      });

How should I change the JS so that, it opens at the given zoom level when I give the bound extents.

1
  • By default the extent setting means neither the width or height of the extent can be exceeded. Include showFullExtent: true, in the options to change that so one but not both can be exceeded.
    – Mike
    Dec 31 '20 at 10:33
4

If you look at the specification of the view extent option, it says:

The extent that constrains the view, in other words, nothing outside of this extent can be visible on the map.

In your case that means that nothing to the left of 60° and right of 100° longitude should be visible in the map view. Since at zoom 3 more would be visible, higher zoom is used to comply with the extent restriction.

If you want to limit viewable extent of a specific layer, use extent option when defining that layer.

1
  • Yeah, you are right, & I exactly want to keep the things within the bound that i have mentioned in the code [60, 6, 100, 40], nothing left of 60° and nothing right of 100°, similarly nothing above 40° and nothing below 6°. I think the code is right, the issue is with the map-view of HTML web-page. Dec 31 '20 at 14:35

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.