如何将带权重的折线转换为传单中的多边形?

Rus*_*lin 6 geometry routes polyline leaflet

我需要允许用户绘制具有指定道路半径的路线(使用折线)(视觉上它是用“重量”参数完成的)。

视觉上看起来是这样的:

在此处输入图片说明

所以我想知道如何围绕这条折线构建一个带有一些偏移的多边形?像这样:

在此处输入图片说明

Rus*_*lin 3

最后我用 JSTS 库( https://www.npmjs.com/package/jsts )做到了。

这很容易:

//pathCoords should be an array of jsts.geom.Coordinate
var pathCoords = [];
var geometryFactory = new jsts.geom.GeometryFactory();

// on what distance new polygon should be built
var distance = (meters * 0.0001) / 111.12;
var shell = geometryFactory.createLineString(pathCoords);

// building a new polygon
var polygon = shell.buffer(distance);

// finally get your new polygon coordinates
var polygonCoords = polygon.getCoordinates();
Run Code Online (Sandbox Code Playgroud)