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