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