Files
openlayers/src/ol/geom/abstractcollection.js
Tim Schaub b52d283641 Allow geometries to use a shared vertex array
The ol.geom.SharedVertices structure represents a flattened array of vertex coordinates.  This is intended to support optimal WebGL rendering.
2013-03-02 18:39:24 +01:00

80 lines
1.6 KiB
JavaScript

goog.provide('ol.geom.AbstractCollection');
goog.require('ol.Extent');
goog.require('ol.geom.Geometry');
/**
* A collection of geometries. This constructor is not to be used directly.
*
* @constructor
* @extends {ol.geom.Geometry}
*/
ol.geom.AbstractCollection = function() {
goog.base(this);
/**
* @type {number}
*/
this.dimension;
/**
* @type {Array.<ol.geom.Geometry>}
*/
this.components = null;
/**
* @type {ol.Extent}
* @protected
*/
this.bounds = null;
};
goog.inherits(ol.geom.AbstractCollection, ol.geom.Geometry);
/**
* @inheritDoc
*/
ol.geom.AbstractCollection.prototype.getBounds = function() {
if (goog.isNull(this.bounds)) {
var minX,
minY = minX = Number.POSITIVE_INFINITY,
maxX,
maxY = maxX = Number.NEGATIVE_INFINITY,
components = this.components,
len = components.length,
bounds, i;
for (i = 0; i < len; ++i) {
bounds = components[i].getBounds();
minX = Math.min(bounds.minX, minX);
minY = Math.min(bounds.minY, minY);
maxX = Math.max(bounds.maxX, maxX);
maxY = Math.max(bounds.maxY, maxY);
}
this.bounds = new ol.Extent(minX, minY, maxX, maxY);
}
return this.bounds;
};
/**
* @inheritDoc
*/
ol.geom.AbstractCollection.prototype.getCoordinates = function() {
var count = this.components.length;
var coordinates = new Array(count);
for (var i = 0; i < count; ++i) {
coordinates[i] = this.components[i].getCoordinates();
}
return coordinates;
};
/**
* @inheritDoc
*/
ol.geom.AbstractCollection.prototype.getType = goog.abstractMethod;