Browser-side Geospatial Maps

If you know many marathon runners, then you probably know somebody in the Fifty States Marathon Club, like my friend Jennifer. Here is a post from Jennifer on Facebook:

Map of states run

Jennifer’s 50-States Progress Report

What if users could simply use their electronic running log to generate progress maps on-the-fly? And, what if that map could be generated without increasing the load on expensive geospatial database servers?

That is exactly what I’m demonstrating today with Tom McWright‘s Leaflet-pip library. See it live here: http://exploringspatial.com/#demo/8. This demo reuses a personal running log GeoJSON file from demo 5. It combines my race data with a GeoJSON file containing shapes for the 50 states that I found at Frictionless Data.

The map flow is illustrated below. Keep in mind that I’m doing all of this with static files on my Amazon S3-hosted website.

states_map_flow

First, RightSideView.js downloads the running log GeoJSON file and the States GeoJSON file. It passes the states GeoJSON feature collection to StatesMapLayerView.js which loads it into three maps: the mainland, Alaska, and Hawaii.

Next, RacesMapLayerView.js loads the running log GeoJSON feature collection into a Leaflet GeoJson Layer filtering by eventType = “Race” and totalMeters equals the selected race distance. As each point is added to the map, MapEventDispatcher.js is used to publish a RACE_ADDED event.

The RACE_ADDED event triggers the State Map Layer View to call the Leaflet-pip library to find the state polygon containing the race point and change that state’s background color from blue to red.

Image of code used to find the race start point.

Find State Containing Race Start Point

Above the map is the race selector. It uses the Map Event Dispatcher to fire the RACE_SELECTED event. The RACE_SELECTED event triggers the State Map Layer View to remove all state highlighting. It also triggers the Race Map Layer View to re-filter the running log GeoJSON file using the updated race distance. That, in turn, fires RACE_ADDED again, which re-triggers state highlighting.

That’s it. Pretty simple. The geospatial matching to produce this map, that might have been done, say, in Oracle Spatial, is successfully offloaded to the customer’s web browser instead. This leaves expensive servers to do the large-scale geospatial operations they do best.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s