[GIS] Problem mixing the google maps and WMS layer

openlayers-2

I have been trying to use both google maps and WMS layers as an option in the layerswitching panel. But when I switch the base layer from WMS to Google Maps layer and then back to WMS,

the bounds of the map do not come right and the map is not displayed properly.
Even the vector overlay features which display correctly at 1st in the WMS, get crowded into small area on the google maps. I think there is some problem with the re-instantiation of the maps variable during layer switch, due to which the map bounds are not correct.

But still on the whole, please tell me how to solve this problem as it would be great to be able to use any map service in a single HTML page.

Best Answer

Is the WMS layer in the same projection as the Google layer? If not, you will have to handle the LayerSwitch event and reproject the overlay to make it align with the different projection. Note that the OpenLayers devs don't recommend mixing base layer projections, but in practice it can be made to work.