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

Tweak range marker offset and route segments #223

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions src/smk/api/route-planner.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,23 @@ include.module( 'api.route-planner-js', [ 'jquery', 'util' ], function () {
data.segments = [];
var distanceKm = 0;
var routeIndex = 0;

// Capture the route segment where the range limit is reached
for (var i = 0; i < data.route.length + 1; i += 1) {
for (var i = 0; i < (data.route.length - 1); i += 1) {
distanceKm += turf.distance(data.route[i], data.route[i+1], {units: "kilometers"});
if (distanceKm >= option.rangeKm) {
data.rangeLimit = data.route[i];
routeIndex = i;
if (distanceKm >= option.rangeKm && i > 0) {
data.rangeLimit = data.route[i - 1];
routeIndex = i - 1;
break;
}
}

// Add two segments - one before the range limit is reached, one after
data.segments.push(turf.lineString(data.route.slice(0, routeIndex), { index: 0 }));
data.segments.push(turf.lineString(data.route.slice(routeIndex), { index: 1, "@layer": "@segments-after-range-limit" }));
// If rangeKm is close enough to data.distance, we may not hit the break above and routeIndex will remain 0
if (routeIndex === 0) {
data.segments = [turf.lineString(data.route, { index: 0 })];
} else {
// Add two segments - one before the range limit is reached, one after
data.segments.push(turf.lineString(data.route.slice(0, routeIndex), { index: 0 }));
data.segments.push(turf.lineString(data.route.slice(routeIndex), { index: 1, "@layer": "@segments-after-range-limit" }));
}
} else {
data.segments = [ turf.lineString( data.route, { index: 0 } ) ]
}
Expand Down
2 changes: 1 addition & 1 deletion src/smk/tool/directions/config/tool-directions-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ include.module( 'tool-directions-config', [
style: {
markerUrl: inc[ 'tool-directions-config.range-limit-png' ],
markerSize: [ 38, 42 ],
markerOffset: [ 19, 42 ],
markerOffset: [ 10, 42 ],
shadowUrl: inc[ 'tool-directions-config.range-limit-shadow-png' ],
shadowSize: [ 38, 42 ],
popupOffset: [ 1, -34 ]
Expand Down