Skip to content

Instantly share code, notes, and snippets.

@Kenny806
Kenny806 / splitLine.js
Last active October 7, 2021 11:47
A script that splits an ol3 LineString geometry into n segments of the same length, creates a point geometry at each split point and returns an array of the point geometries.
/**
* Accepts an ol.geom.LineString instance and a number (the desired number of segments) as parameters
*/
var splitLineString = function(geometry, n) {
var splitPoints = new Array(n);
var coords = geometry.getCoordinates();
var coordIndex = 0;
var startPoint = coords[coordIndex];
var nextPoint = coords[coordIndex + 1];
var segmentLength = geometry.getLength() / n;