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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user