Add ol.geom.LineString#getSimplifiedGeometryInternal
This commit is contained in:
@@ -2,6 +2,7 @@ goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.simplify');
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +37,22 @@ ol.geom.LineString.prototype.getLength = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.LineString.prototype.getSimplifiedGeometryInternal =
|
||||
function(squaredTolerance) {
|
||||
var simplifiedFlatCoordinates = [];
|
||||
simplifiedFlatCoordinates.length = ol.geom.simplify.douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
var simplifiedLineString = new ol.geom.LineString(null);
|
||||
simplifiedLineString.setFlatCoordinates(
|
||||
ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates);
|
||||
return simplifiedLineString;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -156,6 +156,39 @@ describe('ol.geom.LineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('with a simple line string', function() {
|
||||
|
||||
var lineString;
|
||||
beforeEach(function() {
|
||||
lineString = new ol.geom.LineString(
|
||||
[[0, 0], [1, 1], [3, 3], [5, 1], [6, 3], [7, 5]]);
|
||||
});
|
||||
|
||||
describe('#getSimplifiedGeometry', function() {
|
||||
|
||||
it('returns the expectedResult', function() {
|
||||
var simplifiedGeometry = lineString.getSimplifiedGeometry(1);
|
||||
expect(simplifiedGeometry).to.be.an(ol.geom.LineString);
|
||||
expect(simplifiedGeometry.getCoordinates()).to.eql(
|
||||
[[0, 0], [3, 3], [5, 1], [7, 5]]);
|
||||
});
|
||||
|
||||
it('caches by resolution', function() {
|
||||
var simplifiedGeometry1 = lineString.getSimplifiedGeometry(1);
|
||||
var simplifiedGeometry2 = lineString.getSimplifiedGeometry(1);
|
||||
expect(simplifiedGeometry1).to.be(simplifiedGeometry2);
|
||||
});
|
||||
|
||||
it('invalidates the cache when the geometry changes', function() {
|
||||
var simplifiedGeometry1 = lineString.getSimplifiedGeometry(1);
|
||||
lineString.setCoordinates(lineString.getCoordinates());
|
||||
var simplifiedGeometry2 = lineString.getSimplifiedGeometry(1);
|
||||
expect(simplifiedGeometry1).not.to.be(simplifiedGeometry2);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user