04: Custom Map Controls
This example demonstrates a map with two toggleable layers—hexbins and crash points—overlaid on a Mapbox GL base map. The hexbins are generated from a GeoJSON dataset of NYC crashes using Turf.js to create a hex grid and count incidents per cell, colored with a Jenks natural breaks classification. Custom UI buttons let users toggle each layer on and off, with active states highlighted. The code also shows how to filter invalid geometries and style layers dynamically.
AI-generated description04 Adding Custom Map Controls
In this example we add a couple buttons to our map (their style could be improved, sorry!) which allow for toggling the hexbins and crashes point data on and off.
Things to Try out
- See if you can add a slider for each layer, to change its opacity.
- What other UI elements might we need for this map? How would we go about making them?
Built with blockbuilder.org
forked from <a href='http://bl.ocks.org/clhenrick/'>clhenrick</a>'s block: <a href='http://bl.ocks.org/clhenrick/54868a85037c69e54f5e43ffe07c7ee9'>ischool-geo-viz-template</a>
forked from <a href='http://bl.ocks.org/clhenrick/'>clhenrick</a>'s block: <a href='http://bl.ocks.org/clhenrick/57a76d0f25877840568ab26515eb03ac'>ischool-geo-viz-02</a>
forked from <a href='http://bl.ocks.org/clhenrick/'>clhenrick</a>'s block: <a href='http://bl.ocks.org/clhenrick/b60428829fc936a16706ac9964f8b450'>ischool-geo-viz-04</a>