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.
- Start with this jsbin, which loads city council districts and vacant lots in Queens.
- Use
turf.count
to get the city council districts including the number of vacant lots in each one. - Set
classes
to the result of classifying the city council districts by the number of vacant lots in each, for example by usingturf.jenks
. Use 4 classes. - Add the resulting GeoJSON object to
turfLayer
. - This jsbin is a working example.
Part 2: Turf, dynamic
Make a map that uses Turf in response to user input.
- Start with this jsbin.
- Where the file indicates that you should, use
clearLayers()
to get rid of any existing layers onturfLayer
. - As indicated, use
getLayers()
to write anif
statement that checks that the number of layers onturfLayer
is at least 3. - Within the
if
statement from 3, find the convex hull of theclickedPoints
and add that toturfLayer
. - This jsbin is a working example.