Merge pull request #1783 from twpayne/first-last-coordinate

Get first and last coordinate
This commit is contained in:
Tom Payne
2014-02-28 17:34:13 +01:00
3 changed files with 34 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
@exportSymbol ol.geom.SimpleGeometry
@exportProperty ol.geom.SimpleGeometry.prototype.getExtent
@exportProperty ol.geom.SimpleGeometry.prototype.getFirstCoordinate
@exportProperty ol.geom.SimpleGeometry.prototype.getLastCoordinate
@exportProperty ol.geom.SimpleGeometry.prototype.getLayout
@exportProperty ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry
@exportProperty ol.geom.SimpleGeometry.prototype.transform

View File

@@ -99,6 +99,14 @@ ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) {
};
/**
* @return {ol.Coordinate} First coordinate.
*/
ol.geom.SimpleGeometry.prototype.getFirstCoordinate = function() {
return this.flatCoordinates.slice(0, this.stride);
};
/**
* @return {Array.<number>} Flat coordinates.
*/
@@ -107,6 +115,14 @@ ol.geom.SimpleGeometry.prototype.getFlatCoordinates = function() {
};
/**
* @return {ol.Coordinate} Last point.
*/
ol.geom.SimpleGeometry.prototype.getLastCoordinate = function() {
return this.flatCoordinates.slice(this.flatCoordinates.length - this.stride);
};
/**
* @return {ol.geom.GeometryLayout} Layout.
* @todo stability experimental

View File

@@ -164,6 +164,14 @@ describe('ol.geom.LineString', function() {
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
});
describe('#getFirstCoordinate', function() {
it('returns the expected result', function() {
expect(lineString.getFirstCoordinate()).to.eql([0, 0]);
});
});
describe('#getFlatMidpoint', function() {
it('returns the expected result', function() {
@@ -176,6 +184,14 @@ describe('ol.geom.LineString', function() {
});
describe('#getLastCoordinate', function() {
it('returns the expected result', function() {
expect(lineString.getLastCoordinate()).to.eql([7, 5]);
});
});
describe('#getSimplifiedGeometry', function() {
it('returns the expectedResult', function() {