How to use the @turf/along function in @turf/along

To help you get started, we’ve selected a few @turf/along examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FreemapSlovakia / freemap-v3-react / src / processors / elevationChartProcessor.ts View on Github external
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,
github ibi-group / datatools-ui / lib / editor / selectors / index.js View on Github external
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}
}
github ibi-group / datatools-ui / lib / editor / actions / map / stopStrategies.js View on Github external
// 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 => {
github FreemapSlovakia / freemap-v3-react / src / logic / elevationChartLogic.js View on Github external
function resolveElevationProfilePointsViaApi(
  trackGeojson,
  dispatch,
  cancelled$,
  storeDispatch,
  done,
) {
  const totalDistanceInKm = turfLength(trackGeojson);
  const delta = Math.min(0.1, totalDistanceInKm / (window.innerWidth / 2));
  const elevationProfilePoints = [];
  for (let dist = 0; dist <= totalDistanceInKm; dist += delta) {
    const [lon, lat] = getCoord(turfAlong(trackGeojson, dist));
    elevationProfilePoints.push({ lat, lon, distance: dist * 1000 });
  }

  const pid = Math.random();
  dispatch(startProgress(pid));
  const source = axios.CancelToken.source();
  cancelled$.subscribe(() => {
    source.cancel();
  });
  axios
    .post(
      `${process.env.API_URL}/geotools/elevation`,
      elevationProfilePoints.map(({ lat, lon }) => [lat, lon]),
      {
        validateStatus: status => status === 200,
        cancelToken: source.token,
github FreemapSlovakia / freemap-v3-react / src / components / RoutePlannerResult.tsx View on Github external
return [];
    }

    const points: [number, number][] = [];
    for (const step of alternatives[activeAlternativeIndex].itinerary) {
      points.push(
        ...step.shapePoints.map(([a, b]) => [b, a] as [number, number]),
      );
    }

    const line = lineString(points);
    const len = length(line);

    const milestones: Feature[] = [];
    for (let i = step; i < len; i += step) {
      milestones.push(along(line, i));
    }

    return milestones;
  }, [activeAlternativeIndex, alternatives, step, showMilestones]);
github sharedstreets / sharedstreets-road-closure-ui / src / selectors / road-closure-map.ts View on Github external
currentItem.features.forEach((feature: any) => {
        const featureLength = length(feature, {units: "meters"});
        const halfwayAlongFeature = along(feature, featureLength/2, {units: "meters"})
        halfwayAlongFeature.properties = {
            bearing: bearing(
                feature.geometry.coordinates[0],
                feature.geometry.coordinates[
                    feature.geometry.coordinates.length-1
                ]
            )
        };
        outputFeatures.push(
            halfwayAlongFeature  
        );
    });

@turf/along

turf along module

MIT
Latest version published 3 years ago

Package Health Score

80 / 100
Full package analysis

Popular @turf/along functions