[OpenLayers-Dev] Switching between base layers with different projection?

Julien-Samuel Lacroix jlacroix at mapgears.com
Wed Jun 4 10:51:47 EDT 2008


We've successfully changed the baseLayer of our application by changing 
only the projection, maxExtent, units and maxResolution of the layer we 
want as the new baseLayer.

if(myLayer.name == 'Normal projection')
     myLayer.projection = new OpenLayers.Projection('EPSG:4326');
     myLayer.maxExtent = new OpenLayers.Bounds(-165, 15, -50, 75);
     myLayer.units = 'degrees';
     myLayer.maxResolution = 1.40625;
else if(myLayer.name == 'SphericalMercator projection')
     myLayer.projection = new OpenLayers.Projection('EPSG:900913');
     myLayer.maxExtent = new OpenLayers.Bounds(-20037508.34, 
-20037508.34, 20037508.34, 20037508.34);
     myLayer.units = 'm';
     myLayer.maxResolution = 156543.0339;
// Then zoom to SphericalMercator bounds

Note that we had a bunch of custom Controls that we needed to be updated 
to check the projection before zooming somewhere. But other than that it 
was pretty straight forward.


Roald de Wit wrote:
> Hi list,
> For a client I'd like to provide a map with base layers in different
> projections (and with overlays) that switches nicely between base
> layers, recalculating the overlays.
> crschmidt just told me on IRC [1][2] that it is probably not possible
> with the current code in the trunk, since when switching base layers,
> the map tries to keep the 'same' maxextent.
> Edgemaster, apparently you've got it working in a sandbox. If so, could
> you please tell a little bit more about it and point to a working
> example? This might be a nice addition for trunk?
> Thanks,
> Roald
> [1] http://crschmidt.net/irc/openlayers/log.cgi/2008-06-02#T23-46-35
> [2] http://crschmidt.net/irc/openlayers/log.cgi/2008-06-03#T00-23-04

Julien-Samuel Lacroix

More information about the Dev mailing list