Advanced Interactive Web Mapping, Programming, and Design

In-class Excercises: Turf

Part 1: Turf, aggregation

Make a choropleth map by counting the number of points in each polygon and classifying the polygons.

  1. Start with this jsbin, which loads city council districts and vacant lots in Queens.
  2. Use turf.count to get the city council districts including the number of vacant lots in each one.
  3. Set classes to the result of classifying the city council districts by the number of vacant lots in each, for example by using turf.jenks. Use 4 classes.
  4. Add the resulting GeoJSON object to turfLayer.
  5. This jsbin is a working example.

Part 2: Turf, dynamic

Make a map that uses Turf in response to user input.

  1. Start with this jsbin.
  2. Where the file indicates that you should, use clearLayers() to get rid of any existing layers on turfLayer.
  3. As indicated, use getLayers() to write an if statement that checks that the number of layers on turfLayer is at least 3.
  4. Within the if statement from 3, find the convex hull of the clickedPoints and add that to turfLayer.
  5. This jsbin is a working example.