I need to allow user to draw a route (using polyline) with specified road radius (visually it was done with "weight" parameter).
Visually it looks like that:
So I'm wondering how can build a polygon around this polyline with some offset? Like this:
Finally I made it with JSTS library (https://www.npmjs.com/package/jsts).
It's easy:
//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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With