根据中心位置移动多边形点?

xsp*_*ydr 3 turfjs

有人有一个使用 Turf 根据新中心点将所有多边形点从一个位置移动到另一个位置的示例吗?

\n\n

例如,让\xe2\x80\x99s 说我已经根据最初创建点的位置计算了一个中心。

\n\n

然后我需要根据计算出的中心将这些点移动到新位置。

\n\n

一如既往,任何帮助都会很棒!

\n

Ana*_*nov 6

您需要使用transformTranslate

var poly = turf.polygon([[[0,29], [3.5,29], [2.5,32], [0,29]]]);

//calculates the centroid of the polygon
var center = turf.centroid(poly);

var from = turf.point([center.geometry.coordinates[0], center.geometry.coordinates[1]]);

var to = turf.point([4, 35]);

//finds the bearing angle between the points
var bearing = turf.rhumbBearing(from, to);

//calculates the distance between the points
var distance = turf.rhumbDistance(from, to);

//moves the polygon to the distance on the direction angle.
var translatedPoly = turf.transformTranslate(poly, distance, bearing)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述