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

Move polygon points based on center location?

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

例如,假设我根据最初创建点的位置计算了一个中心。

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

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

您需要使用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)