How to use @turf/transform-rotate - 4 common examples

To help you get started, we’ve selected a few @turf/transform-rotate 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 / core / src / lib / layers / editable-geojson-layer.js View on Github external
mode: 'query',
        layers: [this.props.id],
        radius: 100,
        viewports: [this.context.viewport]
      });
      // do nothing when mouse position far away from any point
      if (!picks || !picks.length || !picks[0].object.position) {
        return;
      }
      pivot = picks[0].object.position;
    } else {
      pivot = modeConfig.pivot;
    }
    const featureIndex = this.props.selectedFeatureIndexes[0];
    const feature = this.state.selectedFeatures[0];
    const rotatedFeature = turfTransformRotate(feature, 2, { pivot });

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

    this.props.onEdit({
      updatedData,
      editType: 'transformPosition',
      featureIndex,
      positionIndexes: this.props.positionIndexes,
      position: groundCoords
    });
  }
github w3reality / three-geo / src / Utils.js View on Github external
static rotateTurfObject(turfObj, deg, pivotLatlng, mutate=true) {
        return turfTransformRotate(turfObj, deg, {
                pivot: [pivotLatlng[1], pivotLatlng[0]],
                mutate: mutate,
            });
    }
github uber / nebula.gl / modules / layers / src / mode-handlers / rotate-handler.js View on Github external
getRotateAction(startDragPoint: Position, currentPoint: Position, editType: string): EditAction {
    const startPosition = startDragPoint;
    const centroid = turfCentroid(this._geometryBeingRotated);
    const angle = getRotationAngle(centroid, startPosition, currentPoint);

    const rotatedFeatures = turfTransformRotate(this._geometryBeingRotated, angle);

    let updatedData = this.getImmutableFeatureCollection();

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

    return {
      updatedData: updatedData.getObject(),
      editType,
      featureIndexes: selectedIndexes,
      editContext: null
    };
github Turfjs / turf / packages / turf-ellipse / index.js View on Github external
if (stepAngle < -90 && stepAngle >= -270) x = -x;
        if (stepAngle < -180 && stepAngle >= -360) y = -y;
        if (units === 'degrees') {
            var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
            var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
            x = newx;
            y = newy;
        }

        coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
    }
    coordinates.push(coordinates[0]);
    if (units === 'degrees') {
        return polygon([coordinates], properties);
    } else {
        return transformRotate(polygon([coordinates], properties), angle, { pivot: pivot });
    }
}

@turf/transform-rotate

turf transform-rotate module

MIT
Latest version published 3 years ago

Package Health Score

80 / 100
Full package analysis

Popular @turf/transform-rotate functions