sparc-commons
Advanced tools
Comparing version 0.1.8 to 0.1.9
var es = exports, | ||
_ = require('lodash'); | ||
var asCategoryFeatures = es.asCategoryFeatures = function(route, categories){ | ||
function createFeature(mode){ | ||
return { | ||
type: "Feature", | ||
geometry: { | ||
type: "LineString", | ||
coordinates: [] | ||
}, | ||
properties: { | ||
category: _.findKey(categories, {mode: mode}), | ||
mode: mode, | ||
routepoints: [] | ||
} | ||
} | ||
} | ||
return _.reduce(route.events, function(repr, event){ | ||
var feature; | ||
if(_.isEmpty(repr.features)){ | ||
feature = createFeature(event.properties.mode) | ||
} else { | ||
feature = repr.features.pop() | ||
} | ||
//We populate features | ||
var mode = event.properties.mode | ||
if(mode !== feature.properties.mode){ | ||
//The point has a different category than the previous points. We create a new feature | ||
// TODO why? | ||
if(feature.geometry.coordinates.length <= 1){ | ||
feature.geometry.type = "Point" | ||
feature.geometry.coordinates = _.flatten(feature.geometry.coordinates) | ||
} | ||
repr.features.push(feature) | ||
feature = createFeature(event.properties.mode) | ||
} | ||
feature.geometry.coordinates.push(event.geometry.coordinates) | ||
feature.properties.routepoints.push(event.properties) | ||
repr.features.push(feature) | ||
return repr | ||
}, { | ||
type: "FeatureCollection", | ||
features: [], | ||
properties: _.omit(route.getFields(), ['events']) | ||
}) | ||
} | ||
var coordIdx = es.coordIdx = function coordIdx(lonLat, feature){ | ||
@@ -5,0 +52,0 @@ var idx = _.findIndex(feature.geometry.coordinates, function(coord){ |
{ | ||
"name": "sparc-commons", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Library with all small time common stuff used across the SPARC echosystem", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43442
979
0