December 19
How do you get Google Map working with custom WMS layers with Mapbuilder / OpenLayer ?
Posted by AjayI came across an interesting problem when working on an interesting feature for our web mapping application. Let me first give you a very brief background about our application. Our web mapping setup uses Mapbuilder/OpenLayers as the client side Javascript API, A custom WMS/WFS server, geowebcache as our caching intermediary and PostGIS/PostGRES as our geospatial database. Every web mapping software will have a set of layers that are rendered. Every web mapping software will also have a basemap which defines the projection and bounding box for the model.
Our application has a very beautiful basemap designed by our GIS Analysts, that even includes beautiful hill terrain details. But one fine day our client gave us some extra money to research the feasibility of allowing users to select multiple types of basemaps , allowing them options to use Google and Yahoo basemaps instead of the basemaps we designed for them.
This led me on the journey to figure how to set our client to get a google basemap. One of the very irritating things about Google is their affinity to the 900913 SRS code.
Mapbuilder/OGC provides a very nice standard context document called OWSCOntext that allows Mapbuilder to use non WMS based layers like google and yahoo maps. Setting this up is simple as creating a context document that serves an OWSContext. But the catch is trying to get our WMS layers (that are 4326 based) to work with google maps. Google maps accepts two CRS 4326 and 90013, but guess what, it’s only the 900913 system that guarantees that the WMS layers lines up with the google map. The catch doesnt stop there, apparently PostGIS does not really have 90013 SRS setup.
SO in order to use google maps as a basemap on Mapbuilder/OPenLayers along with custom WMS layers served by our geospatial server, we need to follow the following steps
1. Setup an OWSCOntext document
2. make sure all the bounding box and SRS in the context document is in SRS 900913
3. make sure the spatial database recognizes 900913
4. if you use a custom geospatial server, make sure that you perform necessary transformations to convert your 4326 data to 900913.
And guess what geotools does not support 900913 off the box, but it does allow you to use the WKT of that CRS to create your CoordinateReferenceSystem. Next on my to do list, get our mapping application working with yahoo maps and Microsoft map.