Merge pull request #2571 from fredj/rotatecontrol-cleanup
ol.control.Rotate cleanup and optimization
This commit is contained in:
@@ -5,6 +5,7 @@ goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.animation');
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('ol.css');
|
||||
@@ -30,10 +31,13 @@ ol.control.Rotate = function(opt_options) {
|
||||
var className = goog.isDef(options.className) ?
|
||||
options.className : 'ol-rotate';
|
||||
|
||||
var label = goog.dom.createDom(goog.dom.TagName.SPAN,
|
||||
/**
|
||||
* @type {Element}
|
||||
* @private
|
||||
*/
|
||||
this.label_ = goog.dom.createDom(goog.dom.TagName.SPAN,
|
||||
{ 'class': 'ol-compass' },
|
||||
goog.isDef(options.label) ? options.label : '\u21E7');
|
||||
this.label_ = label;
|
||||
|
||||
var tipLabel = goog.isDef(options.tipLabel) ?
|
||||
options.tipLabel : 'Reset rotation';
|
||||
@@ -45,7 +49,7 @@ ol.control.Rotate = function(opt_options) {
|
||||
'class': className + '-reset ol-has-tooltip',
|
||||
'name' : 'ResetRotation',
|
||||
'type' : 'button'
|
||||
}, tip, label);
|
||||
}, tip, this.label_);
|
||||
|
||||
var handler = new ol.pointer.PointerEventHandler(button);
|
||||
this.registerDisposable(handler);
|
||||
@@ -82,6 +86,12 @@ ol.control.Rotate = function(opt_options) {
|
||||
*/
|
||||
this.autoHide_ = goog.isDef(options.autoHide) ? options.autoHide : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.rotation_ = undefined;
|
||||
|
||||
element.style.opacity = (this.autoHide_) ? 0 : 1;
|
||||
|
||||
};
|
||||
@@ -146,11 +156,14 @@ ol.control.Rotate.prototype.handleMapPostrender = function(mapEvent) {
|
||||
return;
|
||||
}
|
||||
var rotation = frameState.viewState.rotation;
|
||||
var transform = 'rotate(' + rotation * 360 / (Math.PI * 2) + 'deg)';
|
||||
if (this.autoHide_) {
|
||||
this.element.style.opacity = (rotation === 0) ? 0 : 1;
|
||||
if (rotation != this.rotation_) {
|
||||
var transform = 'rotate(' + goog.math.toDegrees(rotation) + 'deg)';
|
||||
if (this.autoHide_) {
|
||||
this.element.style.opacity = (rotation === 0) ? 0 : 1;
|
||||
}
|
||||
this.label_.style.msTransform = transform;
|
||||
this.label_.style.webkitTransform = transform;
|
||||
this.label_.style.transform = transform;
|
||||
}
|
||||
this.label_.style.msTransform = transform;
|
||||
this.label_.style.webkitTransform = transform;
|
||||
this.label_.style.transform = transform;
|
||||
this.rotation_ = rotation;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user