Merge pull request #3343 from fredj/line-arrows

Line arrows example
This commit is contained in:
Frédéric Junod
2015-03-16 14:30:08 +01:00
5 changed files with 144 additions and 4 deletions

View File

@@ -9,20 +9,22 @@ goog.provide('ol.geom.flat.segments');
* @param {number} offset Offset.
* @param {number} end End.
* @param {number} stride Stride.
* @param {function(ol.Coordinate, ol.Coordinate): T} callback Function
* @param {function(this: S, ol.Coordinate, ol.Coordinate): T} callback Function
* called for each segment.
* @param {S=} opt_this The object to be used as the value of 'this'
* within callback.
* @return {T|boolean} Value.
* @template T
* @template T,S
*/
ol.geom.flat.segments.forEach =
function(flatCoordinates, offset, end, stride, callback) {
function(flatCoordinates, offset, end, stride, callback, opt_this) {
var point1 = [flatCoordinates[offset], flatCoordinates[offset + 1]];
var point2 = [];
var ret;
for (; (offset + stride) < end; offset += stride) {
point2[0] = flatCoordinates[offset + stride];
point2[1] = flatCoordinates[offset + stride + 1];
ret = callback(point1, point2);
ret = callback.call(opt_this, point1, point2);
if (ret) {
return ret;
}

View File

@@ -11,6 +11,7 @@ goog.require('ol.geom.flat.inflate');
goog.require('ol.geom.flat.interpolate');
goog.require('ol.geom.flat.intersectsextent');
goog.require('ol.geom.flat.length');
goog.require('ol.geom.flat.segments');
goog.require('ol.geom.flat.simplify');
@@ -107,6 +108,25 @@ ol.geom.LineString.prototype.closestPointXY =
};
/**
* Iterate over each segment, calling the provided callback.
* If the callback returns a truthy value the function returns that
* value immediately. Otherwise the function returns `false`.
*
* @param {function(this: S, ol.Coordinate, ol.Coordinate): T} callback Function
* called for each segment.
* @param {S=} opt_this The object to be used as the value of 'this'
* within callback.
* @return {T|boolean} Value.
* @template T,S
* @api
*/
ol.geom.LineString.prototype.forEachSegment = function(callback, opt_this) {
return ol.geom.flat.segments.forEach(this.flatCoordinates, 0,
this.flatCoordinates.length, this.stride, callback, opt_this);
};
/**
* Returns the coordinate at `m` using linear interpolation, or `null` if no
* such coordinate exists.