Add geom.ol.geom.Geometry#computeExtent function
This commit is contained in:
@@ -94,20 +94,14 @@ ol.geom.Circle.prototype.getCenter = function() {
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
ol.geom.Circle.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
var flatCoordinates = this.flatCoordinates;
|
||||
var radius = flatCoordinates[this.stride] - flatCoordinates[0];
|
||||
this.extent = ol.extent.createOrUpdate(
|
||||
flatCoordinates[0] - radius, flatCoordinates[1] - radius,
|
||||
flatCoordinates[0] + radius, flatCoordinates[1] + radius,
|
||||
this.extent);
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
ol.geom.Circle.prototype.computeExtent = function(extent) {
|
||||
var flatCoordinates = this.flatCoordinates;
|
||||
var radius = flatCoordinates[this.stride] - flatCoordinates[0];
|
||||
return ol.extent.createOrUpdate(
|
||||
flatCoordinates[0] - radius, flatCoordinates[1] - radius,
|
||||
flatCoordinates[0] + radius, flatCoordinates[1] + radius,
|
||||
extent);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
goog.provide('ol.geom.Geometry');
|
||||
goog.provide('ol.geom.GeometryType');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol.Observable');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.proj');
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@ ol.geom.Geometry = function() {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.Extent|undefined}
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.extent = undefined;
|
||||
this.extent = ol.extent.createEmpty();
|
||||
|
||||
/**
|
||||
* @protected
|
||||
@@ -134,6 +134,14 @@ ol.geom.Geometry.prototype.containsCoordinate = function(coordinate) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @protected
|
||||
* @return {ol.Extent} extent Extent.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.computeExtent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
@@ -144,12 +152,17 @@ ol.geom.Geometry.prototype.containsXY = goog.functions.FALSE;
|
||||
|
||||
/**
|
||||
* Get the extent of the geometry.
|
||||
* @function
|
||||
* @param {ol.Extent=} opt_extent Extent.
|
||||
* @return {ol.Extent} extent Extent.
|
||||
* @api stable
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getExtent = goog.abstractMethod;
|
||||
ol.geom.Geometry.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
this.extent = this.computeExtent(this.extent);
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
goog.provide('ol.geom.GeometryCollection');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.object');
|
||||
@@ -130,21 +129,14 @@ ol.geom.GeometryCollection.prototype.containsXY = function(x, y) {
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api stable
|
||||
*/
|
||||
ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
var extent = ol.extent.createOrUpdateEmpty(this.extent);
|
||||
var geometries = this.geometries_;
|
||||
var i, ii;
|
||||
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
ol.extent.extend(extent, geometries[i].getExtent());
|
||||
}
|
||||
this.extent = extent;
|
||||
this.extentRevision = this.getRevision();
|
||||
ol.geom.GeometryCollection.prototype.computeExtent = function(extent) {
|
||||
ol.extent.createOrUpdateEmpty(extent);
|
||||
var geometries = this.geometries_;
|
||||
for (var i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
ol.extent.extend(extent, geometries[i].getExtent());
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
return extent;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -73,14 +73,8 @@ ol.geom.Point.prototype.getCoordinates = function() {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.Point.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
this.extent = ol.extent.createOrUpdateFromCoordinate(
|
||||
this.flatCoordinates, this.extent);
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
ol.geom.Point.prototype.computeExtent = function(extent) {
|
||||
return ol.extent.createOrUpdateFromCoordinate(this.flatCoordinates, extent);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -90,17 +90,11 @@ ol.geom.SimpleGeometry.prototype.containsXY = goog.functions.FALSE;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api stable
|
||||
*/
|
||||
ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.getRevision()) {
|
||||
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
this.extent);
|
||||
this.extentRevision = this.getRevision();
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
ol.geom.SimpleGeometry.prototype.computeExtent = function(extent) {
|
||||
return ol.extent.createOrUpdateFromFlatCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
extent);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user