Only update rotate control element when it's needed
To avoid a lot of 'Recalculate style' events by the browser.
This commit is contained in:
@@ -88,6 +88,12 @@ ol.control.Rotate = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.autoHide_ = goog.isDef(options.autoHide) ? options.autoHide : true;
|
this.autoHide_ = goog.isDef(options.autoHide) ? options.autoHide : true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number|undefined}
|
||||||
|
*/
|
||||||
|
this.rotation_ = undefined;
|
||||||
|
|
||||||
element.style.opacity = (this.autoHide_) ? 0 : 1;
|
element.style.opacity = (this.autoHide_) ? 0 : 1;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -152,6 +158,7 @@ ol.control.Rotate.prototype.handleMapPostrender = function(mapEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var rotation = frameState.viewState.rotation;
|
var rotation = frameState.viewState.rotation;
|
||||||
|
if (rotation != this.rotation_) {
|
||||||
var transform = 'rotate(' + goog.math.toDegrees(rotation) + 'deg)';
|
var transform = 'rotate(' + goog.math.toDegrees(rotation) + 'deg)';
|
||||||
if (this.autoHide_) {
|
if (this.autoHide_) {
|
||||||
this.element.style.opacity = (rotation === 0) ? 0 : 1;
|
this.element.style.opacity = (rotation === 0) ? 0 : 1;
|
||||||
@@ -159,4 +166,6 @@ ol.control.Rotate.prototype.handleMapPostrender = function(mapEvent) {
|
|||||||
this.label_.style.msTransform = transform;
|
this.label_.style.msTransform = transform;
|
||||||
this.label_.style.webkitTransform = transform;
|
this.label_.style.webkitTransform = transform;
|
||||||
this.label_.style.transform = transform;
|
this.label_.style.transform = transform;
|
||||||
|
}
|
||||||
|
this.rotation_ = rotation;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user