Add transform method to geometries

In the typical sequence of parse-transform-render the most efficient place to transform coordinate values is deep within the parser immediately after values have been read (this would avoid a second pass over whatever structure is used to back geometries).  To accomplish this transform during parsing, we could add back parser read options to pass the transform function around.

Until then, a transform method on geometries is straightforward to implement.  This means we do a second pass through coordinate structures to transform, but this is typically done only once immediately after parsing.
This commit is contained in:
Tim Schaub
2013-09-25 15:59:21 +02:00
parent e1ba1d8887
commit 33457c48de
9 changed files with 192 additions and 0 deletions

View File

@@ -112,3 +112,18 @@ ol.geom.LineString.prototype.distanceFromCoordinate = function(coordinate) {
}
return Math.sqrt(dist2);
};
/**
* @inheritDoc
*/
ol.geom.LineString.prototype.transform = function(transform) {
var coordinates = this.getCoordinates();
var dimension = this.dimension;
var coord;
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
coord = coordinates[i];
transform(coord, coord, dimension);
}
this.bounds_ = null;
};