Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function resolveElevationProfilePointsViaApi(
getState,
trackGeojson,
dispatch: Dispatch,
) {
const totalDistanceInKm = turfLength(trackGeojson);
const delta = Math.min(0.1, totalDistanceInKm / (window.innerWidth / 2));
const elevationProfilePoints: {
lat: number;
lon: number;
ele: number;
distance: number;
}[] = [];
for (let dist = 0; dist <= totalDistanceInKm; dist += delta) {
const [lon, lat] = getCoord(turfAlong(trackGeojson, dist));
elevationProfilePoints.push({
lat,
lon,
distance: dist * 1000,
ele: Number.NaN, // will be filled later
});
}
const { data } = await httpRequest({
getState,
method: 'POST',
url: '/geotools/elevation',
data: elevationProfilePoints.map(({ lat, lon }) => [lat, lon]),
expectedStatus: 200,
cancelActions: [
elevationChartSetTrackGeojson,
export function sliceAtPoint (
line: GeoJsonLinestring,
beginPoint: GeoJsonPoint,
alongPoint: ?GeoJsonPoint = null,
lengthInMeters: number = 0
) {
if (!alongPoint && !lengthInMeters && lengthInMeters !== 0) {
throw new Error(
'Must provide alongPoint argument or positive number for lengthInMeters'
)
} else if (!alongPoint) {
alongPoint = along(line, lengthInMeters, {units: 'meters'})
}
const lineSegment: GeoJsonLinestring = lineSlice(beginPoint, alongPoint, line)
// measure line segment
const distance: number = lineDistance(lineSegment, 'meters')
const index = lineSegment.geometry.coordinates.length
return {distance, index, alongPoint, lineSegment}
}
// skip vertex if incidentStreets tags highway !== primary or secondary
// else if (toVertex) {
//
// }
// modify location according to distanceFromIntersection and before/after
const start = afterIntersection
? constructPoint(feature.geometry.coordinates[feature.geometry.coordinates.length - 1])
: constructPoint(shape.coordinates[0])
const end = afterIntersection
? constructPoint(shape.coordinates[shape.coordinates.length - 1])
: constructPoint(feature.geometry.coordinates[feature.geometry.coordinates.length - 1])
// TODO-lineSlice: refactor below code to use only relevant section of shape with lineSlice
// the current code may have undesired results in cases where the shape overlaps itself
const lineFromPoint = lineSlice(start, end, {type: 'Feature', geometry: shape})
const stopLocation = along(lineFromPoint, distanceFromIntersection / 1000, {units: 'kilometers'})
const latlng = ll.toLeaflet(stopLocation.geometry.coordinates)
// const {afterIntersection, intersectionStep, distanceFromIntersection} = getState().editor.editSettings.present
return dispatch(addStopAtPoint(latlng, false, patternStops.length, activePattern))
}))
.then(stops => {
function getUnitAnchors(street_feature, bounding_box, unit_options) {
let unit_anchors = [],
unit_length = unit_options.length / 1000, //Kilometers.
unit_buffer = unit_options.side_buffer / 1000, //Distance between units, kilometers.
endpoint = street_feature.geometry.coordinates[street_feature.geometry.coordinates.length - 1],
start_anchor = along(street_feature, 0),
end_anchor = along(street_feature, unit_length),
distance_along = unit_length;
while (end_anchor.geometry.coordinates != endpoint) {
//Exclude proposed anchors if they're outside of the bounding box.
start_coord = L.A.reversedCoordinates(start_anchor.geometry.coordinates),
end_coord = L.A.reversedCoordinates(end_anchor.geometry.coordinates);
if (L.latLngBounds(bounding_box).contains(start_coord) &&
L.latLngBounds(bounding_box).contains(end_coord)) {
unit_anchors.push([start_anchor, end_anchor]);
}
//Find next pair of anchors.
start_anchor = along(street_feature, distance_along + unit_buffer);
end_anchor = along(street_feature, distance_along + unit_buffer + unit_length);
endpoint = street_feature.geometry.coordinates[street_feature.geometry.coordinates.length - 1],
start_anchor = along(street_feature, 0),
end_anchor = along(street_feature, unit_length),
distance_along = unit_length;
while (end_anchor.geometry.coordinates != endpoint) {
//Exclude proposed anchors if they're outside of the bounding box.
start_coord = L.A.reversedCoordinates(start_anchor.geometry.coordinates),
end_coord = L.A.reversedCoordinates(end_anchor.geometry.coordinates);
if (L.latLngBounds(bounding_box).contains(start_coord) &&
L.latLngBounds(bounding_box).contains(end_coord)) {
unit_anchors.push([start_anchor, end_anchor]);
}
//Find next pair of anchors.
start_anchor = along(street_feature, distance_along + unit_buffer);
end_anchor = along(street_feature, distance_along + unit_buffer + unit_length);
distance_along += unit_buffer + unit_length
}
return unit_anchors;
}
start_anchor = along(street_feature, 0),
end_anchor = along(street_feature, unit_length),
distance_along = unit_length;
while (end_anchor.geometry.coordinates != endpoint) {
//Exclude proposed anchors if they're outside of the bounding box.
start_coord = L.A.reversedCoordinates(start_anchor.geometry.coordinates),
end_coord = L.A.reversedCoordinates(end_anchor.geometry.coordinates);
if (L.latLngBounds(bounding_box).contains(start_coord) &&
L.latLngBounds(bounding_box).contains(end_coord)) {
unit_anchors.push([start_anchor, end_anchor]);
}
//Find next pair of anchors.
start_anchor = along(street_feature, distance_along + unit_buffer);
end_anchor = along(street_feature, distance_along + unit_buffer + unit_length);
distance_along += unit_buffer + unit_length;
}
return unit_anchors;
}
end_anchor = along(street_feature, unit_length),
distance_along = unit_length;
while (end_anchor.geometry.coordinates != endpoint) {
//Exclude proposed anchors if they're outside of the bounding box.
start_coord = L.A.reversedCoordinates(start_anchor.geometry.coordinates),
end_coord = L.A.reversedCoordinates(end_anchor.geometry.coordinates);
if (L.latLngBounds(bounding_box).contains(start_coord) &&
L.latLngBounds(bounding_box).contains(end_coord)) {
unit_anchors.push([start_anchor, end_anchor]);
}
//Find next pair of anchors.
start_anchor = along(street_feature, distance_along + unit_buffer);
end_anchor = along(street_feature, distance_along + unit_buffer + unit_length);
distance_along += unit_buffer + unit_length;
}
return unit_anchors;
}
function getUnitAnchors(street_feature, bounding_box, unit_options) {
let unit_anchors = [],
unit_length = unit_options.length / 1000, //Kilometers.
unit_buffer = unit_options.side_buffer / 1000, //Distance between units, kilometers.
endpoint = street_feature.geometry.coordinates[street_feature.geometry.coordinates.length - 1],
start_anchor = along(street_feature, 0),
end_anchor = along(street_feature, unit_length),
distance_along = unit_length;
while (end_anchor.geometry.coordinates != endpoint) {
//Exclude proposed anchors if they're outside of the bounding box.
start_coord = L.A.reversedCoordinates(start_anchor.geometry.coordinates),
end_coord = L.A.reversedCoordinates(end_anchor.geometry.coordinates);
if (L.latLngBounds(bounding_box).contains(start_coord) &&
L.latLngBounds(bounding_box).contains(end_coord)) {
unit_anchors.push([start_anchor, end_anchor]);
}
//Find next pair of anchors.
start_anchor = along(street_feature, distance_along + unit_buffer);
end_anchor = along(street_feature, distance_along + unit_buffer + unit_length);
distance_along += unit_buffer + unit_length
function getUnitAnchors(street_feature, bounding_box, unit_options) {
let unit_anchors = [],
unit_length = unit_options.length / 1000, //Kilometers.
unit_buffer = unit_options.side_buffer / 1000, //Distance between units, kilometers.
endpoint = street_feature.geometry.coordinates[street_feature.geometry.coordinates.length - 1],
start_anchor = along(street_feature, 0),
end_anchor = along(street_feature, unit_length),
distance_along = unit_length;
while (end_anchor.geometry.coordinates != endpoint) {
//Exclude proposed anchors if they're outside of the bounding box.
start_coord = L.A.reversedCoordinates(start_anchor.geometry.coordinates),
end_coord = L.A.reversedCoordinates(end_anchor.geometry.coordinates);
if (L.latLngBounds(bounding_box).contains(start_coord) &&
L.latLngBounds(bounding_box).contains(end_coord)) {
unit_anchors.push([start_anchor, end_anchor]);
}
//Find next pair of anchors.
start_anchor = along(street_feature, distance_along + unit_buffer);
end_anchor = along(street_feature, distance_along + unit_buffer + unit_length);
start_anchor = along(street_feature, 0),
end_anchor = along(street_feature, unit_length),
distance_along = unit_length;
while (end_anchor.geometry.coordinates != endpoint) {
//Exclude proposed anchors if they're outside of the bounding box.
start_coord = L.A.reversedCoordinates(start_anchor.geometry.coordinates),
end_coord = L.A.reversedCoordinates(end_anchor.geometry.coordinates);
if (L.latLngBounds(bounding_box).contains(start_coord) &&
L.latLngBounds(bounding_box).contains(end_coord)) {
unit_anchors.push([start_anchor, end_anchor]);
}
//Find next pair of anchors.
start_anchor = along(street_feature, distance_along + unit_buffer);
end_anchor = along(street_feature, distance_along + unit_buffer + unit_length);
distance_along += unit_buffer + unit_length
}
return unit_anchors;
}