GithubHelp home page GithubHelp logo

ahazrat / leaflet-choropleth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timwis/leaflet-choropleth

0.0 1.0 0.0 380 KB

Choropleth plugin for Leaflet (color scale based on value)

Home Page: http://timwis.com/leaflet-choropleth/examples/basic

License: MIT License

JavaScript 100.00%

leaflet-choropleth's Introduction

Leaflet Choropleth Build Status js-standard-style

NPM

Choropleth plugin for Leaflet (color scale based on value) - Demo

screenshot

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.choropleth(geojsonData, {
	valueProperty: 'incidents', // which property in the features to use
	scale: ['white', 'red'], // chroma.js scale - include as many as you like
	steps: 5, // number of breaks or steps in range
	mode: 'q', // q for quantile, e for equidistant, k for k-means
	style: {
		color: '#fff', // border color
		weight: 2,
		fillOpacity: 0.8
	},
	onEachFeature: function(feature, layer) {
		layer.bindPopup(feature.properties.value)
	}
}).addTo(map)

Advanced

  • colors: If you prefer to specify your own exact colors, use colors: ['#fff', '#777', ...] instead of scale. Just make sure the number of colors is the same as the number of steps 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 from this repository on your page after Leaflet:

<script src="path/to/leaflet.js"></script>
<script src="path/to/choropleth.js"></script>

Or, if using via CommonJS (Browserify, Webpack, etc.):

var L = require('leaflet')
require('leaflet-choropleth')

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/, use npm run build to optimize and minify for production use

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.