[OpenLayers-Users] Wipe out Map for different projection

Heiko Schröter schroete at iup.physik.uni-bremen.de
Fri Oct 9 06:31:16 EDT 2009


> why don't you just configure your WMS base layer in both projections
> (instead of configuring the map with a projection)? When you switch the
> base layer, the map will automatically change its projection. Just make
> sure that you remove the google layers before you switch to EPSG:4326.

@Andreas
Thanks, this does it indeed. the only drawback i have now is when swicthing from EPSG4326 to EPSG900913 and vice versa the map is zoomed in as close as poss.
(with or without any added layers).

Is there a way to limit the zooming level when swicthing the projection ?
Limiting scales and ZoomLevels in the Layer definition doesn't help.

@Arnd
Very interesting. I tried it but failed to remove all but the last map.layer. This kept the map from beeing wiped out cleanly. So probably i'am using somehting which prevents this. Anyway i'd like to follow Andreas solution.

Thanks for your help and suggestions
Heiko

<snip>
    var myoptions = {
	maxResolution: 156543.0339,
	projection: new OpenLayers.Projection("EPSG:900913"),
	displayProjection: new OpenLayers.Projection("EPSG:4326"),
	units: "m",
	maxExtent: new OpenLayers.Bounds(xxmin,yymin,xxmax,yymax),
	restrictedExtent: new OpenLayers.Bounds(xxmin,yymin,xxmax,yymax),
	controls: [
		   new OpenLayers.Control.PanZoom(),
		   new OpenLayers.Control.Navigation(),
		   new OpenLayers.Control.MousePosition({"numDigits": 2}),
		   new OpenLayers.Control.LayerSwitcher()
		   ],
	
	numZoomLevels: 8
    };
    map = new OpenLayers.Map('map', myoptions);

    var epsg4326layer  = new OpenLayers.Layer.WMS( "EPSG:4326", 
                                               http_mapserver,
                                               {map: mapfile,
                                                layers: "KARTE,GRID,LOGO,COPYRIGHT",
                                                transparent: true },
                                               {singleTile:true, isBaseLayer: true,
                                                wrapDateLine: true,
						projection: new OpenLayers.Projection('EPSG:4326'),
						maxExtent: new OpenLayers.Bounds(xxxmin,yyymin,xxxmax,yyymax),
						restrictedExtent: new OpenLayers.Bounds(xxxmin,yyymin,xxxmax,yyymax),
						maxResolution: 'auto',
                                                queryable: true});
    make_base_layers.push(epsg4326layer);
    var epsg900913layer  = new OpenLayers.Layer.WMS( "EPSG:900913", 
                                               http_mapserver,
						{map: mapfile,
						 layers: "KARTE,GRID,LOGO,COPYRIGHT",
						 transparent: true },
						{singleTile:true, isBaseLayer: true,
						 projection: new OpenLayers.Projection('EPSG:900913'),
						 maxExtent: new OpenLayers.Bounds(xxmin,yymin,xxmax,yymax),
						 restrictedExtent: new OpenLayers.Bounds(xxmin,yymin,xxmax,yymax),
						 maxResolution: 156543.0339,
						 wrapDateLine: true,
						 queryable: true});
    make_base_layers.push(epsg900913layer);
    
    var ggphy = new OpenLayers.Layer.Google(
					    "Google Physical",
					    {type: G_PHYSICAL_MAP,
					     'sphericalMercator': true});
    var ggsat = new OpenLayers.Layer.Google(
					    "Google Satellite",
					    {type: G_SATELLITE_MAP,
					     'sphericalMercator': true});
    
    make_base_layers.push(epsg4326layer,epsg900913layer,ggphy,ggsat);
    map.addLayers(make_base_layers);
    map.setCenter(new OpenLayers.LonLat(0, 0), 3);
<snap>



More information about the Users mailing list