Merge pull request #1788 from twpayne/interpolate-m
getCoordinateAtM for MultiLineStrings
This commit is contained in:
@@ -310,16 +310,13 @@ ol.geom.flat.lineStringInterpolate =
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||
* @param {number} m M.
|
||||
* @param {boolean} extrapolate Extrapolate.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
ol.geom.flat.lineStringCoordinateAtM =
|
||||
function(flatCoordinates, offset, end, stride, layout, m, extrapolate) {
|
||||
if ((layout != ol.geom.GeometryLayout.XYM &&
|
||||
layout != ol.geom.GeometryLayout.XYZM) ||
|
||||
end == offset) {
|
||||
function(flatCoordinates, offset, end, stride, m, extrapolate) {
|
||||
if (end == offset) {
|
||||
return null;
|
||||
}
|
||||
var coordinate;
|
||||
@@ -374,6 +371,60 @@ ol.geom.flat.lineStringCoordinateAtM =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array.<number>} ends Ends.
|
||||
* @param {number} stride Stride.
|
||||
* @param {number} m M.
|
||||
* @param {boolean} extrapolate Extrapolate.
|
||||
* @param {boolean} interpolate Interpolate.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
ol.geom.flat.lineStringsCoordinateAtM = function(
|
||||
flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) {
|
||||
if (interpolate) {
|
||||
return ol.geom.flat.lineStringCoordinateAtM(
|
||||
flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate);
|
||||
}
|
||||
var coordinate;
|
||||
if (m < flatCoordinates[stride - 1]) {
|
||||
if (extrapolate) {
|
||||
coordinate = flatCoordinates.slice(0, stride);
|
||||
coordinate[stride - 1] = m;
|
||||
return coordinate;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (flatCoordinates[flatCoordinates.length - 1] < m) {
|
||||
if (extrapolate) {
|
||||
coordinate = flatCoordinates.slice(flatCoordinates.length - stride);
|
||||
coordinate[stride - 1] = m;
|
||||
return coordinate;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var i, ii;
|
||||
for (i = 0, ii = ends.length; i < ii; ++i) {
|
||||
var end = ends[i];
|
||||
if (offset == end) {
|
||||
continue;
|
||||
}
|
||||
if (m < flatCoordinates[offset + stride - 1]) {
|
||||
return null;
|
||||
} else if (m <= flatCoordinates[end - 1]) {
|
||||
return ol.geom.flat.lineStringCoordinateAtM(
|
||||
flatCoordinates, offset, end, stride, m, false);
|
||||
}
|
||||
offset = end;
|
||||
}
|
||||
goog.asserts.fail();
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {number} offset Offset.
|
||||
|
||||
@@ -81,14 +81,26 @@ ol.geom.LineString.prototype.closestPointXY =
|
||||
|
||||
|
||||
/**
|
||||
* Returns the coordinate at `m` using linear interpolation, or `null` if no
|
||||
* such coordinate exists.
|
||||
*
|
||||
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the
|
||||
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
|
||||
* M will return the first coordinate and Ms greater than the last M will
|
||||
* return the last coordinate.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) {
|
||||
if (this.layout != ol.geom.GeometryLayout.XYM &&
|
||||
this.layout != ol.geom.GeometryLayout.XYZM) {
|
||||
return null;
|
||||
}
|
||||
var extrapolate = goog.isDef(opt_extrapolate) ? opt_extrapolate : false;
|
||||
return ol.geom.flat.lineStringCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.flatCoordinates.length, this.stride, this.layout, m, extrapolate);
|
||||
this.flatCoordinates.length, this.stride, m, extrapolate);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@exportSymbol ol.geom.MultiLineString
|
||||
@exportProperty ol.geom.MultiLineString.prototype.clone
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getCoordinateAtM
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getCoordinates
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getLineStrings
|
||||
@exportProperty ol.geom.MultiLineString.prototype.getType
|
||||
|
||||
@@ -78,6 +78,41 @@ ol.geom.MultiLineString.prototype.closestPointXY =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the coordinate at `m` using linear interpolation, or `null` if no
|
||||
* such coordinate exists.
|
||||
*
|
||||
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the
|
||||
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
|
||||
* M will return the first coordinate and Ms greater than the last M will
|
||||
* return the last coordinate.
|
||||
*
|
||||
* `opt_interpolate` controls interpolation between consecutive LineStrings
|
||||
* within the MultiLineString. If `opt_interpolate` is `true` the coordinates
|
||||
* will be linearly interpolated between the last coordinate of one LineString
|
||||
* and the first coordinate of the next LineString. If `opt_interpolate` is
|
||||
* `false` then the function will return `null` for Ms falling between
|
||||
* LineStrings.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate.
|
||||
* @param {boolean=} opt_interpolate Interpolate.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getCoordinateAtM =
|
||||
function(m, opt_extrapolate, opt_interpolate) {
|
||||
if ((this.layout != ol.geom.GeometryLayout.XYM &&
|
||||
this.layout != ol.geom.GeometryLayout.XYZM) ||
|
||||
this.flatCoordinates.length === 0) {
|
||||
return null;
|
||||
}
|
||||
var extrapolate = goog.isDef(opt_extrapolate) ? opt_extrapolate : false;
|
||||
var interpolate = goog.isDef(opt_interpolate) ? opt_interpolate : false;
|
||||
return ol.geom.flat.lineStringsCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.ends_, this.stride, m, extrapolate, interpolate);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.geom.RawMultiLineString} Coordinates.
|
||||
* @todo stability experimental
|
||||
|
||||
Reference in New Issue
Block a user