I have a Leaflet LayerGroup that I add turf.buffers to like that:
const buffered = turf.buffer(trackAsJson, 0.5, {units: 'kilometers'});
After adding two tracks, the layer group looks like this:
{
type: "FeatureCollection",
features: Array(2)
}features: Array(2)0: geometry: {
type: "Polygon",
coordinates: Array(1)
}properties: {
name: "Track 1",
time: "2016-10-15T13:24:36.000Z"
}type: "Feature"__proto__: Object1: geometry: {
type: "Polygon",
coordinates: Array(1)
}properties: {
name: "Track 2",
time: "2018-02-17T09:58:32.000Z"
}type: "Feature"__proto__: Objectlength: 2__proto__: Array(0)type: "FeatureCollection"__proto__: Object
Now, I'd like to create a union of this LayerGroup:
unify(buffers.getLayers());
private unify(polyList): L.GeoJSON {
let unionTemp: any;
for (let i = 0; i < polyList.length; i++) {
if (i === 0) {
unionTemp = polyList[i].toGeoJSON();
} else {
unionTemp = turf.union(unionTemp, polyList[i]);
}
}
return L.geoJSON(unionTemp);
}
However, when I do that, I get the following error:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
In the line
unionTemp = turf.union(unionTemp, polyList[i]);
I really don't understand why. Any hints would be welcome.