How to use @turf/transform-translate - 3 common examples

To help you get started, we’ve selected a few @turf/transform-translate 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 w3reality / three-geo / src / Utils.js View on Github external
static translateTurfObject(turfObj, dx, dy, dz, unitsPerMeter, mutate=true) {
        const vec = new THREE.Vector2(dx, dy).divideScalar(unitsPerMeter);
        const theta = 90.0 - vec.angle() * 180.0 / Math.PI;
        return turfTransformTranslate(turfObj, vec.length(), theta, {
                units: 'meters',
                zTranslation: dz / unitsPerMeter,
                mutate: mutate, // "significant performance increase if true" per doc
            });
    }
    static rotateTurfObject(turfObj, deg, pivotLatlng, mutate=true) {
github uber / nebula.gl / modules / core / src / lib / layers / editable-geojson-layer.js View on Github external
handleTransformTranslate(
    screenCoords: Position,
    groundCoords: Position,
    pointerDownPicks: any[],
    distanceMoved: number
  ) {
    const featureIndex = this.props.selectedFeatureIndexes[0];
    const feature = this.state.selectedFeatures[0];
    const p1 = { x: screenCoords[0], y: screenCoords[1] };
    const p2 = { x: pointerDownPicks[0].x, y: pointerDownPicks[0].y };
    const angleFromNorth = (pointA, pointB) => {
      const angleFromWest = (Math.atan2(pointA.y - pointB.y, pointA.x - pointB.x) * 180) / Math.PI;
      return angleFromWest > 90 && angleFromWest < 180 ? angleFromWest - 90 : angleFromWest + 270;
    };
    const direction = angleFromNorth(p2, p1);
    const movedFeature = turfTransformTranslate(feature, distanceMoved, direction);

    const updatedData = this.state.editableFeatureCollection.featureCollection
      .replaceGeometry(featureIndex, movedFeature.geometry)
      .getObject();

    this.props.onEdit({
      updatedData,
      updatedMode: this.props.mode,
      updatedSelectedFeatureIndexes: this.props.selectedFeatureIndexes,
      editType: 'transformPosition',
      featureIndex,
      positionIndexes: this.props.positionIndexes,
      position: groundCoords
    });
  }
github uber / nebula.gl / modules / layers / src / mode-handlers / translate-handler.js View on Github external
getTranslateAction(
    startDragPoint: Position,
    currentPoint: Position,
    editType: string
  ): ?EditAction {
    if (!this._geometryBeforeTranslate) {
      return null;
    }
    const p1 = point(startDragPoint);
    const p2 = point(currentPoint);

    const distanceMoved = turfDistance(p1, p2);
    const direction = turfBearing(p1, p2);

    const movedFeatures = turfTransformTranslate(
      this._geometryBeforeTranslate,
      distanceMoved,
      direction
    );

    let updatedData = this.getImmutableFeatureCollection();

    const selectedIndexes = this.getSelectedFeatureIndexes();
    for (let i = 0; i < selectedIndexes.length; i++) {
      const selectedIndex = selectedIndexes[i];
      const movedFeature = movedFeatures.features[i];
      updatedData = updatedData.replaceGeometry(selectedIndex, movedFeature.geometry);
    }

    return {
      updatedData: updatedData.getObject(),

@turf/transform-translate

turf transform-translate module

MIT
Latest version published 4 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/transform-translate functions