In this final post of the series, the design views in CouchDB will be used to populate heat maps and show near real-time device location. The code for the maps is hosted at GitHub (https://github.com/markfennell/couchdb_heatmap).
The mapping code uses the following libraries:
- heatmap.js v2.0.0 by Patrick Wied (http://www.patrick-wied.at/static/heatmapjs/),
- LeafletJS (http://leafletjs.com/)
- SimpleHeat (https://github.com/mourner/simpleheat)
This post will not discuss the code used to produce the heat maps but will show how the pages render in the browser.
- Cheap, Fast, Reliable
- Eventual Consistency
- Create VM
- SSH Security
- Capture VM
- Client Code
- Create Databases
- Create Benchmark/Testing Code
- Create Views
- Start Replication
- Cron Jobs
- Performance Tweaks
- CouchDB local.ini mods
- Mapping Data
- Aggregate Heat Map
- Live Map
5. Map Code
Aggregate Heat Map
The Aggregate Heat Map uses the map-reduce view to summarize hot spots or (x,y) coordinates to occur frequently in the data. Using Leaflet, the code allows for panning and zooming.
The Live Map shows data points as they are recorded in the database using the map design view. The Live Map has also been called a Marauder Map based on the map used in the Harry Potter series. The map design view serves a timestamp and coordinate pair for a requested time frame. Every five seconds, the data is drawn on a canvas layer that is discarded as time passes and each new layer is drawn on top of older layers with 60% transparency. By using the HTML5 canvas, data and DOM layers do not accumulate over time and reduce the resources required by the browser.