OpenLayers – How to Show Overlay with Different SRS than Base Layer in OpenLayers

coordinate systemopenlayers-2overlay

I need to add an overlay layer that uses EPSG:4326 to a map with a base layer that uses EPSG:32628.

Every time I add the overlay OpenLayers automatically switches the SRS param of the overlay to EPSG:32628 (SRS of baselayer); I can see the base layer, but the overlay isn't shown.

My code is this:

baselayer = new OpenLayers.Layer.WMS(
               baselayername, baselayerurl,
               {
                  width: varmap.size.w,
                  srs: 'EPSG:32628',
                  layers: baselayername,
                  height: varmap.size.h,
                  styles: style,
                  format: format
               }
               );

overlaylayer = new OpenLayers.Layer.WMS(
               overlaylayer name, overlaylayer url,
               {
                  width: varmap.size.w,
                  srs: 'EPSG:4326',
                  layers: layername,
                  height: varmap.size.h,
                  styles: style,
                  format: format,
                  transparent: true
               }
               );

varmap.addLayers([baselayer,overlaylayer]);

How can I do this?

Best Answer

That is how it is supposed to work. OpenLayers can't reproject WMS layers for you so you should let the WMS server take care of that for you.

If your WMS can not support EPSG:32628 then you will need to look into setting up a cascading WMS that can reproject it for you (both MapServer and GeoServer 2.1+ can do this).

Related Question