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 a html page with 2 WMS layers. The first is one Base Layer , & the second is my personal WMS feature. I load it from Geoserver. The problem when I add the 2 layers I do not have the superposition

The problem is maybe on the projection. please can you help me this is my code

<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
  var map;
        OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
        var host = "http://'my_host':8080/geoserver/wms";

        function init() {

            map = new OpenLayers.Map('map', {
                    controls: [
                        new OpenLayers.Control.Navigation(),
                        new OpenLayers.Control.PanZoomBar(),
                        new OpenLayers.Control.LayerSwitcher({'ascending':false}),
                        new OpenLayers.Control.ScaleLine(),                    
                        new OpenLayers.Control.MousePosition()]});

            var reg = new OpenLayers.Layer.WMS(
                "Région",
                host,
                {layers: 'cite:matregion_view', format: 'image/gif',transparent: true}
            );


               var gmap = new OpenLayers.Layer.Google(
                "Google Streets", // the default
                {numZoomLevels: 20}
            );   

 map.addLayers([gmap , reg]);
//map.setCenter(new OpenLayers.LonLat(146.7, -41.8), 6);
        map.zoomToExtent(new OpenLayers.Bounds(-16.884,20.748,-1.026,35.924));

        }

Image

share|improve this question
    
What is the projection of your custom layer? I do not see you setting the projection for your map in Web Mercator. That could potentially solve the problem. –  Devdatta Tengshe May 5 '13 at 7:20
    
the projection of my layer is configured in geoserver settings , it'4362 WGS85 –  Yahia El Haddad May 5 '13 at 9:59
    
This question appears to be off-topic because it is an old question, and the OP has not come back to it. –  Devdatta Tengshe Dec 9 '13 at 14:13

1 Answer 1

To overlay the custom WMS layer correctly, I would first set the projection of the map, by passing in the projection parameter, and then at the end I would set the bounds in this projection.

My code would be as follows:

function init() {

var webMercator=new OpenLayers.Projection("EPSG:3857");
var wgs84=new OpenLayers.Projection("EPSG:4326");

var options = {
    projection:webMercator ,
    units: "m",
    maxResolution: 156543.0339,
    maxExtent:max_Extent ,
    controls: [new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.PanZoomBar(),
        new OpenLayers.Control.LayerSwitcher({'ascending':false}),
        new OpenLayers.Control.ScaleLine(),                    
        new OpenLayers.Control.MousePosition()]    
    };

map = new OpenLayers.Map('map', options );

var reg = new OpenLayers.Layer.WMS(
    "Région", host,
    {layers: 'cite:matregion_view', format: 'image/gif',transparent: true},
    {isBaseLayer:false}
);


var gmap = new OpenLayers.Layer.Google(
    "Google Streets", // the default
    {numZoomLevels: 20}
);   

map.addLayers([gmap , reg]);
var initialBounds=(new OpenLayers.Bounds(-16.884,20.748,-1.026,35.924)).transform(wgs84, webMercator);

map.zoomToExtent(initialBounds);

        }
share|improve this answer
    
thank you for your response ; I tested your code, but it does not work ... i think that i should define a projection in reg layer ; no ? –  Yahia El Haddad May 5 '13 at 18:09
    
I think that the problem might be in the reg layer. If the projection and position of the reg layer was correct it should appear in the correct location using the code I have posted. –  Devdatta Tengshe May 5 '13 at 18:25
    
£mmm ok professor ; i will continue my search ; thanks a lot –  Yahia El Haddad May 5 '13 at 23:47

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.