How to use @turf/destination - 10 common examples

To help you get started, we’ve selected a few @turf/destination 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 uber / nebula.gl / modules / layers / src / mode-handlers / draw-90degree-polygon-handler.js View on Github external
[0, 1, 2].forEach(indexFirst => {
        const line1 = lineString([
          p1,
          destination(p1, distance, angles.first[indexFirst]).geometry.coordinates
        ]);
        [0, 1, 2].forEach(indexSecond => {
          const line2 = lineString([
            p3,
            destination(p3, distance, angles.second[indexSecond]).geometry.coordinates
          ]);
          const fc = lineIntersect(line1, line2);
          if (fc && fc.features.length) {
            // found the intersect point
            pt = fc.features[0].geometry.coordinates;
          }
        });
      });
    }
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
const ddistance = pointToLineDistance(pt, lineString, options);
      const lineBearing = bearing(p1, p2);

      // Check if current point is to the left or right of line
      // Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
      // then (x−x1)(y2−y1)−(y−y1)(x2−x1)
      const isPointToLeftOfLine =
        (groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);

      // Bearing to draw perpendicular to the line string
      const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;

      // Get coordinates for the point p3 and p4 which are perpendicular to the lineString
      // Add the distance as the current position moves away from the lineString
      const p3 = destination(p2, ddistance, orthogonalBearing, options);
      const p4 = destination(p1, ddistance, orthogonalBearing, options);

      this._setTentativeFeature({
        type: 'Feature',
        geometry: {
          type: 'Polygon',
          coordinates: [
            [
              // Draw a polygon containing all the points of the LineString,
              // then the points orthogonal to the lineString,
              // then back to the starting position
              ...lineString.coordinates,
              p3.geometry.coordinates,
              p4.geometry.coordinates,
              p1
            ]
          ]
github uber / nebula.gl / modules / core / src / lib / utils.js View on Github external
const pt = point(groundCoords);
  const ddistance = pointToLineDistance(pt, lineString);
  const lineBearing = bearing(p1, p2);

  // Check if current point is to the left or right of line
  // Line from A=(x1,y1) to B=(x2,y2) a point P=(x,y)
  // then (x−x1)(y2−y1)−(y−y1)(x2−x1)
  const isPointToLeftOfLine =
    (groundCoords[0] - p1[0]) * (p2[1] - p1[1]) - (groundCoords[1] - p1[1]) * (p2[0] - p1[0]);

  // Bearing to draw perpendicular to the line string
  const orthogonalBearing = isPointToLeftOfLine < 0 ? lineBearing - 90 : lineBearing - 270;

  // Get coordinates for the point p3 and p4 which are perpendicular to the lineString
  // Add the distance as the current position moves away from the lineString
  const p3 = destination(p2, ddistance, orthogonalBearing);
  const p4 = destination(p1, ddistance, orthogonalBearing);

  return [p3.geometry.coordinates, p4.geometry.coordinates];
}
github Turfjs / turf / packages / turf-nearest-point-on-line / index.ts View on Github external
flattenEach(lines, function (line: any) {
        var coords: any = getCoords(line);

        for (var i = 0; i < coords.length - 1; i++) {
            //start
            var start = point(coords[i]);
            start.properties.dist = distance(pt, start, options);
            //stop
            var stop = point(coords[i + 1]);
            stop.properties.dist = distance(pt, stop, options);
            // sectionLength
            var sectionLength = distance(start, stop, options);
            //perpendicular
            var heightDistance = Math.max(start.properties.dist, stop.properties.dist);
            var direction = bearing(start, stop);
            var perpendicularPt1 = destination(pt, heightDistance, direction + 90, options);
            var perpendicularPt2 = destination(pt, heightDistance, direction - 90, options);
            var intersect = lineIntersects(
                lineString([perpendicularPt1.geometry.coordinates, perpendicularPt2.geometry.coordinates]),
                lineString([start.geometry.coordinates, stop.geometry.coordinates])
            );
            var intersectPt = null;
            if (intersect.features.length > 0) {
                intersectPt = intersect.features[0];
                intersectPt.properties.dist = distance(pt, intersectPt, options);
                intersectPt.properties.location = length + distance(start, intersectPt, options);
            }

            if (start.properties.dist < closestPt.properties.dist) {
                closestPt = start;
                closestPt.properties.index = i;
                closestPt.properties.location = length;
github sharedstreets / sharedstreets-js / src / geom.ts View on Github external
export function envelopeBufferFromPoint(point, radius):turfHelpers.Feature {
    var nwPoint = destination(point, radius, 315, {'units':'meters'});
    var sePoint = destination(point, radius, 135, {'units':'meters'});
    return envelope(turfHelpers.featureCollection([nwPoint, sePoint]));
}
github sharedstreets / sharedstreets-js / src / geom.ts View on Github external
export function envelopeBufferFromPoint(point, radius):turfHelpers.Feature {
    var nwPoint = destination(point, radius, 315, {'units':'meters'});
    var sePoint = destination(point, radius, 135, {'units':'meters'});
    return envelope(turfHelpers.featureCollection([nwPoint, sePoint]));
}
github sharedstreets / sharedstreets-js / src / tiles.ts View on Github external
export function getTileIdsForPolygon(polygon:turfHelpers.Feature, buffer:number=0):string[] {

    var polyBound = bbox(polygon)

    var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'});
    var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'});
    let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]];
    
    return getTileIdsForBounds(bounds, false);
  
}
github Turfjs / turf / packages / turf-directional-mean / index.ts View on Github external
let endX: number;
        let endY: number;
        const r: number = angle * Math.PI / 180;
        const sin: number = Math.sin(r);
        const cos: number = Math.cos(r);
        beginX = averageX - lenOfLine / 2 * cos;
        beginY = averageY - lenOfLine / 2 * sin;
        endX = averageX + lenOfLine / 2 * cos;
        endY = averageY + lenOfLine / 2 * sin;
        return [
            [beginX, beginY],
            [endX, endY],
        ];
    } else {
        const end = destination(point(centroidOfLine), lenOfLine / 2, angle, { units: "meters" });
        const begin = destination(point(centroidOfLine), -lenOfLine / 2, angle, { units: "meters" });
        return [
            getCoord(begin), getCoord(end),
        ];
    }
}
github conveyal / analysis-ui / lib / components / map / edit-bounds.js View on Github external
function onGeocode(r) {
      if (r.bbox) {
        const [west, south, east, north] = r.bbox
        p.save({north, south, east, west})
      } else {
        const c1 = turfDestination(r.center, 5, 45)
        const c2 = turfDestination(r.center, 5, -135)
        const [east, north] = c1.geometry.coordinates
        const [west, south] = c2.geometry.coordinates
        const newBounds = {north, south, east, west}
        p.save(newBounds)
        p.leaflet.map.fitBounds(toLatLngBounds(newBounds))
      }
    }
github sharedstreets / sharedstreets-js / src / tiles.ts View on Github external
export function getTileIdsForPolygon(polygon:turfHelpers.Feature, buffer:number=0):string[] {

    var polyBound = bbox(polygon)

    var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'});
    var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'});
    let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]];
    
    return getTileIdsForBounds(bounds, false);
  
}

@turf/destination

turf destination module

MIT
Latest version published 3 years ago

Package Health Score

89 / 100
Full package analysis

Popular @turf/destination functions