Compute anchor value only once
This commit is contained in:
@@ -52,6 +52,12 @@ ol.style.Icon = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.anchor_ = goog.isDef(options.anchor) ? options.anchor : [0.5, 0.5];
|
this.anchor_ = goog.isDef(options.anchor) ? options.anchor : [0.5, 0.5];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Array.<number>}
|
||||||
|
*/
|
||||||
|
this.normalizedAnchor_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.style.IconAnchorOrigin}
|
* @type {ol.style.IconAnchorOrigin}
|
||||||
@@ -128,6 +134,9 @@ goog.inherits(ol.style.Icon, ol.style.Image);
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.style.Icon.prototype.getAnchor = function() {
|
ol.style.Icon.prototype.getAnchor = function() {
|
||||||
|
if (!goog.isNull(this.normalizedAnchor_)) {
|
||||||
|
return this.normalizedAnchor_;
|
||||||
|
}
|
||||||
var anchor = this.anchor_;
|
var anchor = this.anchor_;
|
||||||
var size = this.getSize();
|
var size = this.getSize();
|
||||||
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
|
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
|
||||||
@@ -160,7 +169,8 @@ ol.style.Icon.prototype.getAnchor = function() {
|
|||||||
anchor[1] = -anchor[1] + size[1];
|
anchor[1] = -anchor[1] + size[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return anchor;
|
this.normalizedAnchor_ = anchor;
|
||||||
|
return this.normalizedAnchor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user