diff --git a/src/ol/control/FullScreen.js b/src/ol/control/FullScreen.js index cc8a093ba4..70ed0e3bef 100644 --- a/src/ol/control/FullScreen.js +++ b/src/ol/control/FullScreen.js @@ -8,6 +8,30 @@ import {replaceNode} from '../dom.js'; import {listen} from '../events.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 * 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); if (map) { this.listenerKeys.push(listen(document, - FullScreen.getChangeType_(), + getChangeType(), 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; diff --git a/src/ol/control/MousePosition.js b/src/ol/control/MousePosition.js index a1e46c4074..045eb8d52b 100644 --- a/src/ol/control/MousePosition.js +++ b/src/ol/control/MousePosition.js @@ -9,6 +9,18 @@ import BaseObject from '../Object.js'; import Control from '../control/Control.js'; import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js'; + +/** + * @type {string} + */ +const PROJECTION = 'projection'; + +/** + * @type {string} + */ +const COORDINATE_FORMAT = 'coordinateFormat'; + + /** * @classdesc * 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, - BaseObject.getChangeEventType(MousePosition.Property_.PROJECTION), + BaseObject.getChangeEventType(PROJECTION), this.handleProjectionChanged_, this); if (options.coordinateFormat) { @@ -122,7 +134,7 @@ MousePosition.prototype.handleProjectionChanged_ = function() { */ MousePosition.prototype.getCoordinateFormat = function() { 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() { 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 */ 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 */ 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; diff --git a/src/ol/control/ScaleLine.js b/src/ol/control/ScaleLine.js index fa92f9069e..1c6fc34399 100644 --- a/src/ol/control/ScaleLine.js +++ b/src/ol/control/ScaleLine.js @@ -11,6 +11,20 @@ import {listen} from '../events.js'; import {getPointResolution, METERS_PER_UNIT} from '../proj.js'; import Units from '../proj/Units.js'; + +/** + * @type {string} + */ +const UNITS = 'units'; + + +/** + * @const + * @type {Array.} + */ +const LEADING_DIGITS = [1, 2, 5]; + + /** * @classdesc * A control displaying rough y-axis distances, calculated for the center of the @@ -86,7 +100,7 @@ const ScaleLine = function(opt_options) { }); listen( - this, BaseObject.getChangeEventType(ScaleLine.Property_.UNITS), + this, BaseObject.getChangeEventType(UNITS), this.handleUnitsChanged_, this); this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) || @@ -97,13 +111,6 @@ const ScaleLine = function(opt_options) { inherits(ScaleLine, Control); -/** - * @const - * @type {Array.} - */ -ScaleLine.LEADING_DIGITS = [1, 2, 5]; - - /** * Return the units to use in the scale line. * @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() { 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 */ 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)); let count, width; while (true) { - count = ScaleLine.LEADING_DIGITS[((i % 3) + 3) % 3] * + count = LEADING_DIGITS[((i % 3) + 3) % 3] * Math.pow(10, Math.floor(i / 3)); width = Math.round(count / pointResolution); if (isNaN(width)) { @@ -275,12 +282,4 @@ ScaleLine.prototype.updateElement_ = function() { }; - -/** - * @enum {string} - * @private - */ -ScaleLine.Property_ = { - UNITS: 'units' -}; export default ScaleLine; diff --git a/src/ol/control/ZoomSlider.js b/src/ol/control/ZoomSlider.js index acdc81ba87..26556cceaa 100644 --- a/src/ol/control/ZoomSlider.js +++ b/src/ol/control/ZoomSlider.js @@ -1,8 +1,6 @@ /** * @module ol/control/ZoomSlider */ -// FIXME should possibly show tooltip when dragging? - import {inherits} from '../index.js'; import ViewHint from '../ViewHint.js'; import Control from '../control/Control.js'; @@ -15,6 +13,18 @@ import {clamp} from '../math.js'; import PointerEventType from '../pointer/EventType.js'; import PointerEventHandler from '../pointer/PointerEventHandler.js'; + +/** + * The enum for available directions. + * + * @enum {number} + */ +const Direction = { + VERTICAL: 0, + HORIZONTAL: 1 +}; + + /** * @classdesc * 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 - * container and defaults to ol.control.ZoomSlider.Direction_.VERTICAL. + * container and defaults to Direction.VERTICAL. * - * @type {ol.control.ZoomSlider.Direction_} + * @type {Direction} * @private */ - this.direction_ = ZoomSlider.Direction_.VERTICAL; + this.direction_ = Direction.VERTICAL; /** * @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 */ @@ -192,10 +190,10 @@ ZoomSlider.prototype.initSlider_ = function() { this.thumbSize_ = [thumbWidth, thumbHeight]; if (containerSize.width > containerSize.height) { - this.direction_ = ZoomSlider.Direction_.HORIZONTAL; + this.direction_ = Direction.HORIZONTAL; this.widthLimit_ = containerSize.width - thumbWidth; } else { - this.direction_ = ZoomSlider.Direction_.VERTICAL; + this.direction_ = Direction.VERTICAL; this.heightLimit_ = containerSize.height - thumbHeight; } this.sliderInitialized_ = true; @@ -313,7 +311,7 @@ ZoomSlider.prototype.setThumbPosition_ = function(res) { const position = this.getPositionForResolution_(res); const thumb = this.element.firstElementChild; - if (this.direction_ == ZoomSlider.Direction_.HORIZONTAL) { + if (this.direction_ == Direction.HORIZONTAL) { thumb.style.left = this.widthLimit_ * position + 'px'; } else { thumb.style.top = this.heightLimit_ * position + 'px'; @@ -333,7 +331,7 @@ ZoomSlider.prototype.setThumbPosition_ = function(res) { */ ZoomSlider.prototype.getRelativePosition_ = function(x, y) { let amount; - if (this.direction_ === ZoomSlider.Direction_.HORIZONTAL) { + if (this.direction_ === Direction.HORIZONTAL) { amount = x / this.widthLimit_; } else { amount = y / this.heightLimit_; @@ -369,4 +367,5 @@ ZoomSlider.prototype.getPositionForResolution_ = function(res) { const fn = this.getMap().getView().getValueForResolutionFunction(); return 1 - fn(res); }; + export default ZoomSlider;