简体   繁体   中英

OpenLayers minimal zoom smaller than bounding box

I've got a problem with osm and openlayers. first of all, my map object

var wgs84 = new OpenLayers.Projection("EPSG:4326");
var map = new OpenLayers.Map ('map',
    {
    projection: new OpenLayers.Projection("EPSG:900913"),
    displayProjection: wgs84,
    maxExtent: new OpenLayers.Bounds(-180,-20, 180, 90),
    controls: [
    new OpenLayers.Control.MousePosition(),
    new OpenLayers.Control.PanZoomBar(),
    ]
    }); 

as you can see, my bounding box ends at -20, so the antarctis should be displayed.

but i'm able to zoom out so that i can see the whole world, and the map is smaller than the map-div (which is 900 * 500).

Is there any solution to fix it? you shouldn't be able to get a smaller map than the bounding box allows.

Have you implemented the restrictedExtent parameter?

(from the documentation) restrictedExtent

{OpenLayers.Bounds} Limit map navigation to this extent where possible. If a non-null restrictedExtent is set, panning will be restricted to the given bounds. In addition, zooming to a resolution that displays more than the restricted extent will center the map on the restricted extent.

See an example here - This stops you panning beyond the bounds but does not restict the zoom levels. This seems to be a heavily reported missing feature that has not had many resolutions.

I believe this SO post has some workarounds for it though Min Max Zoom level in OpenLayers

Hope I have been some help.

Take a look at the sample I did at http://beta1234.com.sunflower.arvixe.com/maps/ (the server is a bit slow). It uses restrictedExtent and restricted zoom levels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM