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.dom.TagName');
|
||||||
goog.require('goog.events');
|
goog.require('goog.events');
|
||||||
goog.require('goog.events.EventType');
|
goog.require('goog.events.EventType');
|
||||||
|
goog.require('goog.math');
|
||||||
goog.require('ol.animation');
|
goog.require('ol.animation');
|
||||||
goog.require('ol.control.Control');
|
goog.require('ol.control.Control');
|
||||||
goog.require('ol.css');
|
goog.require('ol.css');
|
||||||
@@ -30,10 +31,13 @@ ol.control.Rotate = function(opt_options) {
|
|||||||
var className = goog.isDef(options.className) ?
|
var className = goog.isDef(options.className) ?
|
||||||
options.className : 'ol-rotate';
|
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' },
|
{ 'class': 'ol-compass' },
|
||||||
goog.isDef(options.label) ? options.label : '\u21E7');
|
goog.isDef(options.label) ? options.label : '\u21E7');
|
||||||
this.label_ = label;
|
|
||||||
|
|
||||||
var tipLabel = goog.isDef(options.tipLabel) ?
|
var tipLabel = goog.isDef(options.tipLabel) ?
|
||||||
options.tipLabel : 'Reset rotation';
|
options.tipLabel : 'Reset rotation';
|
||||||
@@ -45,7 +49,7 @@ ol.control.Rotate = function(opt_options) {
|
|||||||
'class': className + '-reset ol-has-tooltip',
|
'class': className + '-reset ol-has-tooltip',
|
||||||
'name' : 'ResetRotation',
|
'name' : 'ResetRotation',
|
||||||
'type' : 'button'
|
'type' : 'button'
|
||||||
}, tip, label);
|
}, tip, this.label_);
|
||||||
|
|
||||||
var handler = new ol.pointer.PointerEventHandler(button);
|
var handler = new ol.pointer.PointerEventHandler(button);
|
||||||
this.registerDisposable(handler);
|
this.registerDisposable(handler);
|
||||||
@@ -82,6 +86,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;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -146,11 +156,14 @@ ol.control.Rotate.prototype.handleMapPostrender = function(mapEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var rotation = frameState.viewState.rotation;
|
var rotation = frameState.viewState.rotation;
|
||||||
var transform = 'rotate(' + rotation * 360 / (Math.PI * 2) + 'deg)';
|
if (rotation != this.rotation_) {
|
||||||
if (this.autoHide_) {
|
var transform = 'rotate(' + goog.math.toDegrees(rotation) + 'deg)';
|
||||||
this.element.style.opacity = (rotation === 0) ? 0 : 1;
|
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.rotation_ = rotation;
|
||||||
this.label_.style.webkitTransform = transform;
|
|
||||||
this.label_.style.transform = transform;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user