[GIS] How to offset a polyline in Openlayers 3

geometryjts-topology-suiteopenlayers

I retrieve ways from OSM with Overpass API and display them in an Openlayers3 vector layer. In the case of a highway with a cycleway along it (e.g. cycleway:right=track) I want to draw a green line with a slight offset to the right of the original way, like on this raster image created with mapnik:

enter image description here

As there is no method in Openlayers I had a look at JSTS. Polyline buffering is coming close to what I am looking for:

var bufParams = new jsts.operation.buffer.BufferParameters();
bufParams.setSingleSided(true);
var jstsGeom = parser.read(feature.getGeometry());
var buffered = jstsGeom.buffer(2, bufParams);
feature.setGeometry(parser.write(buffered));  

enter image description here

What I need is a similar function which results in just one half of the buffer polygon. Is there anyway to do this with JSTS or any other javascript library?

Best Answer

you could use https://github.com/Turfjs/turf-cut to cut the buffered polygon with the original polyline.

EDIT

jsts implements single sided buffer: https://github.com/bjornharrtell/jsts/blob/master/src/org/locationtech/jts/operation/buffer/BufferParameters.js#L69 Setting a negative or positive buffer value you decide which side to buffer.

Related Question