remove state variables from the dom map and dom layer renderers

This commit is contained in:
Éric Lemoine
2012-07-18 11:12:14 +02:00
parent 40c767c330
commit be97a57cad
2 changed files with 13 additions and 88 deletions
-19
View File
@@ -19,15 +19,6 @@ ol.dom.LayerRenderer = function(map, layer, target) {
* @protected * @protected
*/ */
this.target = target; this.target = target;
/**
* Location of the top-left corner of the renderer container in map coords.
*
* @type {goog.math.Coordinate}
* @protected
*/
this.containerOrigin = null;
}; };
goog.inherits(ol.dom.LayerRenderer, ol.LayerRenderer); goog.inherits(ol.dom.LayerRenderer, ol.LayerRenderer);
@@ -41,16 +32,6 @@ ol.dom.LayerRenderer.prototype.getMap = function() {
}; };
/**
* Set the location of the top-left corner of the renderer container.
*
* @param {goog.math.Coordinate} origin The container origin.
*/
ol.dom.LayerRenderer.prototype.setContainerOrigin = function(origin) {
this.containerOrigin = origin;
};
/** /**
*/ */
ol.dom.LayerRenderer.prototype.redraw = goog.abstractMethod; ol.dom.LayerRenderer.prototype.redraw = goog.abstractMethod;
+13 -69
View File
@@ -28,36 +28,6 @@ ol.dom.Map = function(target, opt_values) {
this.layersPane_.className = 'ol-renderer-dom'; this.layersPane_.className = 'ol-renderer-dom';
target.appendChild(this.layersPane_); target.appendChild(this.layersPane_);
/**
* The current top left corner location of the layersPane element
* (map coords).
*
* @type {goog.math.Coordinate}
* @private
*/
this.layersPaneOrigin_ = null;
/**
* The pixel offset of the layersPane element with respect to its
* container.
*
* @type {goog.math.Coordinate}
* @private
*/
this.layersPaneOffset_ = null;
/**
* @type {goog.math.Coordinate|undefined}
* @private
*/
this.renderedCenter_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.renderedResolution_ = undefined;
/** /**
* @type {Object} * @type {Object}
* @private * @private
@@ -79,30 +49,8 @@ goog.inherits(ol.dom.Map, ol.Map);
* @private * @private
*/ */
ol.dom.Map.prototype.resetLayersPane_ = function() { ol.dom.Map.prototype.resetLayersPane_ = function() {
this.layersPaneOrigin_ = this.getOrigin_();
goog.object.forEach(this.layerRenderers, function(layerRenderer) {
layerRenderer.setContainerOrigin(this.layersPaneOrigin_);
});
var offset = new goog.math.Coordinate(0, 0); var offset = new goog.math.Coordinate(0, 0);
goog.style.setPosition(this.layersPane_, offset); goog.style.setPosition(this.layersPane_, offset);
this.renderedCenter_ = this.getCenter();
};
/**
* Get the position of the top-left corner of the layers pane.
* @private
* @return {goog.math.Coordinate} Origin.
*/
ol.dom.Map.prototype.getOrigin_ = function() {
var center = this.getCenter();
var resolution = this.getResolution();
var targetSize = this.getSize();
var targetWidth = targetSize.width;
var targetHeight = targetSize.height;
return new goog.math.Coordinate(
center.x - resolution * targetWidth / 2,
center.y + resolution * targetHeight / 2);
}; };
@@ -111,17 +59,17 @@ ol.dom.Map.prototype.getOrigin_ = function() {
* @private * @private
*/ */
ol.dom.Map.prototype.shiftLayersPane_ = function() { ol.dom.Map.prototype.shiftLayersPane_ = function() {
var center = this.getCenter(); //var center = this.getCenter();
var oldCenter = this.renderedCenter_; //var oldCenter = this.renderedCenter_;
var resolution = this.getResolution(); //var resolution = this.getResolution();
var dx = Math.round((oldCenter.x - center.x) / resolution); //var dx = Math.round((oldCenter.x - center.x) / resolution);
var dy = Math.round((center.y - oldCenter.y) / resolution); //var dy = Math.round((center.y - oldCenter.y) / resolution);
if (!(dx === 0 && dy === 0)) { //if (!(dx === 0 && dy === 0)) {
var offset = this.layersPaneOffset_; //var offset = this.layersPaneOffset_;
offset.x += Math.round((oldCenter.x - center.x) / resolution); //offset.x += Math.round((oldCenter.x - center.x) / resolution);
offset.y += Math.round((center.y - oldCenter.y) / resolution); //offset.y += Math.round((center.y - oldCenter.y) / resolution);
goog.style.setPosition(this.layersPane_, offset); //goog.style.setPosition(this.layersPane_, offset);
} //}
}; };
@@ -142,7 +90,6 @@ ol.dom.Map.prototype.createLayerRenderer = function(layer) {
this.layersPane_.appendChild(layerPane); this.layersPane_.appendChild(layerPane);
var layerRenderer = new ol.dom.TileLayerRenderer(this, layer, layerPane); var layerRenderer = new ol.dom.TileLayerRenderer(this, layer, layerPane);
layerRenderer.setContainerOrigin(this.layersPaneOrigin_);
this.layerPanes_[goog.getUid(layerRenderer)] = layerPane; this.layerPanes_[goog.getUid(layerRenderer)] = layerPane;
@@ -185,11 +132,8 @@ ol.dom.Map.prototype.handleLayerRemove = function(layer) {
*/ */
ol.dom.Map.prototype.handleResolutionChanged = function() { ol.dom.Map.prototype.handleResolutionChanged = function() {
goog.base(this, 'handleResolutionChanged'); goog.base(this, 'handleResolutionChanged');
var resolution = this.getResolution(); this.resetLayersPane_();
if (resolution != this.renderedResolution_) { this.redraw();
this.resetLayersPane_();
this.redraw();
}
}; };