Tiled WMS overlay on Google Map v3

this is the third sample of the tiled WMS overlay over the Spherical Mercator, this time over the new Google Map v3. Previsous post talked about overlyaing WMS in  Silverlight Bing maps (https://blog.sumbera.com/2010/02/25/overlay-wms-on-google-in-silverlight-bing/ ) and OpenLayers (https://blog.sumbera.com/2010/02/17/overlay-wms-on-google-in-openlayers/).

Sample application can be found here: http://www.sumbera.com/lab/GoogleV3/tiledWMSoverlayGoogleV3.htm You can try to run it on your mobile device as well – suprisingly it run very well on my iPhone (sometimes it just crash Safari :), however on the iPad there are some more serious issues that will be hopefuly resolved with new iOS update (JavaScript stops to run).

For the new Google Map v3 you have to do the following :

//Define custom WMS tiled layer

var SLPLayer = 
 new google.maps.ImageMapType (
 {
  getTileUrl:
    function (coord, zoom) { 
      var proj = map.getProjection(); 
      var zfactor = Math.pow(2, zoom); 
       // get Long Lat coordinates
      var top = proj.fromPointToLatLng(
             new google.maps.Point(coord.x * 256 / zfactor, coord.y * 256 / zfactor) ); 
      var bot = proj.fromPointToLatLng(
            new google.maps.Point((coord.x + 1) * 256 / zfactor, (coord.y + 1) * 256 / zfactor)); 
      //corrections for the slight shift of the SLP (mapserver)
       var deltaX = 0.0013; 
       var deltaY = 0.00058; 
      
      //create the Bounding box string
       var bbox = (top.lng() + deltaX) + "," +(bot.lat() + deltaY) +","
                           +(bot.lng() + deltaX) +"," +(top.lat() + deltaY);
      
       //base WMS URL
        var url = 
       "http://mapserver-slp.mendelu.cz/cgi-bin/mapserv?map=/var/local/slp/krtinyWMS.map&" ;
       url +="&REQUEST=GetMap"; //WMS operation
       url +="&SERVICE=WMS"; //WMS service
       url +="&VERSION=1.1.1"; //WMS version 
       url +="&LAYERS=" + "typologie,hm2003"; //WMS layers
       url +="&FORMAT=image/png"; //WMS format
       url +="&BGCOLOR=0xFFFFFF" ;
       url +="&TRANSPARENT=TRUE" ;
       url +="&SRS=EPSG:4326"; //set WGS84 
       url +="&BBOX="+ bbox; // set bounding box
       url +="&WIDTH=256"; //tile size in google
       url +="&HEIGHT=256" ; 
       return url; // return URL for the tile    
     }, //getTileURL

 tileSize: new google.maps.Size(256, 256),
 isPng: true
 });

//add WMS layer
 map.overlayMapTypes.push(SLPLayer); 

 
 
 

15 thoughts on “Tiled WMS overlay on Google Map v3

  1. Pingback: Overlay WMS on Google in Silverlight Bing « Geospatial Haiku

  2. Pingback: Overlay WMS on Google in OpenLayers « Geospatial Haiku

  3. Niklas Ringdahl

    What is the correction deltaX/deltaY for? I’ve been struggling with errors that was fixed when I removed them. I use ArcGIS Server for my WMS, what do you use?

    Reply
  4. Tomas

    Parada. Ale jak je to s copyrightem u OpenStreetMaps? Chtel bych je taky pridat jako vrstvu do sve mapove aplikace. Musim pak zobrazovat nejake logo a dalsi informace? Jak?

    Reply
  5. Pingback: How to style transparent overlayed WMS layer | appsgoogleplus.com

  6. dt

    Hi,
    firstable congratulations for your app!
    Is it possible to have your mapserver mapfile?
    I would like to know how to set a mapfile in order to be used by googlemaps api

    Reply
  7. Pingback: How to style a WMS layer? | web technical support

  8. Pingback: How to style a WMS layer? | Q&A System

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.