1

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

3
  • 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. Commented May 5, 2013 at 7:20
  • the projection of my layer is configured in geoserver settings , it'4362 WGS85 Commented May 5, 2013 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. Commented Dec 9, 2013 at 14:13

1 Answer 1

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);

        }
3
  • 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 ? Commented May 5, 2013 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. Commented May 5, 2013 at 18:25
  • £mmm ok professor ; i will continue my search ; thanks a lot Commented May 5, 2013 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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