Thursday, August 30, 2007

Maps, and a Google tweak

Today I stumbled across the Species Distribution Widget from GBIF (written by Tim Robertson and Dave Martin). For Mac OS X 10.4 users, this provides a cool way to quickly get a distribution map for a taxon. Given that Apple dashboard widgets are essentially Javascript and HTML, it occurred to me to reverse engineer the widget to see what it did. To open the widget you just "Ctrl-click" on the widget icon, select Show Package Contents, and the contents open in a Finder window.

The guts of the widget is in the scripts folder. This contains a Javascript file. The widget calls the URL /view/ajaxMapUrls/provider/1/?query=, to which is appended the taxon name you are searching for. Back comes the result in XML. For example, searching for Apus apus returns:
<name>Apus apus</name>
<commonName>Common swift</commonName>

(Shouldn't "taxons" be "taxa"?) The URL of the corresponding map is given in the <url> tag. Append this to ", and you have the URL for the image of the map. For example, here's the map for Apus apus.

I've added code to do this to iSpecies, so it now features maps from from GBIF. I've also finally tweaked the Google code to stop mangling UTF-8 characters.