Make extent a function rather than a property

This commit is contained in:
Tom Payne
2012-07-24 11:21:25 +02:00
parent 8a8a9a8c9a
commit b1012b5b86
+15 -33
View File
@@ -47,7 +47,6 @@ ol.MapProperty = {
BACKGROUND_COLOR: 'backgroundColor', BACKGROUND_COLOR: 'backgroundColor',
CENTER: 'center', CENTER: 'center',
CONTROLS: 'controls', CONTROLS: 'controls',
EXTENT: 'extent',
LAYERS: 'layers', LAYERS: 'layers',
PROJECTION: 'projection', PROJECTION: 'projection',
RESOLUTION: 'resolution', RESOLUTION: 'resolution',
@@ -327,7 +326,18 @@ ol.Map.prototype.getCoordinateFromPixel = function(pixel) {
* @return {ol.Extent|undefined} Extent. * @return {ol.Extent|undefined} Extent.
*/ */
ol.Map.prototype.getExtent = function() { ol.Map.prototype.getExtent = function() {
return /** @type {ol.Extent} */ this.get(ol.MapProperty.EXTENT); var size = this.getSize();
var center = this.getCenter();
var resolution = this.getResolution();
if (!goog.isDef(size) || !goog.isDef(center) || !goog.isDef(resolution)) {
return undefined;
} else {
var minX = center.x - resolution * size.width / 2;
var minY = center.y - resolution * size.height / 2;
var maxX = center.x + resolution * size.width / 2;
var maxY = center.y + resolution * size.height / 2;
return new ol.Extent(minX, minY, maxX, maxY);
}
}; };
@@ -481,9 +491,7 @@ ol.Map.prototype.handleDraggerEvent = function(event) {
/** /**
* @protected * @protected
*/ */
ol.Map.prototype.handleCenterChanged = function() { ol.Map.prototype.handleCenterChanged = goog.nullFunction;
this.recalculateExtent_();
};
/** /**
@@ -585,17 +593,13 @@ ol.Map.prototype.handleProjectionChanged = function() {
/** /**
* @protected * @protected
*/ */
ol.Map.prototype.handleResolutionChanged = function() { ol.Map.prototype.handleResolutionChanged = goog.nullFunction;
this.recalculateExtent_();
};
/** /**
* @protected * @protected
*/ */
ol.Map.prototype.handleSizeChanged = function() { ol.Map.prototype.handleSizeChanged = goog.nullFunction;
this.recalculateExtent_();
};
/** /**
@@ -615,28 +619,6 @@ ol.Map.prototype.handleViewportResize = function() {
}; };
/**
* @private
*/
ol.Map.prototype.recalculateExtent_ = function() {
var size = this.getSize();
var center = this.getCenter();
var resolution = this.getResolution();
if (!goog.isDef(size) || !goog.isDef(center) || !goog.isDef(resolution)) {
if (goog.isDef(this.getExtent())) {
this.set(ol.MapProperty.EXTENT, undefined);
}
} else {
var minX = center.x - resolution * size.width / 2;
var minY = center.y - resolution * size.height / 2;
var maxX = center.x + resolution * size.width / 2;
var maxY = center.y + resolution * size.height / 2;
var extent = new ol.Extent(minX, minY, maxX, maxY);
this.set(ol.MapProperty.EXTENT, extent);
}
};
/** /**
* @private * @private
*/ */