1

Set extent to view:

var view = new ol.View({
            projection: 'EPSG:3857',
            center: center,
            zoom: 11,
            minZoom: 11,
            extent : [
                LeftPointX,
                LeftPointY,
                RightPointX,
                RightPointY
            ],
            maxZoom: 16
        });

When I zoom map on left corner areas and trying to drag map, the position when I focused is lost. Map goes to another coordinate. When I remove view.extent It works normaly.

Examples here:

  1. http://jsfiddle.net/umid/x4m4g1wg/2/
  • 1
    Its because of your extent. On lower zoom levels a outer margin around the extent is lost. So check your extent at boundingbox.klokantech.com (epsg:4326 i think) Maybe you should choose a bigger extent. – MichaelJS Jul 7 '15 at 12:48
  • 1
    The extent property only guarantees that the map centre does not fall outside the bounds. It does not constrain the edges directly. Like @MichaelJS said, you may want a larger extent. – nagytech Jul 7 '15 at 12:55
  • Is it possible to change extent dynamically when view is changed ? – Umid Abulkasimov Jul 7 '15 at 13:21
  • You could try to use the view.on('change:center') event and set the extent there - something like ol.View().set('extent',newextent) see openlayers.org/en/v3.6.0/apidoc/ol.View.html – MichaelJS Jul 7 '15 at 13:52
  • var extent = [4179159, 7499612, 4197368, 7542408]; view.on('change:center', function(evt){ var r = evt.target.getResolution(); map.getView().set('extent', [ extent[0] * r, extent[1] * r, extent[2] * r, extent[3] * r ]); }); Does not help – Umid Abulkasimov Jul 7 '15 at 14:30

Your Answer

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

Browse other questions tagged or ask your own question.