Generic Contour Plotting for Google Maps
posted by brian at 02:01 PM
The other day Mike, Spiros, and I began thinking about generating SVG contour maps with JavaScript. The reason is that I want to be able to show a contour map of crime density (like this one of property crime) on the Campus Crime Mapper.
I think a way to generate generic contour maps for Google Maps in JavaScript would be extremely popular with Google Maps developers. It could be used to map temperatures, population density, precipitation, wifi coverage, and lots of other things people are using Google Maps for.
There are only a couple sites out there that have overlayed contour maps on their Google map. The best one seems to be EarthTools, which uses it to display a topographic contour map of the area. I can't tell if it uses static image tiles, SVG, or Canvas; maybe someone else can figure it out.
You're probably wondering why I want to do it all in JavaScript and SVG as opposed to rendering static tiles on the server and overlaying them. There are a few reasons:
- Using JavaScript will make it available to any Google Maps developer, regardless of their server-side tools.
- The contour shapes will only need to be calculated once for all zoom levels, since they are infinitely scalable.
- I am almost positive that the time it takes for the client to calculate and render the SVG contours will be about the same amount of time it would take to download all the custom tiles anyway (especially if they will be zooming and scrolling — hint: they will be).
- Theoretically it will allow the user to change the granularity, colorization, and other aspects of the map.
I'm not looking to generate anything insanely detailed, just something at about this detail level.
I have some proof-of-concept code online that tests finding shape contours and smoothing them with Bezier curves. You will need either Firefox 1.5 or a browser with Adove SVG enabled to view those demos (I'm considering also supporting Canvas).
Note: Those pages (and the Crime Mapper) will be down while I move into the Village.
Speaking of SVG and Canvas, I'm going to use this sweet JavaScript plotting library called plotkit to show crime statistics — check out the demo on that page!
I'm excited to see how far I can take this, but right now I've got two days left in the Summer of Code.
Comments
How about giving us some details on how the SoC project is going? ;-)
Hey! Look at my blog, everyone!
Did I do that myself? Hells no! Thank this guy over here for abolishing that pile of UGLY that used to be my blog. New entries on the way... :)
EarthTools uses png overlays such as these two:
http://www.earthtools.org/tiles/tqt/srr/rsr/srt.png
http://www.earthtools.org/tiles/tqt/srr/rsr/ss.png
use a WMS to overlay that stuff
Re: WMS...
Wouldn't that be the same as generating static image tiles, except they just happen to be described by a document format with a well-defined spec?
Was just looking through the referrers list for earthtools.org and noticed this blog!
I have (am!) statically generated all the tiles for earthtools.org - sadly it is extremely computationally expensive for some of the tiles where there are many contours.
The code I use reads a 2D matrix of values and draws contours based on a number of options - the algorithm is really rather simple and I don't do any complicated rendering such as bezier curves as it would be more difficult to get the tiles to match up.
If you're interested I might be able to help out if you want to contact me.