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

Semantica jvanulde at nrcan.gc.ca
Wed Aug 27 14:17:20 EDT 2008


Hi Chris,

Thanks for that.  I am unclear on why I would need to change the resolution. 
I am simply loading a WMC that I have created using format.write(map).  Now
it seems to me that since I am loading it into exactly the same viewport it
should load to the WMC extent, however it always (without exception) loads
it with an extent that is equivalent to one level of zoom out.  Any ideas on
why this is occuring?  I noticed that the WMC demo doesn't seem to have this
issue so I am wondering if it has something to do with the fact that I am
loading all layers as overlays with a fake baselayer that doesn't have an
extent set.  

Any suggestions would be appreciated!



Chris Adams wrote:
> 
> 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!
>>
>>
>>   
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Map-won%27t-zoom-to-full-extent-tp741546p787735.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list