I am a biker, sailor, and skier... and also
a geographer, cartographer, web guy, and educator.
Skills and tools for better planning.
Goal improve departmental capacity in data analysis, visual representation, and technological communication tools.
Spring 2015
http://duspviz.mit.edu/web-map-workshop
GOAL: Introduce webmapping and coding to planners in a relevant and concise way.
A lightweight web map application in which visitors can input information.
We need a place to keep our data.
This database has to be spatially enabled.
PostgreSQL and PostGIS would do the trick.
Provides a configured, cloud-based instance of PostGIS
Con: storage limited. Pro: storage still often sufficient.
Allows us to hit our CartoDB datasets with SQL Queries, returns JSON object.
Accepts SELECT, INSERT, UPDATE, and DELETE Statements
View DocumentationSELECT * FROM coffee_cafes
ORDER BY the_geom <-> ST_SetSRID(ST_MakePoint({lng},{lat}), 4326) LIMIT 5
Security Matters... we'll talk more about this later.
We need something server-side to hold our credentialed information to allow for write access.
We have some options... NodeJS? PHP?
Easy to use, intuitive interface.
Build a nice modal to collect information.
JavaScript and jQuery
Data Collector
Throw in a couple test points in CartoDB.
Set up the page.
This application is contained all within a single html doc.
Set up the document and map
// Create Leaflet map object
var map = L.map('map',{ center: [42.381899, -71.122499], zoom: 13});
// Add Tile Layer basemap
L.tileLayer('http://a{s}.acetate.geoiq.com/tiles/acetate-hillshading/{z}/{x}/{y}.png', {
attribution: '©2012 Esri & Stamen, Data from OSM and Natural Earth',
subdomains: '0123',
minZoom: 2,
maxZoom: 18
}).addTo(map);
Use the SQL API to call a JSON object into your map.
CartoDB SQL API in action
// Get CartoDB selection as GeoJSON and Add to Map
function getGeoJSON(){
$.getJSON("https://"+cartoDBUsername+".cartodb.com/api/v2/sql?format=GeoJSON&q="+sqlQuery, function(data) {
cartoDBPoints = L.geoJson(data,{
pointToLayer: function(feature,latlng){
var marker = L.marker(latlng);
marker.bindPopup('' + feature.properties.description + '
Submitted by ' + feature.properties.name + '
');
return marker;
}
}).addTo(map);
});
};
Leaflet Draw is one of many "crazy useful and awesome" Leaflet plugins.
Utlize jQuery set up a modal window to get information from the user.
Set up functions to compile our query to put items to the server.
Our basic structure and workflow is almost done.
Protect yourself from deviants and queries that wreak havoc.
Check out this pull request to address this problem.Collect lines and polygons.
Add user registration and login.
Edit points and update your dataset.
Expand to Mobile.
Implement higher security measures
Migrate to Leaflet 1.0
Utilize CartoDB.js and non PHP options
Explore other Data Collection Alternatives
Expand Data Storage Options
All this code is open sourced.