Caching bounds center location. r=elemoine (closes #1814)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8286 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -38,7 +38,14 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
* Property: top
|
||||
* {Number} Maximum vertical coordinate.
|
||||
*/
|
||||
top: null,
|
||||
top: null,
|
||||
|
||||
/**
|
||||
* Property: centerLonLat
|
||||
* {<OpenLayers.LonLat>} A cached center location. This should not be
|
||||
* accessed directly. Use <getCenterLonLat> instead.
|
||||
*/
|
||||
centerLonLat: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Bounds
|
||||
@@ -215,8 +222,12 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
* {<OpenLayers.LonLat>} The center of the bounds in map space.
|
||||
*/
|
||||
getCenterLonLat:function() {
|
||||
return new OpenLayers.LonLat( (this.left + this.right) / 2,
|
||||
(this.bottom + this.top) / 2);
|
||||
if(!this.centerLonLat) {
|
||||
this.centerLonLat = new OpenLayers.LonLat(
|
||||
(this.left + this.right) / 2, (this.bottom + this.top) / 2
|
||||
);
|
||||
}
|
||||
return this.centerLonLat;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -257,7 +268,7 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
var bottom = (this.bottom - origy) * ratio + origy;
|
||||
var right = (this.right - origx) * ratio + origx;
|
||||
var top = (this.top - origy) * ratio + origy;
|
||||
|
||||
|
||||
return new OpenLayers.Bounds(left, bottom, right, top);
|
||||
},
|
||||
|
||||
@@ -291,8 +302,9 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
* object - {Object} Can be LonLat, Point, or Bounds
|
||||
*/
|
||||
extend:function(object) {
|
||||
var bounds = null;
|
||||
if (object) {
|
||||
// clear cached center location
|
||||
this.centerLonLat = null;
|
||||
switch(object.CLASS_NAME) {
|
||||
case "OpenLayers.LonLat":
|
||||
bounds = new OpenLayers.Bounds(object.lon, object.lat,
|
||||
@@ -309,6 +321,7 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
}
|
||||
|
||||
if (bounds) {
|
||||
var bounds = null;
|
||||
if ( (this.left == null) || (bounds.left < this.left)) {
|
||||
this.left = bounds.left;
|
||||
}
|
||||
@@ -499,6 +512,8 @@ OpenLayers.Bounds = OpenLayers.Class({
|
||||
* {<OpenLayers.Bounds>} Itself, for use in chaining operations.
|
||||
*/
|
||||
transform: function(source, dest) {
|
||||
// clear cached center location
|
||||
this.centerLonLat = null;
|
||||
var ll = OpenLayers.Projection.transform(
|
||||
{'x': this.left, 'y': this.bottom}, source, dest);
|
||||
var lr = OpenLayers.Projection.transform(
|
||||
|
||||
Reference in New Issue
Block a user