1

I'm using openlayers with OSM as a map source. I would like to change map settings co I cannot zoom more than map size.

enter image description here

This is a situation now. I do not want to see the white space. I do not want map to wrap X (I already did that with wrapX : false in OSM constructor). But how can I set up the map to see it just once? I tried to set min zoom to some value But I could still see the white space.

This is my init function

    this._source = new OSM({
        cacheSize: 10000,
        wrapX : false
    });

    this._layer = new OlTileLayer({
        source: this._source
    });

    this._view = new OlView({
        center: [-7916041.528716288, 5228379.045749711],
        zoom: 4,
        minZoom: 2
    });

    this.map = new OlMap({
        target: 'map',
        layers: [this._layer],
        view: this._view,
        controls: [
            new OlControlZoom(),
            new OlControlZoomSlider()
        ]
    });

Can anyone help me?

4
  • As far as I know, there's no way to restrict the area. but you can manually set extent on View with minZoom. then though there'll be white space displaying which are out boundary of the map, the map will not allow you to move out of extent
    – Chase Choi
    Commented Mar 13, 2018 at 0:37
  • @Chase Choi And can you tell me hod to do it?
    – Johnczek
    Commented Mar 14, 2018 at 18:05
  • check the coordinates(boundary) you want to restrict and add it into OlView
    – Chase Choi
    Commented Mar 15, 2018 at 1:13
  • I tried to get the OSM coordinates and give them somehow to extent of view but that doesnt work. Can you please show me how to do it?
    – Johnczek
    Commented Mar 18, 2018 at 15:01

1 Answer 1

1

As I comment on the question, you can use extent which limits center coordinates to move within the range.
You figure out which is the exact coordinates of map images(e.g. for OSM, it's [-20027724.40316874, -20027724.40316874, 20027724.403168738, 20032616.372978993]), then set this as a extent then the map center doesn't go outside of the map.
This is you can do for now though you may see half area of white space when you reach its boundary.

Another way is, if you support few levels, setting extent as a little inside points from boundary so it can display map images instead white. but extent is based on coordinates and doesn't care about visual things so when you zoom-in/out, you will loose boundary images if you set too deep inside coordidnates from boundary, you will see white space if you set too shallow insdie coordinates from boundary.

https://codepen.io/anon/pen/eMBeMM is example for zoom:2, width:500px, height: 600px with OSM

view: new ol.View({
  center: [0, 0],
  zoom: 2,
  minZoom: 2,
  extent: [-7435794.111581946, -8766409.899970295, 8688138.383006273, 9314310.518718438]
})

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.