0

I use two base layers and user can switch from OSM MapQuest to Google from a drop down list. However my WFS layer is not in position (shift of about 5 degrees to the East) when the base layers is a Google Base Layer. Position is fine when the OSM layer is used.

I have read a few posts about related problems which were caused by wrong coordinate systems for the map (not using spherical Mercator for the map projection) but I tried to set it properly.

    geographic = new OpenLayers.Projection("EPSG:4326");
    mercator = new OpenLayers.Projection("EPSG:3857");

    OLmap = new OpenLayers.Map('map', {

        projection: mercator,
        //maxExtent: extent,

        controls: [
            new OpenLayers.Control.Navigation(),
            new OpenLayers.Control.MousePosition(), //{div:document.getElementById("coordinates")}
            new OpenLayers.Control.ScaleLine(),
            new OpenLayers.Control.Zoom()           
        ],
        zoomDuration: 2,
        numZoomLevels: 10,
        displayProjection: geographic
    });

    arrayOSM = ["http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",
                "http://otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",
                "http://otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",
                "http://otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg"];

    baseOSM = new OpenLayers.Layer.OSM("Political map", arrayOSM,OpenLayers.Layer.OSM,
        {'maxExtent': new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)});
    OLmap.addLayer(baseOSM);

    var gphy = new OpenLayers.Layer.Google(
        "Google Physical",
        {type: google.maps.MapTypeId.TERRAIN}
        // used to be {type: G_PHYSICAL_MAP}
    );  

    OLmap.addLayer(gphy);

    Feature_centroid_wfs = new OpenLayers.Layer.Vector("site",
    {
        projection: geographic // layers' original projection
        ,styleMap: StyleObject
        ,rendererOptions: {zIndexing: true}
        ,strategies: [new OpenLayers.Strategy.Fixed()]          
        ,protocol: new OpenLayers.Protocol.WFS({
            version: "1.1.0"
            ,url: "http://myserver/geoserver/wfs"
            ,featurePrefix: "ramsar_sdi" //geoserver worspace name
            ,featureType: "features_centroid_published" //geoserver Layer Name
            ,featureNS: "http://myserver/geoserver/ramsar_sdi" // Workspace URI
            ,geometryName: "geom" // field in Feature Type details with type "Geometry"
            ,srsName : "EPSG:4326" 
            ,outputFormat: "application/json"
            ,readFormat: new OpenLayers.Format.GeoJSON()
            //,maxExtent: extent  // necessary if BBOX()
        })
    });

    OLmap.addLayer(Feature_centroid_wfs);
1

Your projection value should be a String.

Change mercator to

mercator = "EPSG:3857";

And Just to be clear: You are setting the displayProjection correctly as it requires an OpenLayers.Projection object. It's just the projection value that should be a String.

1
  • I have just tried but it doesn't solve it. My WFS is still off 5 degrees east at full extent (world map) and then the more I zoom the more the WFS features get closer to their correct position. – Pierric May 7 '14 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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