Closed bsudekum closed 8 years ago
Instead of duplicating code for handling various geometry types, write a recursive function.
function addLayers(geojson, layers) {
switch (geojson.type) {
case 'FeatureCollection':
geojson.features.forEach(function (feature) { addLayers(feature, layers); });
case 'Feature':
switch (geojson.geometry.type) {
case 'LineString':
layers.push(makeLayer(geojson, 'LineString'));
break;
case 'Polygon': ...
layers.push(makeLayer(geojson, 'LineString'));
layers.push(makeLayer(geojson, 'Polygon'));
break;
default: throw new Error("unknown or unsupported GeoJSON geometry type");
}
default: throw new Error("unknown or unsupported GeoJSON type");
}
}
This will also handle nested FeatureCollections.
@jfirebaugh Updated with a cleaner code path
Closes: https://github.com/mapbox/simplespec-to-gl-style/issues/1
Accounts for a single geojson feature and also featureCollections.
/cc @jfirebaugh for :eyes: