WMS in Google Maps

As a follow up to my previous tutorial on how to use your own custom map tiles in Google Maps, here’s the code (function) you need to convert Google tile x, y, and zoom into a suitable WMS URL. Just stick this code in the getTileURL(x, y, zoom) or getOverlayURL(x, y, zoom) functions and tweek some of the parameters to your needs.


var baseURL = "http://localhost/cgi-bin/mapserv?"; //begining of the WMS URL ending with a "?" or a "&".
var format = "image/jpeg"; //type of image returned
var layers = "example_layer"; //WMS layers to display
var styles = ""; //styles to use for the layers
var srs = "EPSG:4326"; //projection to display. Don't change unless you know what you are doing.
var ts = this.tileSize;
var ul = this.getLatLng(x*ts,(y+1)*ts, zoom);
var lr = this.getLatLng((x+1)*ts,y*ts, zoom);
var bbox = ul.x + "," + ul.y + "," + lr.x + "," + lr.y;
var url = baseURL + "version=1.1.1&request=GetMap&Layers=" + layers + "&Styles=" + styles + "&SRS="+ srs +"&BBOX=" + bbox + "&width=" + ts +"&height=" + ts + "&format=" + format + "&transparent=true";
return url;

13 Responses to “WMS in Google Maps”

  1. Just Says:

    Great work!
    See also http://www.geoskating.com/gmap and my blog http://www.justobjects.org/blog/index.php?p=14 . I basically formalized your solution (and from Brian Flood http://www.spatialdatalogic.com/cs/blogs/brian_flood/archive/2005/07/11/39.aspx) into a function.

    best,

    Just

  2. JC Says:

    Thanks for the email Kyle. This is good stuff and does address my comment in the previous installment. I wonder though, if it would be possible for just a few more comments through the code?

  3. subu Says:

    hi kyle my aim is to connect Map server and google API for my Indian data.If there is any source code available kindly send me please…if full source code available it would be helpful…

  4. Kha Says:

    How’s about geocode and routing function?
    Can we submit their data?
    Thanks

  5. Kyle Mulka Says:

    Kha,

    What about geocode and routing? The Google Maps API doesn’t provide that service.

    What do you mean by “submit their data”. Who’s they, and where are we submitting it?

    -Kyle

  6. Kha Says:

    Hi Kyle,

    I see geocode and routing functions are supported by maps.google.com. Can we implement for unsupported areas?

    In WMS example (Kyle and Just), the overlay layer will hide G’s layers. I see G’s Road layer in Kyle’s but no G’s layer in Just’s. My map http://naman.dyndns.org:8080/map1.html also hide G’s.
    Could we mix them?

    Thanks

  7. Jacob Reimers' Weblog Says:

    Experimenting With Web Map Services for Google Maps

    Viewing map images from Web Map Services (WMS) servers is a useful extension to the Google Maps API. It lets you present more than just geographical data. Now you can present weather maps or vegetation maps and lads of other topics.

  8. varun Says:

    sir at d very begining of ur tutorial u hv mentioned dat u ;ll assume dat 1 would knw dat how 2 make a function dat can get correct image url for each tile of google map ……
    but dis is wat i want to know dat wat is dat function dat can fetch tile url …..plzzzzzzzzzzzz help me out wid dis
    regards varun

  9. Joshua Marinacci's Blog Says:

    NASA Maps in your Swing App

    Short short version: Not Awesome Awesome! Short version You can now embed some NASA map servers into your own Swing apps using the JXMapViewer component in SwingX-WS. Long version For the Aerith demo we showed at JavaOne we build a…

  10. n0mer’Z home » Карты NASA в Swing-приложении Says:

    […] отке, решая сложные уравнения. Но толковые ребята Kyle Mulka и Charlie Savage дали толковые объяснения, что сделало возмож […]

  11. Kyle Mulka’s Weblog » How To Overlay Custom Maps Using the Google Maps API Says:

    […] Warning: For this tutorial I assume you know how to make a function that returns the correct image URL for each tile based on Google’s numbering system. I explain how to use a WMS service to generate tiles for you here. […]

  12. Mark Mouse Says:
  13. Gaurav Says:

    hi kyle my aim is to connect Map server and google API for my Indian data.If there is source code available it would be helpful…

    thanks in advance

    waiting for your reply

Leave a Reply