1

I can drag the map out of window.

See this example. Can I disable these borders not allowing drag the map out of window?

enter image description here

2
  1. First of all you are using a very old version of OL3. 3.0.0 while currenlty version 3.11.2 is running.
  2. The solution @Zoltan suggests will prevent your map to move the map center outside the supplied extent. I am not sure whether this is going to help you.
  3. A combination of @zoltan suggestion + a maxZoom parameter maybe will solve your case.
  4. The example you provide is wrapping the tiles horizontally. As a result your map width is too big compared to the height. For the specific layer you use new ol.source.MapQuest there is no option to disable it. But for other tile layers like OSM you have the option to disable x wrapping. like so

     new ol.layer.Tile({
      source: new ol.source.OSM({
        wrapX: false
      })
    })
    

now using this case and a maxZoom will solve your problem.

  1. If none of the above feets your case, cosider to style the div you use to place your map and give a lowest heigh so that it feets with the map.

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.