Factor out ol.geom.SimpleGeometry
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
@exportSymbol ol.geom.Geometry
|
||||
@exportProperty ol.geom.Geometry.prototype.getClosestPoint
|
||||
@exportProperty ol.geom.Geometry.prototype.getExtent
|
||||
@exportProperty ol.geom.Geometry.prototype.getLayout
|
||||
@exportProperty ol.geom.Geometry.prototype.getSimplifiedGeometry
|
||||
@exportProperty ol.geom.Geometry.prototype.transform
|
||||
@exportProperty ol.geom.Geometry.prototype.getType
|
||||
|
||||
@@ -5,10 +5,7 @@ goog.provide('ol.geom.Geometry');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Observable');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.flat');
|
||||
|
||||
|
||||
/**
|
||||
@@ -45,24 +42,6 @@ ol.geom.Geometry = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.geom.GeometryLayout}
|
||||
*/
|
||||
this.layout = ol.geom.GeometryLayout.XY;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.stride = 2;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.flatCoordinates = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
@@ -82,22 +61,22 @@ ol.geom.Geometry = function() {
|
||||
this.extentRevision = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
* @type {Object.<string, ol.geom.Geometry>}
|
||||
*/
|
||||
this.simplifiedGeometryCache_ = {};
|
||||
this.simplifiedGeometryCache = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance_ = 0;
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.simplifiedGeometryRevision_ = 0;
|
||||
this.simplifiedGeometryRevision = 0;
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.Geometry, ol.Observable);
|
||||
@@ -126,44 +105,6 @@ ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} stride Stride.
|
||||
* @private
|
||||
* @return {ol.geom.GeometryLayout} layout Layout.
|
||||
*/
|
||||
ol.geom.Geometry.getLayoutForStride_ = function(stride) {
|
||||
if (stride == 2) {
|
||||
return ol.geom.GeometryLayout.XY;
|
||||
} else if (stride == 3) {
|
||||
return ol.geom.GeometryLayout.XYZ;
|
||||
} else if (stride == 4) {
|
||||
return ol.geom.GeometryLayout.XYZM;
|
||||
} else {
|
||||
throw new Error('unsupported stride: ' + stride);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||
* @private
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
ol.geom.Geometry.getStrideForLayout_ = function(layout) {
|
||||
if (layout == ol.geom.GeometryLayout.XY) {
|
||||
return 2;
|
||||
} else if (layout == ol.geom.GeometryLayout.XYZ) {
|
||||
return 3;
|
||||
} else if (layout == ol.geom.GeometryLayout.XYM) {
|
||||
return 3;
|
||||
} else if (layout == ol.geom.GeometryLayout.XYZM) {
|
||||
return 4;
|
||||
} else {
|
||||
throw new Error('unsupported layout: ' + layout);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Contains coordinate.
|
||||
@@ -194,31 +135,7 @@ ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
|
||||
* @param {ol.Extent=} opt_extent Extent.
|
||||
* @return {ol.Extent} extent Extent.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.revision) {
|
||||
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
|
||||
this.flatCoordinates, this.stride, this.extent);
|
||||
this.extentRevision = this.revision;
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getFlatCoordinates = function() {
|
||||
return this.flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.geom.GeometryLayout} Layout.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getLayout = function() {
|
||||
return this.layout;
|
||||
};
|
||||
ol.geom.Geometry.prototype.getExtent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
@@ -233,60 +150,7 @@ ol.geom.Geometry.prototype.getRevision = function() {
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {ol.geom.Geometry} Simplified geometry.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision_ != this.revision) {
|
||||
goog.object.clear(this.simplifiedGeometryCache_);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance_ = 0;
|
||||
this.simplifiedGeometryRevision_ = this.revision;
|
||||
}
|
||||
// If squaredTolerance is negative or if we know that simplification will not
|
||||
// have any effect then just return this.
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance_ !== 0 &&
|
||||
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance_)) {
|
||||
return this;
|
||||
}
|
||||
var key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache_.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache_[key];
|
||||
} else {
|
||||
var simplifiedGeometry =
|
||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||
var simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||
this.simplifiedGeometryCache_[key] = simplifiedGeometry;
|
||||
return simplifiedGeometry;
|
||||
} else {
|
||||
// Simplification did not actually remove any coordinates. We now know
|
||||
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
||||
// than or equal to the current squaredTolerance will also not have any
|
||||
// effect. This allows us to short circuit simplification (saving CPU
|
||||
// cycles) and prevents the cache of simplified geometries from filling
|
||||
// up with useless identical copies of this geometry (saving memory).
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance_ = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {ol.geom.Geometry} Simplified geometry.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getSimplifiedGeometryInternal =
|
||||
function(squaredTolerance) {
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getStride = function() {
|
||||
return this.stride;
|
||||
};
|
||||
ol.geom.Geometry.prototype.getSimplifiedGeometry = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
@@ -295,59 +159,10 @@ ol.geom.Geometry.prototype.getStride = function() {
|
||||
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.Geometry.prototype.setFlatCoordinatesInternal =
|
||||
function(layout, flatCoordinates) {
|
||||
this.stride = ol.geom.Geometry.getStrideForLayout_(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryLayout|undefined} layout Layout.
|
||||
* @param {Array} coordinates Coordinates.
|
||||
* @param {number} nesting Nesting.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.Geometry.prototype.setLayout =
|
||||
function(layout, coordinates, nesting) {
|
||||
/** @type {number} */
|
||||
var stride;
|
||||
if (goog.isDef(layout)) {
|
||||
stride = ol.geom.Geometry.getStrideForLayout_(layout);
|
||||
} else {
|
||||
var i;
|
||||
for (i = 0; i < nesting; ++i) {
|
||||
if (coordinates.length === 0) {
|
||||
this.layout = ol.geom.GeometryLayout.XY;
|
||||
this.stride = 2;
|
||||
return;
|
||||
} else {
|
||||
coordinates = /** @type {Array} */ (coordinates[0]);
|
||||
}
|
||||
}
|
||||
stride = (/** @type {Array} */ (coordinates)).length;
|
||||
layout = ol.geom.Geometry.getLayoutForStride_(stride);
|
||||
}
|
||||
this.layout = layout;
|
||||
this.stride = stride;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TransformFunction} transformFn Transform.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.transform = function(transformFn) {
|
||||
if (!goog.isNull(this.flatCoordinates)) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
ol.geom.Geometry.prototype.transform = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
@@ -391,21 +206,3 @@ ol.geom.RawMultiLineString;
|
||||
* @typedef {Array.<ol.geom.RawPolygon>}
|
||||
*/
|
||||
ol.geom.RawMultiPolygon;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Geometry} geometry Geometry.
|
||||
* @param {goog.vec.Mat4.AnyType} transform Transform.
|
||||
* @param {Array.<number>=} opt_dest Destination.
|
||||
* @return {Array.<number>} Transformed flat coordinates.
|
||||
*/
|
||||
ol.geom.transformGeometry2D = function(geometry, transform, opt_dest) {
|
||||
var flatCoordinates = geometry.getFlatCoordinates();
|
||||
if (goog.isNull(flatCoordinates)) {
|
||||
return null;
|
||||
} else {
|
||||
var stride = geometry.getStride();
|
||||
return ol.geom.flat.transform2D(
|
||||
flatCoordinates, stride, transform, opt_dest);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
goog.provide('ol.geom.LinearRing');
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.closest');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.simplify');
|
||||
@@ -10,7 +10,7 @@ goog.require('ol.geom.simplify');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @extends {ol.geom.SimpleGeometry}
|
||||
* @param {ol.geom.RawLinearRing} coordinates Coordinates.
|
||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
@@ -33,7 +33,7 @@ ol.geom.LinearRing = function(coordinates, opt_layout) {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.LinearRing, ol.geom.Geometry);
|
||||
goog.inherits(ol.geom.LinearRing, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.closest');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.simplify');
|
||||
@@ -10,7 +10,7 @@ goog.require('ol.geom.simplify');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @extends {ol.geom.SimpleGeometry}
|
||||
* @param {ol.geom.RawLineString} coordinates Coordinates.
|
||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
@@ -33,7 +33,7 @@ ol.geom.LineString = function(coordinates, opt_layout) {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
||||
goog.inherits(ol.geom.LineString, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
goog.provide('ol.geom.MultiLineString');
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.closest');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.simplify');
|
||||
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @extends {ol.geom.SimpleGeometry}
|
||||
* @param {ol.geom.RawMultiLineString} coordinates Coordinates.
|
||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
@@ -40,7 +40,7 @@ ol.geom.MultiLineString = function(coordinates, opt_layout) {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.MultiLineString, ol.geom.Geometry);
|
||||
goog.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
goog.provide('ol.geom.MultiPoint');
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.flat');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @extends {ol.geom.SimpleGeometry}
|
||||
* @param {ol.geom.RawMultiPoint} coordinates Coordinates.
|
||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
@@ -17,7 +17,7 @@ ol.geom.MultiPoint = function(coordinates, opt_layout) {
|
||||
goog.base(this);
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
};
|
||||
goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry);
|
||||
goog.inherits(ol.geom.MultiPoint, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
goog.provide('ol.geom.MultiPolygon');
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.closest');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.simplify');
|
||||
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @extends {ol.geom.SimpleGeometry}
|
||||
* @param {ol.geom.RawMultiPolygon} coordinates Coordinates.
|
||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
@@ -52,7 +52,7 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.MultiPolygon, ol.geom.Geometry);
|
||||
goog.inherits(ol.geom.MultiPolygon, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,14 +2,14 @@ goog.provide('ol.geom.Point');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.flat');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @extends {ol.geom.SimpleGeometry}
|
||||
* @param {ol.geom.RawPoint} coordinates Coordinates.
|
||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
@@ -17,7 +17,7 @@ ol.geom.Point = function(coordinates, opt_layout) {
|
||||
goog.base(this);
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
};
|
||||
goog.inherits(ol.geom.Point, ol.geom.Geometry);
|
||||
goog.inherits(ol.geom.Point, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
goog.provide('ol.geom.Polygon');
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.geom.closest');
|
||||
goog.require('ol.geom.flat');
|
||||
goog.require('ol.geom.simplify');
|
||||
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @extends {ol.geom.SimpleGeometry}
|
||||
* @param {ol.geom.RawPolygon} coordinates Coordinates.
|
||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
@@ -52,7 +52,7 @@ ol.geom.Polygon = function(coordinates, opt_layout) {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
|
||||
goog.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
5
src/ol/geom/simplegeometry.exports
Normal file
5
src/ol/geom/simplegeometry.exports
Normal file
@@ -0,0 +1,5 @@
|
||||
@exportSymbol ol.geom.SimpleGeometry
|
||||
@exportProperty ol.geom.SimpleGeometry.prototype.getExtent
|
||||
@exportProperty ol.geom.SimpleGeometry.prototype.getLayout
|
||||
@exportProperty ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry
|
||||
@exportProperty ol.geom.SimpleGeometry.prototype.transform
|
||||
247
src/ol/geom/simplegeometry.js
Normal file
247
src/ol/geom/simplegeometry.js
Normal file
@@ -0,0 +1,247 @@
|
||||
goog.provide('ol.geom.SimpleGeometry');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.flat');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
*/
|
||||
ol.geom.SimpleGeometry = function() {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.geom.GeometryLayout}
|
||||
*/
|
||||
this.layout = ol.geom.GeometryLayout.XY;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.stride = 2;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.flatCoordinates = null;
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.SimpleGeometry, ol.geom.Geometry);
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} stride Stride.
|
||||
* @private
|
||||
* @return {ol.geom.GeometryLayout} layout Layout.
|
||||
*/
|
||||
ol.geom.SimpleGeometry.getLayoutForStride_ = function(stride) {
|
||||
if (stride == 2) {
|
||||
return ol.geom.GeometryLayout.XY;
|
||||
} else if (stride == 3) {
|
||||
return ol.geom.GeometryLayout.XYZ;
|
||||
} else if (stride == 4) {
|
||||
return ol.geom.GeometryLayout.XYZM;
|
||||
} else {
|
||||
throw new Error('unsupported stride: ' + stride);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||
* @private
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
ol.geom.SimpleGeometry.getStrideForLayout_ = function(layout) {
|
||||
if (layout == ol.geom.GeometryLayout.XY) {
|
||||
return 2;
|
||||
} else if (layout == ol.geom.GeometryLayout.XYZ) {
|
||||
return 3;
|
||||
} else if (layout == ol.geom.GeometryLayout.XYM) {
|
||||
return 3;
|
||||
} else if (layout == ol.geom.GeometryLayout.XYZM) {
|
||||
return 4;
|
||||
} else {
|
||||
throw new Error('unsupported layout: ' + layout);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.containsXY = goog.functions.FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.revision) {
|
||||
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
|
||||
this.flatCoordinates, this.stride, this.extent);
|
||||
this.extentRevision = this.revision;
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getFlatCoordinates = function() {
|
||||
return this.flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.geom.GeometryLayout} Layout.
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getLayout = function() {
|
||||
return this.layout;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry =
|
||||
function(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.revision) {
|
||||
goog.object.clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.revision;
|
||||
}
|
||||
// If squaredTolerance is negative or if we know that simplification will not
|
||||
// have any effect then just return this.
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||
return this;
|
||||
}
|
||||
var key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache[key];
|
||||
} else {
|
||||
var simplifiedGeometry =
|
||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||
var simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||
this.simplifiedGeometryCache[key] = simplifiedGeometry;
|
||||
return simplifiedGeometry;
|
||||
} else {
|
||||
// Simplification did not actually remove any coordinates. We now know
|
||||
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
||||
// than or equal to the current squaredTolerance will also not have any
|
||||
// effect. This allows us to short circuit simplification (saving CPU
|
||||
// cycles) and prevents the cache of simplified geometries from filling
|
||||
// up with useless identical copies of this geometry (saving memory).
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {ol.geom.SimpleGeometry} Simplified geometry.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometryInternal =
|
||||
function(squaredTolerance) {
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getStride = function() {
|
||||
return this.stride;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.setFlatCoordinatesInternal =
|
||||
function(layout, flatCoordinates) {
|
||||
this.stride = ol.geom.SimpleGeometry.getStrideForLayout_(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryLayout|undefined} layout Layout.
|
||||
* @param {Array} coordinates Coordinates.
|
||||
* @param {number} nesting Nesting.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.setLayout =
|
||||
function(layout, coordinates, nesting) {
|
||||
/** @type {number} */
|
||||
var stride;
|
||||
if (goog.isDef(layout)) {
|
||||
stride = ol.geom.SimpleGeometry.getStrideForLayout_(layout);
|
||||
} else {
|
||||
var i;
|
||||
for (i = 0; i < nesting; ++i) {
|
||||
if (coordinates.length === 0) {
|
||||
this.layout = ol.geom.GeometryLayout.XY;
|
||||
this.stride = 2;
|
||||
return;
|
||||
} else {
|
||||
coordinates = /** @type {Array} */ (coordinates[0]);
|
||||
}
|
||||
}
|
||||
stride = (/** @type {Array} */ (coordinates)).length;
|
||||
layout = ol.geom.SimpleGeometry.getLayoutForStride_(stride);
|
||||
}
|
||||
this.layout = layout;
|
||||
this.stride = stride;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.transform = function(transformFn) {
|
||||
if (!goog.isNull(this.flatCoordinates)) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.SimpleGeometry} simpleGeometry Simple geometry.
|
||||
* @param {goog.vec.Mat4.AnyType} transform Transform.
|
||||
* @param {Array.<number>=} opt_dest Destination.
|
||||
* @return {Array.<number>} Transformed flat coordinates.
|
||||
*/
|
||||
ol.geom.transformSimpleGeometry2D =
|
||||
function(simpleGeometry, transform, opt_dest) {
|
||||
var flatCoordinates = simpleGeometry.getFlatCoordinates();
|
||||
if (goog.isNull(flatCoordinates)) {
|
||||
return null;
|
||||
} else {
|
||||
var stride = simpleGeometry.getStride();
|
||||
return ol.geom.flat.transform2D(
|
||||
flatCoordinates, stride, transform, opt_dest);
|
||||
}
|
||||
};
|
||||
@@ -113,7 +113,7 @@ ol.render.canvas.Immediate.prototype.drawImages_ = function(geometry) {
|
||||
goog.asserts.assert(goog.isDef(state.anchorY));
|
||||
goog.asserts.assert(goog.isDef(state.height));
|
||||
goog.asserts.assert(goog.isDef(state.width));
|
||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
||||
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||
geometry, this.transform_, this.pixelCoordinates_);
|
||||
var i, ii;
|
||||
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
|
||||
@@ -144,7 +144,7 @@ ol.render.canvas.Immediate.prototype.drawText_ = function(geometry) {
|
||||
return;
|
||||
}
|
||||
this.setFillStrokeStyles_();
|
||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
||||
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||
geometry, this.transform_, this.pixelCoordinates_);
|
||||
var i, ii;
|
||||
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
|
||||
@@ -251,7 +251,7 @@ ol.render.canvas.Immediate.prototype.drawLineStringGeometry =
|
||||
}
|
||||
this.setFillStrokeStyles_();
|
||||
var context = this.context_;
|
||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
||||
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||
lineStringGeometry, this.transform_, this.pixelCoordinates_);
|
||||
context.beginPath();
|
||||
this.moveToLineTo_(pixelCoordinates, 0, pixelCoordinates.length, false);
|
||||
@@ -271,7 +271,7 @@ ol.render.canvas.Immediate.prototype.drawMultiLineStringGeometry =
|
||||
}
|
||||
this.setFillStrokeStyles_();
|
||||
var context = this.context_;
|
||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
||||
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||
multiLineStringGeometry, this.transform_, this.pixelCoordinates_);
|
||||
context.beginPath();
|
||||
var ends = multiLineStringGeometry.getEnds();
|
||||
@@ -298,7 +298,7 @@ ol.render.canvas.Immediate.prototype.drawPolygonGeometry =
|
||||
}
|
||||
this.setFillStrokeStyles_();
|
||||
var context = this.context_;
|
||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
||||
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||
polygonGeometry, this.transform_, this.pixelCoordinates_);
|
||||
var ends = polygonGeometry.getEnds();
|
||||
context.beginPath();
|
||||
@@ -327,7 +327,7 @@ ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry =
|
||||
}
|
||||
this.setFillStrokeStyles_();
|
||||
var context = this.context_;
|
||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
||||
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||
multiPolygonGeometry, this.transform_, this.pixelCoordinates_);
|
||||
var endss = multiPolygonGeometry.getEndss();
|
||||
var offset = 0;
|
||||
|
||||
Reference in New Issue
Block a user