Home About Links How To Use MyStuff Search

Publishing Large Datasets on Google Maps

- from a talk to NMGIC on April 24, 2008, Nelson Guda, PhD

Here is a word file with the notes taken directly from my ppt.

 

Getting WMS data on Google Maps

I used Mapserver as a WMS server to create tiles from ESRI shapefiles. On Roadlessland.org, all the roadless areas, wilderness areas and other forest service areas are drawn this way from shapefile data. The Topo map layer is also a WMS layer that is served by the USGS.

To put wms layer in your map you can use a small javascript file developed by John Deck at Berkeley called wms236.js.

WMS layers can be added as either new base layers or as layers that float on top of all your base layers. Here are examples of both with the code:

New WMS base layer || WMS floating layer

Querying WMS data on Google Maps

You can query WMS layers indirectly from Mapserver with a GetFeatureInfo query. Here is how to do that.

  1. Set a function on the google map to record the lat / lng of your clicks and send it to another function (here is an example).
  2. Calculate the info that Mapserver needs to match your lat/lng point with a particular tile at a particular zoom level.
  3. Mapserver can't just use the lat/lng points of your query, it needs the coordinates translated into information that matches the WMS tile for that location. Specifically, it needs to know:
    1. the lat/lng coordinates of the tile that would enclose your query point (bbox) at a specific zoom; and
    2. xy distance in pixels from the corner of the tile to the point you are querying.
  4. This is a pain, but you can calculate all of that with a php function that was developed by other people! Here is a link to a post I put on the Google Map API group where I put the code for calculating WMS tile coordinates.
  5. Here is an example of using php to calculate the bbox and xy pixel coordinates.
  6. Then you send a GetFeatureInfo query in the same way that you send a WMS query - as a URL. Here is an example of what the URL needs to look like broken into its component parts (this all gets strung together):
    • http://yourdomain/cgi-bin/mapserv?
    • map=yourmapfile&
    • REQUEST=GetFeatureInfo&
    • SERVICE=WMS&reaspect=false&VERSION=1.1.1&
    • LAYERS=layer1,layer1&
    • STYLES=default&FORMAT=image/gif&
    • BGCOLOR=0xFFFFFF&TRANSPARENT=TRUE&SRS=EPSG:4326&
    • WIDTH=256&HEIGHT=256&
    • QUERY_LAYERS=layer1,layer2&
    • bbox=west,north,east,south&
    • x=num&y=num

Here is an example of a mapfile that allows you to make GetFeatureInfo queries. The important things to include are:

    • Layer tags:
      • TOLERANCE 3 (how large an area should the query consider)
      • TOLERANCEUNITS PIXELS
      • DUMP TRUE (allow the wms to release data)
    • These layer metadata tags:
      • "wms_feature_info_mime_type" "text/html"
      • 'wms_include_items' 'all'

Here is an example of WMS GetFeatureInfo queries returned using the above methods.

Other Stuff

Drag Zoom: This is the box that lets you drag to zoom into an area on the map. Dragzoom is part of the GMap utility library, which has some other good utilities also. Here is the original post about dragzoom. This is a link to the simple dragzoom example where you can get the code.

I'll post more things here when I think of them, or if people ask.

More Good Links

Google Map Documentation

Google Map API discussion group

- There are lots of good answers in here, but you often have to dig deep for them.

Google Map Tutorials by Mike Williams

- Excellent simple tutorials with good examples

Google Earth Documentation

Using Google Earth files on Google Maps

 

If you have any other questions, feel free to e-mail me at