I'm trying to overlay a WMS layer over GoogleMaps base one. The WMS
layer is defined like this:
var catastro_layer = new OpenLayers.Layer.WMS(
"WMS Catastro",
http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?SERVICE=WMS&VERSION=1.1.1,
{
layers: "catastro",
format:"image/png",
srs: "EPSG:3785",
transparent: false
}
);
GoogleMaps layers are defined just like here
http://openlayers.org/blog/2010/07/10/google-maps-v3-for-openlayers/.
As result, my WMS layer appears as one base layer more. So, I can
select it instead of the other base layers, not over them. This
screenshots shows what I mean:
http://dl.dropbox.com/u/6599273/capa_wms1.png
The WMS requests are ok:
But this isn't what I need. I want a GoogleMaps base layer and a
transparent WMS overlay.
Now, if I change the WMS layer defintion replacing transparent: false
by transparent: true:
var catastro_layer = new OpenLayers.Layer.WMS(
"WMS Catastro",
http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?SERVICE=WMS&VERSION=1.1.1,
{
layers: "catastro",
format:"image/png",
srs: "EPSG:3785",
transparent: true
}
);
My WMS layer appears as a overlay:
http://dl.dropbox.com/u/6599273/capa_wms2.png, just what I want.
But now, the requests are incorrect:
As you can see, the epsg:3785 has been replaced by epsg:900913. But
the only change I've made is "transparent: false" by "transparent:
true". Why is this happening?
Many thanks in advance, and best regards
Best Answer
In OpenLayers, the base layer dictates what is going to be the "base spatial reference". So any overlay will be projected to the base srid. Since any base layer that comes from the consumer-based providers (google, bing, yahoo, etc) supports only 900913, then OpenLayers is doing the right thing for your.
If you do a GetCapabilities call on your server you will notice the following section:
Lo and behold, 900913 is not an option. You may need to either:
By looking at the URL, it seems you are using an ASP .NET WMS server, since Geoserver is java and Mapserver if cgi, and ArcGIS Server is .NET, I am going guess this is an ESRI server, so the instructions on how to modify this is here.
Update: As mkennedy points out, the official EPSG code for SphericalMercator (aka Google's projection) is 3857 and a previous assigned number was 3785. If you are wondering why there are so many numbers that refer to the same spatial reference, crschmidt's blog post will give you a clue...
Ian pointed out the relevant OpenLayer's documentation section to force OpenLayers to use that EPSG code instead.
Since your GetCapabilities section shows 3785, the code from the OL documentation won't work as is, you will need to replace all the 3857 for 3785.