Remove private static members from control constructors

This commit is contained in:
Tim Schaub
2018-02-09 15:08:10 -07:00
parent 2779fe57ff
commit 80fa8dbaf5
4 changed files with 80 additions and 76 deletions

View File

@@ -8,6 +8,30 @@ import {replaceNode} from '../dom.js';
import {listen} from '../events.js'; import {listen} from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
/**
* @return {string} Change type.
*/
const getChangeType = (function() {
let changeType;
return function() {
if (!changeType) {
const body = document.body;
if (body.webkitRequestFullscreen) {
changeType = 'webkitfullscreenchange';
} else if (body.mozRequestFullScreen) {
changeType = 'mozfullscreenchange';
} else if (body.msRequestFullscreen) {
changeType = 'MSFullscreenChange';
} else if (body.requestFullscreen) {
changeType = 'fullscreenchange';
}
}
return changeType;
};
})();
/** /**
* @classdesc * @classdesc
* Provides a button that when clicked fills up the full screen with the map. * Provides a button that when clicked fills up the full screen with the map.
@@ -162,7 +186,7 @@ FullScreen.prototype.setMap = function(map) {
Control.prototype.setMap.call(this, map); Control.prototype.setMap.call(this, map);
if (map) { if (map) {
this.listenerKeys.push(listen(document, this.listenerKeys.push(listen(document,
FullScreen.getChangeType_(), getChangeType(),
this.handleFullScreenChange_, this) this.handleFullScreenChange_, this)
); );
} }
@@ -236,26 +260,4 @@ FullScreen.exitFullScreen = function() {
} }
}; };
/**
* @return {string} Change type.
* @private
*/
FullScreen.getChangeType_ = (function() {
let changeType;
return function() {
if (!changeType) {
const body = document.body;
if (body.webkitRequestFullscreen) {
changeType = 'webkitfullscreenchange';
} else if (body.mozRequestFullScreen) {
changeType = 'mozfullscreenchange';
} else if (body.msRequestFullscreen) {
changeType = 'MSFullscreenChange';
} else if (body.requestFullscreen) {
changeType = 'fullscreenchange';
}
}
return changeType;
};
})();
export default FullScreen; export default FullScreen;

View File

@@ -9,6 +9,18 @@ import BaseObject from '../Object.js';
import Control from '../control/Control.js'; import Control from '../control/Control.js';
import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js'; import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js';
/**
* @type {string}
*/
const PROJECTION = 'projection';
/**
* @type {string}
*/
const COORDINATE_FORMAT = 'coordinateFormat';
/** /**
* @classdesc * @classdesc
* A control to show the 2D coordinates of the mouse cursor. By default, these * A control to show the 2D coordinates of the mouse cursor. By default, these
@@ -39,7 +51,7 @@ const MousePosition = function(opt_options) {
}); });
listen(this, listen(this,
BaseObject.getChangeEventType(MousePosition.Property_.PROJECTION), BaseObject.getChangeEventType(PROJECTION),
this.handleProjectionChanged_, this); this.handleProjectionChanged_, this);
if (options.coordinateFormat) { if (options.coordinateFormat) {
@@ -122,7 +134,7 @@ MousePosition.prototype.handleProjectionChanged_ = function() {
*/ */
MousePosition.prototype.getCoordinateFormat = function() { MousePosition.prototype.getCoordinateFormat = function() {
return ( return (
/** @type {ol.CoordinateFormatType|undefined} */ this.get(MousePosition.Property_.COORDINATE_FORMAT) /** @type {ol.CoordinateFormatType|undefined} */ this.get(COORDINATE_FORMAT)
); );
}; };
@@ -136,7 +148,7 @@ MousePosition.prototype.getCoordinateFormat = function() {
*/ */
MousePosition.prototype.getProjection = function() { MousePosition.prototype.getProjection = function() {
return ( return (
/** @type {ol.proj.Projection|undefined} */ this.get(MousePosition.Property_.PROJECTION) /** @type {ol.proj.Projection|undefined} */ this.get(PROJECTION)
); );
}; };
@@ -188,7 +200,7 @@ MousePosition.prototype.setMap = function(map) {
* @api * @api
*/ */
MousePosition.prototype.setCoordinateFormat = function(format) { MousePosition.prototype.setCoordinateFormat = function(format) {
this.set(MousePosition.Property_.COORDINATE_FORMAT, format); this.set(COORDINATE_FORMAT, format);
}; };
@@ -200,7 +212,7 @@ MousePosition.prototype.setCoordinateFormat = function(format) {
* @api * @api
*/ */
MousePosition.prototype.setProjection = function(projection) { MousePosition.prototype.setProjection = function(projection) {
this.set(MousePosition.Property_.PROJECTION, getProjection(projection)); this.set(PROJECTION, getProjection(projection));
}; };
@@ -239,12 +251,4 @@ MousePosition.prototype.updateHTML_ = function(pixel) {
}; };
/**
* @enum {string}
* @private
*/
MousePosition.Property_ = {
PROJECTION: 'projection',
COORDINATE_FORMAT: 'coordinateFormat'
};
export default MousePosition; export default MousePosition;

View File

@@ -11,6 +11,20 @@ import {listen} from '../events.js';
import {getPointResolution, METERS_PER_UNIT} from '../proj.js'; import {getPointResolution, METERS_PER_UNIT} from '../proj.js';
import Units from '../proj/Units.js'; import Units from '../proj/Units.js';
/**
* @type {string}
*/
const UNITS = 'units';
/**
* @const
* @type {Array.<number>}
*/
const LEADING_DIGITS = [1, 2, 5];
/** /**
* @classdesc * @classdesc
* A control displaying rough y-axis distances, calculated for the center of the * A control displaying rough y-axis distances, calculated for the center of the
@@ -86,7 +100,7 @@ const ScaleLine = function(opt_options) {
}); });
listen( listen(
this, BaseObject.getChangeEventType(ScaleLine.Property_.UNITS), this, BaseObject.getChangeEventType(UNITS),
this.handleUnitsChanged_, this); this.handleUnitsChanged_, this);
this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) || this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||
@@ -97,13 +111,6 @@ const ScaleLine = function(opt_options) {
inherits(ScaleLine, Control); inherits(ScaleLine, Control);
/**
* @const
* @type {Array.<number>}
*/
ScaleLine.LEADING_DIGITS = [1, 2, 5];
/** /**
* Return the units to use in the scale line. * Return the units to use in the scale line.
* @return {ol.control.ScaleLineUnits|undefined} The units to use in the scale * @return {ol.control.ScaleLineUnits|undefined} The units to use in the scale
@@ -113,7 +120,7 @@ ScaleLine.LEADING_DIGITS = [1, 2, 5];
*/ */
ScaleLine.prototype.getUnits = function() { ScaleLine.prototype.getUnits = function() {
return ( return (
/** @type {ol.control.ScaleLineUnits|undefined} */ this.get(ScaleLine.Property_.UNITS) /** @type {ol.control.ScaleLineUnits|undefined} */ this.get(UNITS)
); );
}; };
@@ -150,7 +157,7 @@ ScaleLine.prototype.handleUnitsChanged_ = function() {
* @api * @api
*/ */
ScaleLine.prototype.setUnits = function(units) { ScaleLine.prototype.setUnits = function(units) {
this.set(ScaleLine.Property_.UNITS, units); this.set(UNITS, units);
}; };
@@ -244,7 +251,7 @@ ScaleLine.prototype.updateElement_ = function() {
Math.log(this.minWidth_ * pointResolution) / Math.log(10)); Math.log(this.minWidth_ * pointResolution) / Math.log(10));
let count, width; let count, width;
while (true) { while (true) {
count = ScaleLine.LEADING_DIGITS[((i % 3) + 3) % 3] * count = LEADING_DIGITS[((i % 3) + 3) % 3] *
Math.pow(10, Math.floor(i / 3)); Math.pow(10, Math.floor(i / 3));
width = Math.round(count / pointResolution); width = Math.round(count / pointResolution);
if (isNaN(width)) { if (isNaN(width)) {
@@ -275,12 +282,4 @@ ScaleLine.prototype.updateElement_ = function() {
}; };
/**
* @enum {string}
* @private
*/
ScaleLine.Property_ = {
UNITS: 'units'
};
export default ScaleLine; export default ScaleLine;

View File

@@ -1,8 +1,6 @@
/** /**
* @module ol/control/ZoomSlider * @module ol/control/ZoomSlider
*/ */
// FIXME should possibly show tooltip when dragging?
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import Control from '../control/Control.js'; import Control from '../control/Control.js';
@@ -15,6 +13,18 @@ import {clamp} from '../math.js';
import PointerEventType from '../pointer/EventType.js'; import PointerEventType from '../pointer/EventType.js';
import PointerEventHandler from '../pointer/PointerEventHandler.js'; import PointerEventHandler from '../pointer/PointerEventHandler.js';
/**
* The enum for available directions.
*
* @enum {number}
*/
const Direction = {
VERTICAL: 0,
HORIZONTAL: 1
};
/** /**
* @classdesc * @classdesc
* A slider type of control for zooming. * A slider type of control for zooming.
@@ -42,12 +52,12 @@ const ZoomSlider = function(opt_options) {
/** /**
* The direction of the slider. Will be determined from actual display of the * The direction of the slider. Will be determined from actual display of the
* container and defaults to ol.control.ZoomSlider.Direction_.VERTICAL. * container and defaults to Direction.VERTICAL.
* *
* @type {ol.control.ZoomSlider.Direction_} * @type {Direction}
* @private * @private
*/ */
this.direction_ = ZoomSlider.Direction_.VERTICAL; this.direction_ = Direction.VERTICAL;
/** /**
* @type {boolean} * @type {boolean}
@@ -145,18 +155,6 @@ ZoomSlider.prototype.disposeInternal = function() {
}; };
/**
* The enum for available directions.
*
* @enum {number}
* @private
*/
ZoomSlider.Direction_ = {
VERTICAL: 0,
HORIZONTAL: 1
};
/** /**
* @inheritDoc * @inheritDoc
*/ */
@@ -192,10 +190,10 @@ ZoomSlider.prototype.initSlider_ = function() {
this.thumbSize_ = [thumbWidth, thumbHeight]; this.thumbSize_ = [thumbWidth, thumbHeight];
if (containerSize.width > containerSize.height) { if (containerSize.width > containerSize.height) {
this.direction_ = ZoomSlider.Direction_.HORIZONTAL; this.direction_ = Direction.HORIZONTAL;
this.widthLimit_ = containerSize.width - thumbWidth; this.widthLimit_ = containerSize.width - thumbWidth;
} else { } else {
this.direction_ = ZoomSlider.Direction_.VERTICAL; this.direction_ = Direction.VERTICAL;
this.heightLimit_ = containerSize.height - thumbHeight; this.heightLimit_ = containerSize.height - thumbHeight;
} }
this.sliderInitialized_ = true; this.sliderInitialized_ = true;
@@ -313,7 +311,7 @@ ZoomSlider.prototype.setThumbPosition_ = function(res) {
const position = this.getPositionForResolution_(res); const position = this.getPositionForResolution_(res);
const thumb = this.element.firstElementChild; const thumb = this.element.firstElementChild;
if (this.direction_ == ZoomSlider.Direction_.HORIZONTAL) { if (this.direction_ == Direction.HORIZONTAL) {
thumb.style.left = this.widthLimit_ * position + 'px'; thumb.style.left = this.widthLimit_ * position + 'px';
} else { } else {
thumb.style.top = this.heightLimit_ * position + 'px'; thumb.style.top = this.heightLimit_ * position + 'px';
@@ -333,7 +331,7 @@ ZoomSlider.prototype.setThumbPosition_ = function(res) {
*/ */
ZoomSlider.prototype.getRelativePosition_ = function(x, y) { ZoomSlider.prototype.getRelativePosition_ = function(x, y) {
let amount; let amount;
if (this.direction_ === ZoomSlider.Direction_.HORIZONTAL) { if (this.direction_ === Direction.HORIZONTAL) {
amount = x / this.widthLimit_; amount = x / this.widthLimit_;
} else { } else {
amount = y / this.heightLimit_; amount = y / this.heightLimit_;
@@ -369,4 +367,5 @@ ZoomSlider.prototype.getPositionForResolution_ = function(res) {
const fn = this.getMap().getView().getValueForResolutionFunction(); const fn = this.getMap().getView().getValueForResolutionFunction();
return 1 - fn(res); return 1 - fn(res);
}; };
export default ZoomSlider; export default ZoomSlider;