Technical Stuff

I started Bus Monster as a side project in April. It was originally just going to be a tech demo of cool things you can do with Google Maps, but it kinda grew into more than that. =) Bus Monster is a collection of hacks mixed together. For those that are interested, I will briefly go over each piece of the puzzle.

Google Maps

The first piece of bus monster is a modified version of the Google Maps javascript application. I changed some of the internals of the existing application and adding a bunch of my own code, adding about 3000 lines of javascript code.

I extended the google maps application to:

  • display more than one polyline (the blue directions line) at once
  • use multiple colors for polylines (IE only)
  • draw direction arrows along a polyline.
  • show multiple overlays of locations at once
  • update overlays without flickering (for bus locations and traffic cams)
  • draw circles with the polyline code
  • split up long directions in non-IE browsers so that polylines that would be longer than 900 characters in the URL are broken into multiple polylines
  • asyncronously load the xml for a bubble, not just the xsl for it.
  • load my own xml formats.
  • draw relative layers in location markers (so that I can show a bus' route number).

In addition, I added the ability to load the bus data on the fly, deal with alarms, and manage searching for bus stops. Finally, traffic cams are "streamed" to the browser and added and removed as you scroll around the map or zoom. This has the potential of allowing a very large number of locations to be "on the map," but still a reasonable number to be shown at once by collecting locations and representing them with other markers at higher zoom levels.

King County Metro - Trip Planner

The second piece of the puzzle involves screen scraping metrokc.gov's trip planner. Bus Monster puts Google Maps' front end on top of the searching capabilities of King County's metro website.

After playing around with metrokc.gov's URLs for ages, I found fairly simple ways of searching for bus stops by name or coordinates, effectively giving me a geocoding/reverse geocoding tool for the Seattle area. This is used to find bus stops near a particular location.

Current schedule data is also retrieved from the metrokc.gov website via their existing tools.

I screen scrape the results of my queries to find bus stop locations and current schedule data. These are structured into pretty XML documents for bus monster's use on your browser.

Univeristy of Washington - Intelligent Transit Systems

The third part is the University of Washington's Intelligent Transportation Systems software. They have a number of cool things that I use to get real-time bus locations and estimated bus arrival times.

ITS has servers pumping out live bus locations that I receive on my server and publish as CSV files for the bus monster to chomp on. ITS, I believe, helps run mybus.org, and has created the estimation software they use. Luckily, they also provide a web service to get current bus arrival time estimates. This is a full SOAP-capable web service, but I use the REST request format for simplicity. These estimates are more useful than the schedules provided by King County Metro, but they are only available for a limited number of stops ("timepoints", they are called). So, I provide this data when I can, caching it for up to a minute on my side to reduce traffic that goes all the way through me to ITS.

Alarms

I provide an email notification system that keeps a database of alarms that get checked against the ITS estimate web service every minute. A perl script that the bus monster polls every minute checks for alarm updates and when the time is right, if you are browsing the site, you get an on-screen notification. Current alarms are stored in a cookie so that you can browse away from the site and come back and still be notified via your browser. Regardless of whether you are visiting the site or not at the time of the notification, you get an email informing you of your alarm going off.

Traffic Conditions

I found many web cams on the various Washington government webpages, but it was annoying having to go from one site to the next to see the ones I wanted. I have combined them into one single map that keeps only some of them loaded at once so as not to slow your browser down. Traffic cams and Zoom markers are combined into a locations database. Each location has a zoom level mask that is used to determine at which zoom levels it is displayed. (e.g., Traffic cams start disappearing around zoom level 4, just about when Zoom markers start appearing.) Initially, I load all locations for your current screen and the eight screens surrounding you. As soon as you move more than 1/2 of a screen in any direction, I request additional locations for the new area covered, and when I get them, I add them to the existing markers displayed on the map and I remove any that are too far away from you. This allows for pretty seamless scrolling (as long as the server isn't overloaded), and it doesn't flicker when you scroll or zoom. The only annoying part of this was having to find the lat/lng of every camera by hand. Fun.

Greg Sadetsky, who made the original Google Maps Traffic hack, let me in on the secret of where the raw XML data is for Traffic.com and Yahoo!. These two sources are grabbed, parsed, and updated every 5 minutes, with advisories put into the traffic cam database and loaded along with them.

Tada!

Well, there you go. With about 3000 lines of javascript, 2000 or so lines of perl, some XSL for HTML rendering, and some Scheme for image generation, you get busmonster! Woo! I will be putting the code online soon. I will also be putting up some cool little google maps hacks that a few people might possibly find remotely interesting. I will post links on my hacks page. Enjoy!

- Chris Smoak (busmonst@gmail.com)