turf-concave
Takes a set of points and returns a concave hull polygon.
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<link rel="stylesheet" href="assets/css/styles.css" type="text/css">
<script src="//cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
<script src="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="assets/js/es6-promise.min.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,fetch"></script>
<script src="assets/js/helpers.js"></script>
<title>Turf and OpenLayers 3 - Concave</title>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
// Declare a source for points and
// for future convex polygon deduced from them
var vectorSourcePoints = new ol.source.Vector();
var vectorConcavePolygon = new ol.source.Vector();
var vectorLayerPoints = new ol.layer.Vector({
source: vectorSourcePoints
});
var vectorLayerConcavePolygon = new ol.layer.Vector({
source: vectorConcavePolygon
});
// Instanciate a map and add layers
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayerPoints,
vectorLayerConcavePolygon
],
view: new ol.View({
center: ol.proj.fromLonLat([-1.555493, 47.216151]),
zoom: 12
})
});
fetch('assets/data/randomConcave.geojson').then(function(response) {
return response.json().then(function(points_fc) {
var hull = turf.concave(points_fc, {
maxEdge: 3,
units: 'kilometers'
});
console.log(hull);
vectorConcavePolygon.addFeatures(geojsonToFeatures(hull, {
featureProjection: 'EPSG:3857'
}));
vectorSourcePoints.addFeatures(geojsonToFeatures(points_fc, {
featureProjection: 'EPSG:3857'
}));
});
});
</script>
</body>
</html>