[OpenLayers-Users] Two base layers with different projections

jorgelopez jorgelopez.physics at gmail.com
Tue May 8 11:21:10 EDT 2012


Hello everyone: 

I am struggling with my faces around projections, extents and base layers. I
am diving into a project that publish 
geospatial informations from different WMS sources. At the beginning, I am
doing several simple taskss 
with a proper map server. 

The main difficult part is related to two base layers with different
projections: one layer from a simple WMS server 
in EPSG:4326, and another from third party API, Google, in EPSG:900913. Onto
these base layers I am serving layers 
REPROJECTING those accordingly, asthey are called from OpenLayers in both
cases. 

I isolated these map-layer projections, (re-)projecting layers WITH ONE BASE
LAYER. In one case, with 4326 and in
another case, with 900913.

But the problem turns out when I bring all together. I would like to control
with a variable when one base layer is 
selected from layerswitcher control. But i did not succeed it.  

My Problems: 

When I change base layers in control, the overlay layers are not properly
projected 

When I switch base layers in control, I lost the visibility of other base
layer 

My code: 

var map;
var options_google, options_NO_google; 
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
		
function init() {
map = new OpenLayers.Map('map', {
eventListeners: {
	'changebaselayer' : function(event){
						if (event.layer.id === 'OpenLayers.Layer.WMS_47') {
							//alert('Enhorabuena');
							this.setOptions({
								projection: new OpenLayers.Projection("EPSG:4326")
								//maxExtent: 
								}); 
												alert(map.projection); 
								} else {
								//alert('malnacido'); 
							this.setOptions({
								projection: new OpenLayers.Projection("EPSG:900913"),
								            units: "m",
									//numZoomLevels: 18,
									//maxResolution: 156543.0339,
									//maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
									//								 20037508, 20037508.34)
									});  
									alert(map.projection); 
									}	
					}
				}
				});			   



var control_layers = new OpenLayers.Control.LayerSwitcher({});
map.addControl(control_layers); 


// BASE LAYER 1
var layer_base = new OpenLayers.Layer.WMS("Capa base WMS",
								"http://vmap0.tiles.osgeo.org/wms/vmap0", 
								{layers: "basic"},
								{isBaseLayer: true}
								//, {opacity: 0.8}
				); 


// BASE LAYER 2
var layer_google_base = new OpenLayers.Layer.Google(
							"Google Satellite",
							{type: google.maps.MapTypeId.TERRAIN
							, numZoomLevels: 22
							}
						);


// OVERLAY LAYER
var layer_wms_mapserver1 = new OpenLayers.Layer.WMS("Capa overlay mapserver
1",
							"http://XXXXXXXXXX/cgi-bin/mapserv?", {
							layers: "NUTS_BN_03M_2006"
								, transparent: true
									}, {
								isBaseLayer: false
								//, opacity: 0.5
								}
				); 


map.addLayers([layer_base,layer_google_base,layer_wms_mapserver1]);


I have no reason for that. Maybe two base layers with different projections
have no sense. 


Has Anyone any idea about this strange behaviour? Or another idea about how
this matter could be done in another way (code/idea)?  


Any help is appreciated 


Jorge


--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Two-base-layers-with-different-projections-tp4960707.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list