Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elevation): correction du profil altimétrique en cas de boucle #384

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 10 additions & 41 deletions src/OpenLayers/Controls/ElevationPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -1336,27 +1336,11 @@ var ElevationPath = (function (Control) {

// le sampling est soit defini par l'utilisateur (opts),
// ou soit calculé dynamiquement...
var sampling = options.sampling;
if (!sampling) {
// computing sampling
var _sampling;
var _length = this._getLength();
logger.trace("length", _length);
var p = Math.max(50, Math.floor(_length) / 5); // en mètre sur un pas moyen de 5m !
if (p > 200) {
_sampling = 200;
} else {
_sampling = Math.floor(p);
}
var pointNumber = this._getSketchCoords().length;
if (pointNumber > 100) {
_sampling = 0;
}
}
var sampling = options.sampling || 200;

if (_sampling > 0) {
if (sampling > 0) {
Utils.mergeParams(options, {
sampling : _sampling
sampling : sampling
});
}

Expand Down Expand Up @@ -1396,11 +1380,6 @@ var ElevationPath = (function (Control) {
if (!_sketchPoints) {
return;
}
// section actuelle du sketch sur laquelle on est
var _currentSection = 0;
// longueur cumulée des sections précédentes
var _previousSectionsLength = 0;
var _nextSectionBegining = _sketchPoints[1];

// Calcul de la distance au départ pour chaque point + arrondi des lat/lon
_data[0].dist = 0;
Expand All @@ -1419,18 +1398,8 @@ var ElevationPath = (function (Control) {

for (var i = 1; i < _data.length; i++) {
var a = [_data[i].lon, _data[i].lat];
var distanceToStart = _previousSectionsLength + olGetDistanceSphere(a, _sketchPoints[_currentSection]);
var dist = distanceToStart - _distance;

// Changement de section
if (a[0] === _nextSectionBegining[0] && a[1] === _nextSectionBegining[1]) {
_currentSection++;
_previousSectionsLength = distanceToStart;
// Pas de next section si on est sur le dernier point
if (i !== _data.length - 1) {
_nextSectionBegining = _sketchPoints[_currentSection + 1];
}
}
var distanceToPrevious = olGetDistanceSphere(a, [_data[i-1].lon, _data[i-1].lat]);
var dist = distanceToPrevious + _distance;

var za = _data[i].z;
var zb = _data[i - 1].z;
Expand All @@ -1442,16 +1411,16 @@ var ElevationPath = (function (Control) {
}
var slope = za - zb;
if (slope < 0) {
_distanceMinus += dist;
_distanceMinus += distanceToPrevious;
_descendingElevation += slope;
} else if (slope > 0) {
_distancePlus += dist;
_distancePlus += distanceToPrevious;
_ascendingElevation += slope;
}
_distance = distanceToStart;
_data[i].dist = distanceToStart;
_distance = dist;
_data[i].dist = dist;

distances.push(distanceToStart);
distances.push(_distance);

_slopes += (slope) ? Math.abs(Math.round(slope / dist * 100)) : 0;
_data[i].slope = (slope) ? Math.abs(Math.round(slope / dist * 100)) : 0;
Expand Down
Loading