[OpenLayers-Users] Map won't zoom to full extent

Chris Adams chris at genieknows.com
Fri Aug 22 13:13:46 EDT 2008


This is because your resolutions do not allow for it.

If you want your the whole map to fit the visible extents, you will 
either need to adjust the size of your map so it fits, or adjust your 
highest resolution. Even adjusting your resolution, you may still need 
to change the width or height of your map, depending on the aspect 
ratio. (Unless of course you want to write a custom projection :) )

Semantica wrote:
> Hi all, 
>
> I submittted a related post earlier.  I am loading a web map context
> document into a map.  I am setting the map extent to context.bounds but no
> dice.  I have tried setting the map extent to format.context.bounds but got
> a null reference error.  Here is the relavant code:
>
>         function initMap() 
>         {     
>    
>             // parse wmc into context object            
>             var wmc = document.getElementById('hidWMC').value;
>             
>             if(wmc)
>             {
>             
>                 context = format.read(wmc, {map: map});
>                 
>                 for (var i=0; i<context.layers.length;i++) 
>                 { 
>                   var layer = context.layers[i]; 
>                   layer.params.TRANSPARENT = 'TRUE'; 
>                 }
>
>                 // construct a map
>                 var mapOptions = {
>                     maxExtent: context.bounds,
>                     projection: context.srs
>                     };
>                     
>                 map = new OpenLayers.Map("map", mapOptions);
>              
>                 // create a fake base layer
>                 var baseLayerOptions = {
>                     isBaseLayer: true, 
>                     displayInLayerSwitcher: false
>                     };
>                     
>                 var fake = new OpenLayers.Layer('fake', baseLayerOptions);
>                 map.addLayer(fake);            
>
>                 // add the context layers to the map
>                 map.addLayers(context.layers);                       
>
>                 // zoom to the maximum extent
>                 map.zoomToMaxExtent();  
>             }
>         }
>
> Here is a screenshot:  http://n2.nabble.com/file/n741546/screenshot.png
> screenshot.png 
>
> Any ideas on how I can get the map to zoom the the extent of the context
> document?
>
> Thank you in advance!
>
>
>   




More information about the Users mailing list