Fork me on GitHub

Classify Data with ClassyBrew

Leaflet Code to Create Map

View storm_events GeoJSON Used in this Example
// create leaflet map
var map = L.map('map').setView([37.8, -96], 3);

// Add basemap
L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.{ext}', {
	attribution: 'Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap',
	subdomains: 'abcd',
	minZoom: 0,
	maxZoom: 20,
	ext: 'png'
}).addTo(map);

// create classybrew object
var brew = new classyBrew();

// pass values from your geojson object into an empty array
// see link above to view geojson used in this example
var values = [];
for (var i = 0; i < storm_events.features.length; i++){
	if (storm_events.features[i].properties['PERCENT'] == null) continue;
	values.push(storm_events.features[i].properties['PERCENT']);
}

// pass array to our classybrew series
brew.setSeries(values);

// define number of classes
brew.setNumClasses(6);

// set color ramp code
brew.setColorCode("Blues");

// classify by passing in statistical method
// i.e. equal_interval, jenks, quantile
brew.classify("equal_interval");

// style function to return
// fill color based on brew.getColorInRange() method
function style(feature) {
	return {
		weight: 2,
		opacity: 1,
		color: 'white',
		dashArray: '3',
		fillOpacity: 0.7,
		fillColor: brew.getColorInRange(feature.properties.PERCENT)
	}
}
		

// add geojson to map
// calling the style method on each feature
geojson = L.geoJson(storm_events, {
	style: style
}).addTo(map);
				


About

ClassyBrew was created by TannerGeo as an Open Source solution to bulding thematic maps and graphics. It uses proven statistical methods and color theory palettes to help you represent your data faster and more accurately. If you find it helpful, please fork this repo and help improve it.