add comments; clean up

This commit is contained in:
alexcojocaru 2020-10-25 20:11:33 -07:00
parent bd0679d15c
commit 75b68ebfe1

View file

@ -163,8 +163,12 @@ BR.Heightgraph = function(map, layersControl, routing, pois) {
// this is going to be initialized in the first iteration // this is going to be initialized in the first iteration
var currentFeature; var currentFeature;
// undefined is fine, as it will be different than the next gradient // undefined is fine, as it will be different than the current gradient
// in the first iteration
var previousGradient; var previousGradient;
// each feature starts with the last point on the previous feature;
// this will also take care of inserting the firstmost point
// (latLngs[0]) at position 0 into the first feature in the list
for (var i = 1; i < latLngs.length; i++) { for (var i = 1; i < latLngs.length; i++) {
var previousPoint = latLngs[i - 1]; var previousPoint = latLngs[i - 1];
var currentPoint = latLngs[i]; var currentPoint = latLngs[i];
@ -174,36 +178,30 @@ BR.Heightgraph = function(map, layersControl, routing, pois) {
var currentGradientPercentage = (altDelta * 100) / dist; var currentGradientPercentage = (altDelta * 100) / dist;
var currentGradient = dist == 0 ? 0 : this._mapGradient(currentGradientPercentage); var currentGradient = dist == 0 ? 0 : this._mapGradient(currentGradientPercentage);
// TODO // TODO
/* console.log(
console.log("gradient %:", currentGradientPercentage, 'gradient %:',
"; gradient level:", currentGradient, currentGradientPercentage,
"; dist:", dist, '; gradient level:',
"; alt:", altDelta, currentGradient,
"; previous point:", previousPoint.lng, previousPoint.lat, previousPoint.alt, '; dist:',
"; current point:", currentPoint.lng, currentPoint.lat, currentPoint.alt); dist,
*/ '; alt:',
altDelta,
var coordinate = [currentPoint.lng, currentPoint.lat, currentPoint.alt]; '; previous point:',
previousPoint.lng,
previousPoint.lat,
previousPoint.alt,
'; current point:',
currentPoint.lng,
currentPoint.lat,
currentPoint.alt
);
if (currentGradient == previousGradient) { if (currentGradient == previousGradient) {
var coordinate = [currentPoint.lng, currentPoint.lat, currentPoint.alt];
currentFeature.geometry.coordinates.push(coordinate); currentFeature.geometry.coordinates.push(coordinate);
} else { } else {
currentFeature = { currentFeature = this._buildFeature(previousPoint, currentPoint, currentGradient);
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [
// each feature starts with the last point on the previous feature;
// that will also take care of inserting the firstmost point
// (latLngs[0]) at position 0 into the first feature in the list
[previousPoint.lng, previousPoint.lat, previousPoint.alt],
coordinate
]
},
properties: {
attributeType: currentGradient
}
};
features.push(currentFeature); features.push(currentFeature);
} }
@ -224,6 +222,19 @@ BR.Heightgraph = function(map, layersControl, routing, pois) {
]; ];
}, },
_buildFeature: function(point1, point2, gradient) {
return {
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [[point1.lng, point1.lat, point1.alt], [point2.lng, point2.lat, point2.alt]]
},
properties: {
attributeType: gradient
}
};
},
/** /**
* Map a gradient percentage to one of the levels defined * Map a gradient percentage to one of the levels defined
* in options.mappings.gradient. * in options.mappings.gradient.