[OpenLayers-Users] Switch of Projection (sphericalMercator)

Tim Schaub tschaub at openplans.org
Thu Jan 31 12:32:19 EST 2008


Hey DiscoBoy-

Can you restate your problem?

If you construct a map with several base layers (some Google/SM and some 
WMS) and several overlays (all WMS), when you switch base layers, your 
WMS overlays should get requested in the map projection - which is the 
projection of the base layer.

So, what you're trying to do should happen transparently (without the 
need for custom code).  Could be, of course, that I just didn't read 
your issue correctly.

One thing that just occurred to me - you could be following the 
spherical-mercator.html example and setting projection related options 
on the map.  In your case, don't do this.  You want to set those same 
options on the individual layers.  Then the map will figure out its 
projection related properties from the current base layer.

Tim

DiscoBoy wrote:
> Hi!
> 
> My final hope lies in you as I have been struggling around since 2 days now
> with OL. I try to use several baseLayers in my Map, that have different
> projections(GoogleMaps/WMS). Additionally I want to overlay these baseLayers
> with external data (e.g. WMS layer/Vetor).
> 
> To achieve a fitting WMS overlay with GoogleMaps I have to use
> sphericalMercator projection (= EPSG:900913). Now I also want to have
> baseLayers without spericalMercator (--> EPSG:4326) and easily switch
> between these baseLayers. Therefor I listen for the
> event(map.changebaselayer) and then call a function
> "resetMapProjection(thenewlayer)".
> 
> The function already notifies me if the new baseLayer
> (thenewlayer.sphericalMercator) is true or not, so I can distinguish if the
> baseLayer I'm switching too needs to have (EPSG:4326) or (EPSG:900913)
> settings.
> 
> 				function resetMapProjection(thenewlayer) {
> 					if(map.getLayer(thenewlayer.sphericalMercator == true) {
> 						map.setOptions({
> 							projection: "EPSG:900913",
> 							displayProjection: "EPSG:4326",
> 							units: "m",
> 							maxResolution: 156543.0339,
> 							maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508,
> 20037508.34)
> 						});
> 					}
> 					else {
> 						map.setOptions({
> 							projection: "EPSG:4326",
> 							displayProjection: "EPSG:4326",
> 							units: "dd",
> 						});
> 					}
> 					map.getLayer(thenewlayer).redraw();
> 				}
> 
> Unfortunately the newly drawn map simply does not use the new map settings!
> After the layer-switch I end up having a new map which has been set to
> meters or degrees (or so on), but I can't make the new baseLayer to be
> rendered using these new settings (Also "redraw()" does not work).
> ggggggrrrrrr....I feel and the end of my wisdom :-(
> 
> And appreciate any hints!
> Thank you!




More information about the Users mailing list