Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
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
});
}
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(),