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 have the following code on my html file:

        // World Geodetic System 1984 projection
    var WGS84 = new OpenLayers.Projection("EPSG:4326");

    // WGS84 Google Mercator projection
    var WGS84_google_mercator = new OpenLayers.Projection("EPSG:900913");       


    // create a map panel with some layers that we will show in our layer tree
    // below.
    layers = [];

    layers.push(new OpenLayers.Layer.Google("Google Maps", {
        numZoomLevels: 20
                    , 'sphericalMercator' : true
            }
    ));

    layers.push(new OpenLayers.Layer.WMS(
    "National Parks", "http://localhost:8080/geoserver/wms", {
        srs: 'EPSG:4326',
        layers: 'National_Parks',
        format: 'image/png',
        buffer:0
    }, {
        'isBaseLayer': false
    }
    ));

    map = new OpenLayers.Map({
        allOverlays: false  // If it is true then both the wms and the map layers will be included under the "Overlays" folder

    });

    mapPanel = new GeoExt.MapPanel({
        region: "center",
        center: new OpenLayers.Bounds(-16.08,49.06,6.76,58.74).transform(WGS84, map.getProjectionObject()),
        zoom: 2,
        map: map
    });

    map.addLayers(layers);

As the code is at the moment i can see the googlemaps layer at full extent (although i wanted it zoomed in at these boundaries -16.08,49.06,6.76,58.74) but i can not see the national parks wms layer.

What i did was to add 'displayOutsideMaxExtent':true next to 'isBaseLayer': false on the wms properties. When i did that i could see tha wms layer on all zoom levels but i couldnt see googlemaps at all. when i was zooming in and out the googlemaps layer was appearing instantly and then it was going off.

Does anyone have any idea where the problem might be?

I am using Geoserver, Openlayers, GeoExt and ext.

Thanks

Image 1 - White background

Image 2 - Google Background

share|improve this question
add comment

3 Answers 3

For safety you should explicitly set the map projection, otherwise the projection of the first layer is used and it's not clear which of those layers will end up first.

Your code is also assuming that the WMS server can reproject for you - it probably can but that could also be the problem. Check what it is returning using firebug (this will also allow you to check what SRS is being sent as OpenLayers will ignore the SRS you set in the WMS layer.

share|improve this answer
    
Hello Iant. Thanks for the reply. I have added this on my code: map = new OpenLayers.Map({ allOverlays: false, projection: new OpenLayers.Projection("EPSG:900913"), displayProjection: new OpenLayers.Projection("EPSG:4326"), units: "m", numZoomLevels: 18 But still i am getting the same problem. How can i see from firebug what SRS is being sent? –  Geo Sep 13 '11 at 15:11
    
look at the url - one of the parameters will be SRS=EPSG:xxxxx where xxxx is a number. In your case it should be 900913 not 4326 –  iant Sep 14 '11 at 7:54
    
It does say 900913. I dont think it has something to do with my projections, as i tried every combination .. but still with no luck .... i suspect it is the coding for ext and geoext that i am using. I had problems before when i got the ext coding from the tree.js file. –  Geo Sep 14 '11 at 13:34
    
and does the server return a map with that url? –  iant Sep 14 '11 at 16:00
    
Well that's the thing.... It returns a white background .. but when i zoom in u can instantly see the background mapping and then it becomes white again. I have attached 2 images to see what i get from firebug... when i first load the html file (image 1) and after i zoom in (image 2) –  Geo Sep 14 '11 at 16:54
show 2 more comments

Is a projection issue.

You have in the layer properties 2 parameters, projection and displayProjection, projection is for the projection of the source, displayProjection is for reproject to "that" projection, now OpenLayers could reproject only vector Layers, because OpenLayers render it, but OpenLayers cannot reproject a image layer.

So you have to reproject in the geoserver side. If you have reproject function in geoserver side you just need to pass to the map projection parameter the spherical mercator projection, because google will not reproject (is little ovbious).

OpenLayers docs about reprojection and tips to use Spherical mercator.

http://docs.openlayers.org/library/spherical_mercator.html

http://trac.osgeo.org/openlayers/wiki/SphericalMercator

share|improve this answer
add comment

Set transparent : True.

layers.push(new OpenLayers.Layer.WMS(
        "National Parks", "http://localhost:8080/geoserver/wms", {
            srs: 'EPSG:4326',
            layers: 'National_Parks',
            format: 'image/png',
            transparent: true,
            buffer:0
        }, {
            'isBaseLayer': false
        }
        ));
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.