añadido proporcionalidad en alturas y distancias de las elevacines con respecto el punto anterior

This commit is contained in:
2026-07-15 11:52:25 +02:00
parent ba502e8ebf
commit c3cbec3523
4 changed files with 65 additions and 21 deletions

View File

@@ -1084,7 +1084,7 @@ public partial class PlanificadorRutas : ComponentBase
if (string.IsNullOrWhiteSpace(_callejeroOrigenResumenRuta))
return string.Empty;
return $"O callejero: {_callejeroOrigenResumenRuta}";
return $"O: {_callejeroOrigenResumenRuta}";
}
private string FormatearResumenCallejeroDestino()
@@ -1092,7 +1092,7 @@ public partial class PlanificadorRutas : ComponentBase
if (string.IsNullOrWhiteSpace(_callejeroDestinoResumenRuta))
return string.Empty;
return $"D callejero: {_callejeroDestinoResumenRuta}";
return $"D: {_callejeroDestinoResumenRuta}";
}
private static string FormatearLugarCallejeroResumen(LugarGeocodificadoCercano? cercano)

View File

@@ -1181,7 +1181,7 @@ public partial class PlanificadorRutas : ComponentBase
private bool _elevPopupMinimizado = false;
private const string _versionApp = "(v-20260714a)";
private const string _versionApp = "(v-20260715a)";
private double? _paradaElevG;

View File

@@ -216,7 +216,8 @@ public partial class PlanificadorRutas : ComponentBase
category = categoria,
slope = pendiente,
distance = distancia,
elevation = elevActual,
elevationStart = elevAnterior,
elevationEnd = elevActual,
label = pendiente is null
? "-"
: pendiente.Value.ToString("+0.0;-0.0;0.0", CultureInfo.InvariantCulture) + " %"

View File

@@ -161,6 +161,59 @@ window.rt.drawRoute = function (id, coords, options) {
if (elevationSegments.length > 0 && coords && coords.length >= 2) {
const group = window.L.layerGroup();
const progressAlongSegment = function (segmentCoords, latlng) {
if (!latlng || !Array.isArray(segmentCoords) || segmentCoords.length < 2) return 0.5;
const start = segmentCoords[0];
const end = segmentCoords[segmentCoords.length - 1];
const startLat = Number(start && start[0]);
const startLon = Number(start && start[1]);
const endLat = Number(end && end[0]);
const endLon = Number(end && end[1]);
if (![startLat, startLon, endLat, endLon, latlng.lat, latlng.lng].every(Number.isFinite))
return 0.5;
const lonScale = Math.cos(((startLat + endLat) / 2) * Math.PI / 180);
const dx = (endLon - startLon) * lonScale;
const dy = endLat - startLat;
const px = (latlng.lng - startLon) * lonScale;
const py = latlng.lat - startLat;
const lengthSquared = dx * dx + dy * dy;
if (lengthSquared <= Number.EPSILON) return 0.5;
const progress = (px * dx + py * dy) / lengthSquared;
return Math.max(0, Math.min(1, progress));
};
const elevationTooltip = function (segment, progress) {
const t = Number.isFinite(progress) ? Math.max(0, Math.min(1, progress)) : 0.5;
const slope = segment && typeof segment.slope === "number" ? segment.slope : null;
const distance = segment && typeof segment.distance === "number" ? segment.distance : null;
const elevationStart = segment && typeof segment.elevationStart === "number" ? segment.elevationStart : null;
const elevationEnd = segment && typeof segment.elevationEnd === "number" ? segment.elevationEnd : null;
const slopeText = slope !== null && Number.isFinite(slope)
? ((slope > 0 ? "+" : "") + slope.toFixed(1) + " %")
: (segment && segment.label ? String(segment.label) : "-");
const distanceText = distance !== null && Number.isFinite(distance)
? (distance * t).toFixed(2) + " m"
: "-";
const estimatedElevation = elevationStart !== null && Number.isFinite(elevationStart) &&
elevationEnd !== null && Number.isFinite(elevationEnd)
? elevationStart + (elevationEnd - elevationStart) * t
: null;
const elevationText = estimatedElevation !== null
? estimatedElevation.toFixed(2) + " m"
: "-";
return [
"Pendiente: " + slopeText,
"Dist. anterior: " + distanceText,
"Altura: " + elevationText
].join("<br>");
};
elevationSegments.forEach(function (segment) {
const segmentCoords = segment && segment.coords;
if (!Array.isArray(segmentCoords) || segmentCoords.length < 2) return;
@@ -177,23 +230,7 @@ window.rt.drawRoute = function (id, coords, options) {
if (dashArray) segmentOpts.dashArray = dashArray;
const segmentLine = buildLine(segmentCoords, segmentOpts);
const slope = segment && typeof segment.slope === "number" ? segment.slope : null;
const distance = segment && typeof segment.distance === "number" ? segment.distance : null;
const elevation = segment && typeof segment.elevation === "number" ? segment.elevation : null;
const slopeText = slope !== null && Number.isFinite(slope)
? ((slope > 0 ? "+" : "") + slope.toFixed(1) + " %")
: (segment && segment.label ? String(segment.label) : "-");
const distanceText = distance !== null && Number.isFinite(distance)
? distance.toFixed(2) + " m"
: "-";
const elevationText = elevation !== null && Number.isFinite(elevation)
? elevation.toFixed(2) + " m"
: "-";
const label = [
"Pendiente: " + slopeText,
"Dist. anterior: " + distanceText,
"Altura: " + elevationText
].join("<br>");
const label = elevationTooltip(segment, 0.5);
if (label) {
segmentLine.bindTooltip(label, {
@@ -202,6 +239,12 @@ window.rt.drawRoute = function (id, coords, options) {
opacity: 0.92,
className: "rt-elev-tooltip"
});
const updateTooltipAtCursor = function (e) {
const progress = progressAlongSegment(segmentCoords, e && e.latlng);
segmentLine.setTooltipContent(elevationTooltip(segment, progress));
};
segmentLine.on("mouseover", updateTooltipAtCursor);
segmentLine.on("mousemove", updateTooltipAtCursor);
}
segmentLine.addTo(group);