Using turf.js to split up a GeoJSON object based on a categorical property and create convex hulls for each result
by nathansnider
HTML
<script src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.css">
<script src="https://api.mapbox.com/mapbox.js/plugins/turf/v2.0.2/turf.min.js"></script>
<div id="map" style="width:500px; height:500px"></div>
JavaScript
////////////////////////////////////////////////////////////////////////////////////////////
//setting up the map//
////////////////////////////////////////////////////////////////////////////////////////////
var map = new L.Map('map').setView([40.75, -74], 11);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
////////////////////////////////////////////////////////////////////////////////////////////
//adding the data//
////////////////////////////////////////////////////////////////////////////////////////////
var casinos = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.997, 40.642]
},
"properties": {
"boss": "Freddy Queens"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.985, 40.680]
},
"properties": {
"boss": "Freddy Queens"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.949, 40.697]
},
"properties": {
"boss": "Freddy Queens"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.968, 40.651]
},
"properties": {
"boss": "Freddy Queens"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.981, 40.772]
},
"properties": {
"boss": "Manhattan Michael"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.939, 40.813]
},
...