Turf issue #1881
by Stefano
HTML
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css">
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
<div id="map"></div>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
#map {
width: 100%;
height: 100%;
}
JavaScript
const data = {"type": "Feature","properties": {},"geometry": {"type": "LineString","coordinates": [[-0.703125,11.523087506868514],[12.3046875,34.016241889667015],[36.03515625,35.460669951495305],[45.3515625,34.88593094075317],[51.328125,31.952162238024975],[61.17187499999999,23.563987128451217],[64.6875,14.43468021529728],[50.09765625,12.382928338487396],[28.828124999999996,12.211180191503997],[14.589843749999998,12.211180191503997],[30.05859375,25.16517336866393],[27.421875,-5.44102230371796],[36.5625,17.811456088564483],[42.1875,4.214943141390651],[47.28515625,17.14079039331665],[64.51171875,12.039320557540572],[57.83203125,0.17578097424708533],[30.234375,-19.808054128088575],[13.7109375,-12.897489183755892],[5.2734375,-5.44102230371796],[-0.17578125,9.96885060854611]]}};
function toPoints (features) {
const points = [];
turf.coordEach(features, function (currentCoord) {
points.push(turf.point(turf.getCoords(currentCoord)));
}, {excludeWrapCoord: true});
return turf.featureCollection(points);
}
const points = toPoints(data);
console.log(JSON.stringify(points));
const hull = turf.concave(points);
console.log(JSON.stringify(hull));
var map = L.map('map', {
center: [15, 25],
zoom: 3,
layers: [ L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png') ],
});
L.geoJSON(hull).addTo(map);