Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?SERVICE=WMS&VERSION=1.1.1&LAYERS=catastro&FORMAT=image%2Fpng&SRS=EPSG%3A3785&TRANSPARENT=false&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&BBOX=-1721973.3737,3228700.0733875,-1702405.4944625,3248267.952625&WIDTH=256&HEIGHT=256

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:

http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?SERVICE=WMS&VERSION=1.1.1&LAYERS=catastro&FORMAT=image%2Fpng&SRS=EPSG%3A900913&TRANSPARENT=true&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&BBOX=-1721973.3737,3228700.0733875,-1702405.4944625,3248267.952625&WIDTH=256&HEIGHT=256

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

share|improve this question
add comment

4 Answers 4

up vote 4 down vote accepted

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:

<Layer queryable="1" opaque="0" noSubsets="0">
<Name>Catastro</Name>
<Title>Catastro</Title>
<Style>
<Name>Default</Name>
<Title>Default</Title>
<LegendURL width="160" height="500">
<Format>image/png</Format>
<OnlineResource xlink:type="simple" xlink:href="http://ovc.catastro.meh.es/Cartografia/WMS/simbolos.png"/>
</LegendURL>
</Style>
<BoundingBox SRS="EPSG:4230" minx="-18.409876" miny="26.275447" maxx="5.22598" maxy="44.85536"/>
<BoundingBox SRS="EPSG:4326" minx="-18.409876" miny="26.275447" maxx="5.22598" maxy="44.85536"/>
<BoundingBox SRS="EPSG:4258" minx="-18.409876" miny="26.275447" maxx="5.22598" maxy="44.85536"/>
<BoundingBox SRS="EPSG:32627" minx="770000" miny="3000000" maxx="2700000" maxy="5000000"/>
<BoundingBox SRS="EPSG:32628" minx="180000" miny="3000000" maxx="2170000" maxy="5000000"/>
<BoundingBox SRS="EPSG:23029" minx="-410000" miny="3000000" maxx="1650000" maxy="5000000"/>
<BoundingBox SRS="EPSG:23030" minx="-1050000" miny="3000000" maxx="1150000" maxy="5000000"/>
<BoundingBox SRS="EPSG:23031" minx="-1615000" miny="3000000" maxx="620000" maxy="5000000"/>
<BoundingBox SRS="EPSG:32629" minx="-410000" miny="3000000" maxx="1650000" maxy="5000000"/>
<BoundingBox SRS="EPSG:32630" minx="-1050000" miny="3000000" maxx="1150000" maxy="5000000"/>
<BoundingBox SRS="EPSG:32631" minx="-1615000" miny="3000000" maxx="620000" maxy="5000000"/>
<BoundingBox SRS="EPSG:25829" minx="-410000" miny="3000000" maxx="1650000" maxy="5000000"/>
<BoundingBox SRS="EPSG:25830" minx="-1050000" miny="3000000" maxx="1150000" maxy="5000000"/>
<BoundingBox SRS="EPSG:25831" minx="-1615000" miny="3000000" maxx="620000" maxy="5000000"/>
<BoundingBox SRS="EPSG:3785" minx="-2100000" miny="3000000" maxx="500000" maxy="5600000"/>
</Layer>

Lo and behold, 900913 is not an option. You may need to either:

  • modify the WMS server definition to make sure that 900913 is allowed as a valid reprojection
  • add a definition for that new srid (depends on what web server you are using)
  • a combination of thse

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.

share|improve this answer
    
Upvoted, since this one had more information, but the key component is in the update; you need to do what the OL docs say. –  Christopher Schmidt Jun 11 '11 at 19:18
    
Many thanks! That solved my problem. –  jorgeas80 Jun 13 '11 at 13:30
add comment

That request is correct - Google uses a spherical mercator projection (epsg:900913) so if you request your WMS layer in 3785 it won't line up with your Google base map. If your server is unable to reproject the data (as appears to be the case) you can set up a cascading WMS (both GeoServer and MapServer can do this) to fetch the WMS layer in 3785 and reproject it to 900913 for you.

share|improve this answer
1  
Side note: mathematically, 3785 = 900913 = 3857 –  mkennedy Jun 11 '11 at 17:54
3  
OK missed that - see docs.openlayers.org/library/… for the work around –  iant Jun 11 '11 at 18:01
add comment

if a layer is not a base layer then you need to add

'isBaseLayer': false

in its definition

share|improve this answer
add comment

I have the same problem, I want to overlay WMS layer in geoserver layer and google does not work.

My WMS layer in geoserver is redesigned to 900913 to work with google maps api

My WMS layer

My code:

    <!DOCTYPE html>
<html lang='en'>
<head>
 <meta charset='utf-8' />
 <title>My OpenLayers Map</title>
 <script type='text/javascript' src='OpenLayers.js'></script>

 <!-- Chamada a Api Google Maps especificando a versão 3.2 -->
 <script src="http://maps.google.com/maps/api/js?sensor=false&v=3.2">
 </script>

 <script type='text/javascript'>

 var map;
 var mercatorProjection = new OpenLayers.Projection('EPSG:900913');
 var latLongProjection = new OpenLayers.Projection('EPSG:4326');

 function init() {

 map = new OpenLayers.Map('map_element',{
    projection: mercatorProjection,
    displayProjection: latLongProjection
 });

 var google_streets = new OpenLayers.Layer.Google(
    "Sreets",
    {numZoomLevels: 20}
    );

 var wms_layer = new OpenLayers.Layer.WMS(
    'Acidentes',
    'http://localhost:8080/geoserver/Teste/wms?',
    {layer:'acidentes', transparent: true},
    {isBaseLayer:false},
    {opacity: 0.5}
    );

map.addLayers([google_streets],[wms_layer]);

var point = new OpenLayers.LonLat(-51.01,-30.01); 
point.transform(new OpenLayers.Projection("EPSG:4326"), 
    map.getProjectionObject()); 
map.setCenter(point, 8);    

 map.addControl(new OpenLayers.Control.LayerSwitcher());

 if(!map.getCenter()){
     map.zoomToMaxExtent();
     }
 }

 </script>
</head>

<body onload='init();'> <!-- Chama a função js init() --> 

<!--Elemento HTML onde o mapa é exibido -->
 <div id='map_element' style='width: 800px; height: 800px;'>
 </div>

</body>
</html>

The result page, not overlay. The base layer only appears.

Page

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.