This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Online Maps with OpenLayers

Making maps with Google Docs and Fusion Tables

Nick Doiron's picture
Mon, 2011-03-21 16:00

Making a KML file using Google Docs / Spreadsheets

The quickest way to create and post a KML file online is to follow Google's directions for making a spreadsheet map.  This tool limits you to 400 points.

http://earth.google.com/outreach/tutorial_spreadsheet.html

Instead of entering each latitude and longitude, you can use this trick - http://apitricks.blogspot.com/2008/10/geocoding-by-google-spreadsheets.html - to get Google Spreadsheets to look up the location on Google Maps.

At the step where you copy the network link KML, take only the URL and download the file.  Copy this file onto a server, use your server to help OpenLayers connect to the URL, or use a text editor such as Notepad to copy the data and paste it into your OpenLayers map page.

Mapping using Google Fusion Tables

The Fusion Tables tool has been maintained by Google for over a year now, but it isn't as well known as Google Docs.  A fusion table is similar to a spreadsheet or database, but it is designed primarily for data on the web.  Google has built in a number of tools to showcase your data on Google Maps, which means it can be shown in OpenLayers, too.

There are two options to map using Google Fusion Tables.  Just like with spreadsheets, you can download all of the data in a KML file.  Google offers directions for adding multiple types of geodata (points, lines, shapes): http://www.google.com/support/fusiontables/bin/answer.py?hl=en&answer=174680 , customizing the appearance of the map http://earth.google.com/outreach/tutorial_fusion_sample.html , and downloading it as KML: http://www.google.com/support/fusiontables/bin/answer.py?answer=171215 
Just as you would with the spreadsheet's KML network link, use the URL part of the link to download the file and copy the data, or use your server to access it.

The second option is to use map tiles from Google Fusion Tables.  Instead of loading all of the data in your Google Fusion Table, your table creates tiles such as this one - http://mt0.googleapis.com/mapslt?hl=en-US&lyrs=ft%3A113681&x=67&y=39&z=7&w=256&h=256 - which are pasted over the map to create the illusion of marker icons.  This is an XYZ tile layer which can be added to OpenLayers, too.  Find the id number of your fusion table - the same you would use with Google Maps - and use it to replace the number 113681 (Google's sample layer) in the following example:

http://jsfiddle.net/UAxun/123/

Here are the key changes:

  • allOverlays: true  in the map-creation options, so that both layers appear together
  • fusionLayer new OpenLayers.Layer.OSM("Fusion Table Map","http://mt0.googleapis.com/mapslt?hl=en-US&lyrs=ft:113681&x=${x}&y=${y}&z=${z}&w=256&h=256&source=maps_api");  // sets up the XYZ layer
  • map.addLayer( fusionLayer );

The main problem with this method is that the points aren't clickable.  I would recommend using this method for something where there are many points that you want to show, but the user doesn't need to click, or you want them to get the real data from you.  You could also use events to recognize when and where the user clicks the map, and you could write a method to respond with a popup of nearby locations.

Comments

US Census Bureau released

Sharon Machlis's picture
Sharon Machlis
Wed, 2011-03-23 18:40

US Census Bureau released 2010 data for Massachusetts yesterday. Here's a map of population changes for towns in Middlesex County

http://cwrld.us/g2ZUDG

(I still need to embed it in an HTML page, code a legend for the colors, put a headline on it, etc., but you get the map idea)

Oops that was the map of

Sharon Machlis's picture
Sharon Machlis
Wed, 2011-03-23 19:59

Oops that was the map of population changes *by census tract* for towns in Middlesex County.

This is the map by town:

http://cwrld.us/dSQMUI

(also still need to embed in page and code a legend)

Sharon, cool! I like both

Randy Rosso's picture
Randy Rosso
Wed, 2011-03-23 20:09

Sharon, cool! I like both maps. I'm curious why you chose to use a county boundary -- I had the impression that counties aren't very meaningful boundaries or entities in New England.

Thanks, Randy, and good

Sharon Machlis's picture
Sharon Machlis
Thu, 2011-03-24 01:51

Thanks, Randy, and good question. A couple of reasons: One is that I wanted to work in smaller units than towns, and the file size would be out of control if I did the whole state. Second is that I used to work at a newspaper called the Middlesex News :) I still naturally gravitate toward exploring that region.

I also didn't want to duplicate what I knew the major newspapers would be doing statewide. Boston Globe did their usual impressive job:
http://www.boston.com/news/local/massachusetts/graphics/03_22_11_2010_ce...

as did the Providence Journal
http://www.projo.com/news/census2010/mass/mass_all_towns800.htm (this one I know was done with QGIS, JavaScript and jQuery. Not sure what the Globe used).

I finally downloaded a data file for blockgroups -- the files are available by county on the Census Web site. I'm going to work on a map for that....

OK here's my final project,

Sharon Machlis's picture
Sharon Machlis
Thu, 2011-03-24 02:59

OK here's my final project, mapping percent of vacant housing units by block group in Middlesex County, Mass.

http://www.machlis.com/housing_census.html