From cee62cea70912b7ed13ebb2819d966e919a88e12 Mon Sep 17 00:00:00 2001 From: elias couppe Date: Fri, 29 Nov 2024 16:16:30 +0100 Subject: [PATCH] fix(elevation): profil en boucle est bien rendu --- src/OpenLayers/Controls/ElevationPath.js | 51 +++++------------------- 1 file changed, 10 insertions(+), 41 deletions(-) diff --git a/src/OpenLayers/Controls/ElevationPath.js b/src/OpenLayers/Controls/ElevationPath.js index 9ccacd052..386e872b3 100644 --- a/src/OpenLayers/Controls/ElevationPath.js +++ b/src/OpenLayers/Controls/ElevationPath.js @@ -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 }); } @@ -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; @@ -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; @@ -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;