Leaflet Choropleth
Choropleth plugin for Leaflet (color scale based on value) - Demo
This plugin extends L.geoJson
, giving each feature a style.fillColor
that corresponds to a specified value
in its properties
object. For information on how to use L.geoJson
, see the Leaflet
tutorial and documentation.
While Leaflet provides a choropleth tutorial, that approach requires you to specify exact breakpoints and colors. This plugin uses chroma.js to abstract that for you. Just tell it which property in the GeoJSON to use and some idea of the color scale you want.
Usage
L
Advanced
- colors: If you prefer to specify your own exact colors, use
colors: ['#fff', '#777', ...]
instead ofscale
. Just make sure the number of colors is the same as the number ofsteps
specified. - valueProperty: To use computed values (such as standardizing),
you can use a function for
valueProperty
that is passed(feature)
and returns a number (example).
Installation
- via NPM:
npm install leaflet-choropleth
- via Bower:
bower install leaflet-choropleth
Include dist/choropleth.js
on your page after Leaflet:
Or, if using via CommonJS (Browserify, Webpack, etc.):
var L =
Examples
Development
This project uses webpack to build the JavaScript and standard for code style linting.
- While developing, use
npm run watch
to automatically rebuild when files are saved - Use
npm test
to run unit tests and code style linter - Before committing
dist/
, usenpm run build
to optimize and minify for production use