diff --git a/src/ol/Object.js b/src/ol/Object.js index 5e664fb51f..67ccb3c354 100644 --- a/src/ol/Object.js +++ b/src/ol/Object.js @@ -76,10 +76,9 @@ inherits(BaseObject, Observable); /** - * @private * @type {Object.} */ -BaseObject.changeEventTypeCache_ = {}; +const changeEventTypeCache = {}; /** @@ -87,9 +86,9 @@ BaseObject.changeEventTypeCache_ = {}; * @return {string} Change name. */ BaseObject.getChangeEventType = function(key) { - return BaseObject.changeEventTypeCache_.hasOwnProperty(key) ? - BaseObject.changeEventTypeCache_[key] : - (BaseObject.changeEventTypeCache_[key] = 'change:' + key); + return changeEventTypeCache.hasOwnProperty(key) ? + changeEventTypeCache[key] : + (changeEventTypeCache[key] = 'change:' + key); }; diff --git a/src/ol/View.js b/src/ol/View.js index a9bcb0bd05..0200aaf99b 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -138,7 +138,7 @@ View.prototype.applyOptions_ = function(options) { properties[ViewProperty.CENTER] = options.center !== undefined ? options.center : null; - const resolutionConstraintInfo = View.createResolutionConstraint_( + const resolutionConstraintInfo = createResolutionConstraint( options); /** @@ -171,9 +171,9 @@ View.prototype.applyOptions_ = function(options) { */ this.minZoom_ = resolutionConstraintInfo.minZoom; - const centerConstraint = View.createCenterConstraint_(options); + const centerConstraint = createCenterConstraint(options); const resolutionConstraint = resolutionConstraintInfo.constraint; - const rotationConstraint = View.createRotationConstraint_(options); + const rotationConstraint = createRotationConstraint(options); /** * @private @@ -1088,25 +1088,23 @@ View.prototype.setZoom = function(zoom) { /** * @param {olx.ViewOptions} options View options. - * @private * @return {ol.CenterConstraintType} The constraint. */ -View.createCenterConstraint_ = function(options) { +export function createCenterConstraint(options) { if (options.extent !== undefined) { return CenterConstraint.createExtent(options.extent); } else { return CenterConstraint.none; } -}; +} /** - * @private * @param {olx.ViewOptions} options View options. * @return {{constraint: ol.ResolutionConstraintType, maxResolution: number, * minResolution: number, zoomFactor: number}} The constraint. */ -View.createResolutionConstraint_ = function(options) { +export function createResolutionConstraint(options) { let resolutionConstraint; let maxResolution; let minResolution; @@ -1180,15 +1178,14 @@ View.createResolutionConstraint_ = function(options) { } return {constraint: resolutionConstraint, maxResolution: maxResolution, minResolution: minResolution, minZoom: minZoom, zoomFactor: zoomFactor}; -}; +} /** - * @private * @param {olx.ViewOptions} options View options. * @return {ol.RotationConstraintType} Rotation constraint. */ -View.createRotationConstraint_ = function(options) { +export function createRotationConstraint(options) { const enableRotation = options.enableRotation !== undefined ? options.enableRotation : true; if (enableRotation) { @@ -1205,7 +1202,7 @@ View.createRotationConstraint_ = function(options) { } else { return RotationConstraint.disable; } -}; +} /** diff --git a/src/ol/interaction/DragAndDrop.js b/src/ol/interaction/DragAndDrop.js index e1b114e49b..a5b51d2aad 100644 --- a/src/ol/interaction/DragAndDrop.js +++ b/src/ol/interaction/DragAndDrop.js @@ -11,6 +11,20 @@ import EventType from '../events/EventType.js'; import Interaction from '../interaction/Interaction.js'; import {get as getProjection} from '../proj.js'; + +/** + * @enum {string} + */ +const DragAndDropEventType = { + /** + * Triggered when features are added + * @event ol.interaction.DragAndDrop.Event#addfeatures + * @api + */ + ADD_FEATURES: 'addfeatures' +}; + + /** * @classdesc * Handles input of vector data by drag and drop. @@ -69,9 +83,8 @@ inherits(DragAndDrop, Interaction); /** * @param {Event} event Event. * @this {ol.interaction.DragAndDrop} - * @private */ -DragAndDrop.handleDrop_ = function(event) { +function handleDrop(event) { const files = event.dataTransfer.files; let i, ii, file; for (i = 0, ii = files.length; i < ii; ++i) { @@ -81,18 +94,17 @@ DragAndDrop.handleDrop_ = function(event) { this.handleResult_.bind(this, file)); reader.readAsText(file); } -}; +} /** * @param {Event} event Event. - * @private */ -DragAndDrop.handleStop_ = function(event) { +function handleStop(event) { event.stopPropagation(); event.preventDefault(); event.dataTransfer.dropEffect = 'copy'; -}; +} /** @@ -135,7 +147,7 @@ DragAndDrop.prototype.handleResult_ = function(file, event) { } this.dispatchEvent( new DragAndDrop.Event( - DragAndDrop.EventType_.ADD_FEATURES, file, + DragAndDropEventType.ADD_FEATURES, file, features, projection)); }; @@ -160,13 +172,13 @@ DragAndDrop.prototype.registerListeners_ = function() { const dropArea = this.target ? this.target : map.getViewport(); this.dropListenKeys_ = [ listen(dropArea, EventType.DROP, - DragAndDrop.handleDrop_, this), + handleDrop, this), listen(dropArea, EventType.DRAGENTER, - DragAndDrop.handleStop_, this), + handleStop, this), listen(dropArea, EventType.DRAGOVER, - DragAndDrop.handleStop_, this), + handleStop, this), listen(dropArea, EventType.DROP, - DragAndDrop.handleStop_, this) + handleStop, this) ]; } }; @@ -224,20 +236,6 @@ DragAndDrop.prototype.unregisterListeners_ = function() { }; -/** - * @enum {string} - * @private - */ -DragAndDrop.EventType_ = { - /** - * Triggered when features are added - * @event ol.interaction.DragAndDrop.Event#addfeatures - * @api - */ - ADD_FEATURES: 'addfeatures' -}; - - /** * @classdesc * Events emitted by {@link ol.interaction.DragAndDrop} instances are instances @@ -246,7 +244,7 @@ DragAndDrop.EventType_ = { * @constructor * @extends {ol.events.Event} * @implements {oli.interaction.DragAndDropEvent} - * @param {ol.interaction.DragAndDrop.EventType_} type Type. + * @param {ol.interaction.DragAndDropEventType} type Type. * @param {File} file File. * @param {Array.=} opt_features Features. * @param {ol.proj.Projection=} opt_projection Projection. diff --git a/src/ol/interaction/DragBox.js b/src/ol/interaction/DragBox.js index 9b069116a1..e22acc9348 100644 --- a/src/ol/interaction/DragBox.js +++ b/src/ol/interaction/DragBox.js @@ -8,6 +8,34 @@ import {always, mouseOnly, mouseActionButton} from '../events/condition.js'; import PointerInteraction from '../interaction/Pointer.js'; import RenderBox from '../render/Box.js'; + +/** + * @enum {string} + */ +const DragBoxEventType = { + /** + * Triggered upon drag box start. + * @event ol.interaction.DragBox.Event#boxstart + * @api + */ + BOXSTART: 'boxstart', + + /** + * Triggered on drag when box is active. + * @event ol.interaction.DragBox.Event#boxdrag + * @api + */ + BOXDRAG: 'boxdrag', + + /** + * Triggered upon drag box end. + * @event ol.interaction.DragBox.Event#boxend + * @api + */ + BOXEND: 'boxend' +}; + + /** * @classdesc * Allows the user to draw a vector box by clicking and dragging on the map, @@ -28,9 +56,9 @@ import RenderBox from '../render/Box.js'; const DragBox = function(opt_options) { PointerInteraction.call(this, { - handleDownEvent: DragBox.handleDownEvent_, - handleDragEvent: DragBox.handleDragEvent_, - handleUpEvent: DragBox.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleUpEvent: handleUpEvent }); const options = opt_options ? opt_options : {}; @@ -90,18 +118,17 @@ DragBox.defaultBoxEndCondition = function(mapBrowserEvent, startPixel, endPixel) /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.DragBox} - * @private */ -DragBox.handleDragEvent_ = function(mapBrowserEvent) { +function handleDragEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return; } this.box_.setPixels(this.startPixel_, mapBrowserEvent.pixel); - this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXDRAG, + this.dispatchEvent(new DragBox.Event(DragBoxEventType.BOXDRAG, mapBrowserEvent.coordinate, mapBrowserEvent)); -}; +} /** @@ -127,9 +154,8 @@ DragBox.prototype.onBoxEnd = nullFunction; * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.DragBox} - * @private */ -DragBox.handleUpEvent_ = function(mapBrowserEvent) { +function handleUpEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return true; } @@ -139,20 +165,19 @@ DragBox.handleUpEvent_ = function(mapBrowserEvent) { if (this.boxEndCondition_(mapBrowserEvent, this.startPixel_, mapBrowserEvent.pixel)) { this.onBoxEnd(mapBrowserEvent); - this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXEND, + this.dispatchEvent(new DragBox.Event(DragBoxEventType.BOXEND, mapBrowserEvent.coordinate, mapBrowserEvent)); } return false; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.DragBox} - * @private */ -DragBox.handleDownEvent_ = function(mapBrowserEvent) { +function handleDownEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return false; } @@ -162,41 +187,13 @@ DragBox.handleDownEvent_ = function(mapBrowserEvent) { this.startPixel_ = mapBrowserEvent.pixel; this.box_.setMap(mapBrowserEvent.map); this.box_.setPixels(this.startPixel_, this.startPixel_); - this.dispatchEvent(new DragBox.Event(DragBox.EventType_.BOXSTART, + this.dispatchEvent(new DragBox.Event(DragBoxEventType.BOXSTART, mapBrowserEvent.coordinate, mapBrowserEvent)); return true; } else { return false; } -}; - - -/** - * @enum {string} - * @private - */ -DragBox.EventType_ = { - /** - * Triggered upon drag box start. - * @event ol.interaction.DragBox.Event#boxstart - * @api - */ - BOXSTART: 'boxstart', - - /** - * Triggered on drag when box is active. - * @event ol.interaction.DragBox.Event#boxdrag - * @api - */ - BOXDRAG: 'boxdrag', - - /** - * Triggered upon drag box end. - * @event ol.interaction.DragBox.Event#boxend - * @api - */ - BOXEND: 'boxend' -}; +} /** diff --git a/src/ol/interaction/DragPan.js b/src/ol/interaction/DragPan.js index c7c6569489..d3c07aede9 100644 --- a/src/ol/interaction/DragPan.js +++ b/src/ol/interaction/DragPan.js @@ -21,9 +21,9 @@ import PointerInteraction from '../interaction/Pointer.js'; const DragPan = function(opt_options) { PointerInteraction.call(this, { - handleDownEvent: DragPan.handleDownEvent_, - handleDragEvent: DragPan.handleDragEvent_, - handleUpEvent: DragPan.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleUpEvent: handleUpEvent }); const options = opt_options ? opt_options : {}; @@ -64,9 +64,8 @@ inherits(DragPan, PointerInteraction); /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.DragPan} - * @private */ -DragPan.handleDragEvent_ = function(mapBrowserEvent) { +function handleDragEvent(mapBrowserEvent) { const targetPointers = this.targetPointers; const centroid = PointerInteraction.centroid(targetPointers); @@ -94,16 +93,15 @@ DragPan.handleDragEvent_ = function(mapBrowserEvent) { } this.lastCentroid = centroid; this.lastPointersCount_ = targetPointers.length; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.DragPan} - * @private */ -DragPan.handleUpEvent_ = function(mapBrowserEvent) { +function handleUpEvent(mapBrowserEvent) { const map = mapBrowserEvent.map; const view = map.getView(); if (this.targetPointers.length === 0) { @@ -133,16 +131,15 @@ DragPan.handleUpEvent_ = function(mapBrowserEvent) { this.lastCentroid = null; return true; } -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.DragPan} - * @private */ -DragPan.handleDownEvent_ = function(mapBrowserEvent) { +function handleDownEvent(mapBrowserEvent) { if (this.targetPointers.length > 0 && this.condition_(mapBrowserEvent)) { const map = mapBrowserEvent.map; const view = map.getView(); @@ -164,7 +161,7 @@ DragPan.handleDownEvent_ = function(mapBrowserEvent) { } else { return false; } -}; +} /** diff --git a/src/ol/interaction/DragRotate.js b/src/ol/interaction/DragRotate.js index f856c5d2b0..be9f85b5cc 100644 --- a/src/ol/interaction/DragRotate.js +++ b/src/ol/interaction/DragRotate.js @@ -27,9 +27,9 @@ const DragRotate = function(opt_options) { const options = opt_options ? opt_options : {}; PointerInteraction.call(this, { - handleDownEvent: DragRotate.handleDownEvent_, - handleDragEvent: DragRotate.handleDragEvent_, - handleUpEvent: DragRotate.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleUpEvent: handleUpEvent }); /** @@ -57,9 +57,8 @@ inherits(DragRotate, PointerInteraction); /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.DragRotate} - * @private */ -DragRotate.handleDragEvent_ = function(mapBrowserEvent) { +function handleDragEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return; } @@ -80,16 +79,15 @@ DragRotate.handleDragEvent_ = function(mapBrowserEvent) { view, rotation - delta); } this.lastAngle_ = theta; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.DragRotate} - * @private */ -DragRotate.handleUpEvent_ = function(mapBrowserEvent) { +function handleUpEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return true; } @@ -101,16 +99,15 @@ DragRotate.handleUpEvent_ = function(mapBrowserEvent) { Interaction.rotate(view, rotation, undefined, this.duration_); return false; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.DragRotate} - * @private */ -DragRotate.handleDownEvent_ = function(mapBrowserEvent) { +function handleDownEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return false; } @@ -123,7 +120,7 @@ DragRotate.handleDownEvent_ = function(mapBrowserEvent) { } else { return false; } -}; +} /** diff --git a/src/ol/interaction/DragRotateAndZoom.js b/src/ol/interaction/DragRotateAndZoom.js index befa311407..be5a55bf2a 100644 --- a/src/ol/interaction/DragRotateAndZoom.js +++ b/src/ol/interaction/DragRotateAndZoom.js @@ -28,9 +28,9 @@ const DragRotateAndZoom = function(opt_options) { const options = opt_options ? opt_options : {}; PointerInteraction.call(this, { - handleDownEvent: DragRotateAndZoom.handleDownEvent_, - handleDragEvent: DragRotateAndZoom.handleDragEvent_, - handleUpEvent: DragRotateAndZoom.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleUpEvent: handleUpEvent }); /** @@ -71,9 +71,8 @@ inherits(DragRotateAndZoom, PointerInteraction); /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.DragRotateAndZoom} - * @private */ -DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) { +function handleDragEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return; } @@ -100,16 +99,15 @@ DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) { this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; } this.lastMagnitude_ = magnitude; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.DragRotateAndZoom} - * @private */ -DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) { +function handleUpEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return true; } @@ -123,16 +121,15 @@ DragRotateAndZoom.handleUpEvent_ = function(mapBrowserEvent) { undefined, this.duration_, direction); this.lastScaleDelta_ = 0; return false; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.DragRotateAndZoom} - * @private */ -DragRotateAndZoom.handleDownEvent_ = function(mapBrowserEvent) { +function handleDownEvent(mapBrowserEvent) { if (!mouseOnly(mapBrowserEvent)) { return false; } @@ -145,5 +142,6 @@ DragRotateAndZoom.handleDownEvent_ = function(mapBrowserEvent) { } else { return false; } -}; +} + export default DragRotateAndZoom; diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 7ac7db9531..8fcbbb5b29 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -29,6 +29,20 @@ import VectorLayer from '../layer/Vector.js'; import VectorSource from '../source/Vector.js'; import Style from '../style/Style.js'; + +/** + * Draw mode. This collapses multi-part geometry types with their single-part + * cousins. + * @enum {string} + */ +const Mode = { + POINT: 'Point', + LINE_STRING: 'LineString', + POLYGON: 'Polygon', + CIRCLE: 'Circle' +}; + + /** * @classdesc * Interaction for drawing feature geometries. @@ -42,9 +56,9 @@ import Style from '../style/Style.js'; const Draw = function(options) { PointerInteraction.call(this, { - handleDownEvent: Draw.handleDownEvent_, - handleEvent: Draw.handleEvent, - handleUpEvent: Draw.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleEvent: handleEvent, + handleUpEvent: handleUpEvent }); /** @@ -107,10 +121,10 @@ const Draw = function(options) { /** * Drawing mode (derived from geometry type. - * @type {ol.interaction.Draw.Mode_} + * @type {ol.interaction.Mode} * @private */ - this.mode_ = Draw.getMode_(this.type_); + this.mode_ = getMode(this.type_); /** * Stop click, singleclick, and doubleclick events from firing during drawing. @@ -129,7 +143,7 @@ const Draw = function(options) { */ this.minPoints_ = options.minPoints ? options.minPoints : - (this.mode_ === Draw.Mode_.POLYGON ? 3 : 2); + (this.mode_ === Mode.POLYGON ? 3 : 2); /** * The number of points that can be drawn before a polygon ring or line string @@ -166,11 +180,11 @@ const Draw = function(options) { } else { let Constructor; const mode = this.mode_; - if (mode === Draw.Mode_.POINT) { + if (mode === Mode.POINT) { Constructor = Point; - } else if (mode === Draw.Mode_.LINE_STRING) { + } else if (mode === Mode.LINE_STRING) { Constructor = LineString; - } else if (mode === Draw.Mode_.POLYGON) { + } else if (mode === Mode.POLYGON) { Constructor = Polygon; } /** @@ -182,7 +196,7 @@ const Draw = function(options) { geometryFunction = function(coordinates, opt_geometry) { let geometry = opt_geometry; if (geometry) { - if (mode === Draw.Mode_.POLYGON) { + if (mode === Mode.POLYGON) { if (coordinates[0].length) { // Add a closing coordinate to match the first geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]); @@ -342,12 +356,12 @@ Draw.prototype.setMap = function(map) { * @this {ol.interaction.Draw} * @api */ -Draw.handleEvent = function(event) { +export function handleEvent(event) { if (event.originalEvent.type === EventType.CONTEXTMENU) { // Avoid context menu for long taps when drawing on mobile event.preventDefault(); } - this.freehand_ = this.mode_ !== Draw.Mode_.POINT && this.freehandCondition_(event); + this.freehand_ = this.mode_ !== Mode.POINT && this.freehandCondition_(event); let move = event.type === MapBrowserEventType.POINTERMOVE; let pass = true; if (this.lastDragTime_ && event.type === MapBrowserEventType.POINTERDRAG) { @@ -385,16 +399,15 @@ Draw.handleEvent = function(event) { } return PointerInteraction.handleEvent.call(this, event) && pass; -}; +} /** * @param {ol.MapBrowserPointerEvent} event Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.Draw} - * @private */ -Draw.handleDownEvent_ = function(event) { +function handleDownEvent(event) { this.shouldHandle_ = !this.freehand_; if (this.freehand_) { @@ -414,16 +427,15 @@ Draw.handleDownEvent_ = function(event) { } else { return false; } -}; +} /** * @param {ol.MapBrowserPointerEvent} event Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.Draw} - * @private */ -Draw.handleUpEvent_ = function(event) { +function handleUpEvent(event) { let pass = true; if (this.downTimeout_) { @@ -433,12 +445,12 @@ Draw.handleUpEvent_ = function(event) { this.handlePointerMove_(event); - const circleMode = this.mode_ === Draw.Mode_.CIRCLE; + const circleMode = this.mode_ === Mode.CIRCLE; if (this.shouldHandle_) { if (!this.finishCoordinate_) { this.startDrawing_(event); - if (this.mode_ === Draw.Mode_.POINT) { + if (this.mode_ === Mode.POINT) { this.finishDrawing(); } } else if (this.freehand_ || circleMode) { @@ -459,7 +471,7 @@ Draw.handleUpEvent_ = function(event) { event.stopPropagation(); } return pass; -}; +} /** @@ -505,9 +517,9 @@ Draw.prototype.atFinish_ = function(event) { if (this.sketchFeature_) { let potentiallyDone = false; let potentiallyFinishCoordinates = [this.finishCoordinate_]; - if (this.mode_ === Draw.Mode_.LINE_STRING) { + if (this.mode_ === Mode.LINE_STRING) { potentiallyDone = this.sketchCoords_.length > this.minPoints_; - } else if (this.mode_ === Draw.Mode_.POLYGON) { + } else if (this.mode_ === Mode.POLYGON) { potentiallyDone = this.sketchCoords_[0].length > this.minPoints_; potentiallyFinishCoordinates = [this.sketchCoords_[0][0], @@ -558,9 +570,9 @@ Draw.prototype.createOrUpdateSketchPoint_ = function(event) { Draw.prototype.startDrawing_ = function(event) { const start = event.coordinate; this.finishCoordinate_ = start; - if (this.mode_ === Draw.Mode_.POINT) { + if (this.mode_ === Mode.POINT) { this.sketchCoords_ = start.slice(); - } else if (this.mode_ === Draw.Mode_.POLYGON) { + } else if (this.mode_ === Mode.POLYGON) { this.sketchCoords_ = [[start.slice(), start.slice()]]; this.sketchLineCoords_ = this.sketchCoords_[0]; } else { @@ -590,9 +602,9 @@ Draw.prototype.modifyDrawing_ = function(event) { let coordinate = event.coordinate; const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); let coordinates, last; - if (this.mode_ === Draw.Mode_.POINT) { + if (this.mode_ === Mode.POINT) { last = this.sketchCoords_; - } else if (this.mode_ === Draw.Mode_.POLYGON) { + } else if (this.mode_ === Mode.POLYGON) { coordinates = this.sketchCoords_[0]; last = coordinates[coordinates.length - 1]; if (this.atFinish_(event)) { @@ -612,7 +624,7 @@ Draw.prototype.modifyDrawing_ = function(event) { } let sketchLineGeom; if (geometry instanceof Polygon && - this.mode_ !== Draw.Mode_.POLYGON) { + this.mode_ !== Mode.POLYGON) { if (!this.sketchLine_) { this.sketchLine_ = new Feature(new LineString(null)); } @@ -638,7 +650,7 @@ Draw.prototype.addToDrawing_ = function(event) { const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); let done; let coordinates; - if (this.mode_ === Draw.Mode_.LINE_STRING) { + if (this.mode_ === Mode.LINE_STRING) { this.finishCoordinate_ = coordinate.slice(); coordinates = this.sketchCoords_; if (coordinates.length >= this.maxPoints_) { @@ -650,7 +662,7 @@ Draw.prototype.addToDrawing_ = function(event) { } coordinates.push(coordinate.slice()); this.geometryFunction_(coordinates, geometry); - } else if (this.mode_ === Draw.Mode_.POLYGON) { + } else if (this.mode_ === Mode.POLYGON) { coordinates = this.sketchCoords_[0]; if (coordinates.length >= this.maxPoints_) { if (this.freehand_) { @@ -682,14 +694,14 @@ Draw.prototype.removeLastPoint = function() { } const geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); let coordinates, sketchLineGeom; - if (this.mode_ === Draw.Mode_.LINE_STRING) { + if (this.mode_ === Mode.LINE_STRING) { coordinates = this.sketchCoords_; coordinates.splice(-2, 1); this.geometryFunction_(coordinates, geometry); if (coordinates.length >= 2) { this.finishCoordinate_ = coordinates[coordinates.length - 2].slice(); } - } else if (this.mode_ === Draw.Mode_.POLYGON) { + } else if (this.mode_ === Mode.POLYGON) { coordinates = this.sketchCoords_[0]; coordinates.splice(-2, 1); sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry()); @@ -718,11 +730,11 @@ Draw.prototype.finishDrawing = function() { } let coordinates = this.sketchCoords_; const geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry()); - if (this.mode_ === Draw.Mode_.LINE_STRING) { + if (this.mode_ === Mode.LINE_STRING) { // remove the redundant last point coordinates.pop(); this.geometryFunction_(coordinates, geometry); - } else if (this.mode_ === Draw.Mode_.POLYGON) { + } else if (this.mode_ === Mode.POLYGON) { // remove the redundant last point in ring coordinates[0].pop(); this.geometryFunction_(coordinates, geometry); @@ -899,40 +911,26 @@ Draw.createBox = function() { * Get the drawing mode. The mode for mult-part geometries is the same as for * their single-part cousins. * @param {ol.geom.GeometryType} type Geometry type. - * @return {ol.interaction.Draw.Mode_} Drawing mode. - * @private + * @return {ol.interaction.Mode} Drawing mode. */ -Draw.getMode_ = function(type) { +function getMode(type) { let mode; if (type === GeometryType.POINT || type === GeometryType.MULTI_POINT) { - mode = Draw.Mode_.POINT; + mode = Mode.POINT; } else if (type === GeometryType.LINE_STRING || type === GeometryType.MULTI_LINE_STRING) { - mode = Draw.Mode_.LINE_STRING; + mode = Mode.LINE_STRING; } else if (type === GeometryType.POLYGON || type === GeometryType.MULTI_POLYGON) { - mode = Draw.Mode_.POLYGON; + mode = Mode.POLYGON; } else if (type === GeometryType.CIRCLE) { - mode = Draw.Mode_.CIRCLE; + mode = Mode.CIRCLE; } - return /** @type {!ol.interaction.Draw.Mode_} */ (mode); -}; + return /** @type {!ol.interaction.Mode} */ (mode); +} -/** - * Draw mode. This collapses multi-part geometry types with their single-part - * cousins. - * @enum {string} - * @private - */ -Draw.Mode_ = { - POINT: 'Point', - LINE_STRING: 'LineString', - POLYGON: 'Polygon', - CIRCLE: 'Circle' -}; - /** * @classdesc * Events emitted by {@link ol.interaction.Draw} instances are instances of diff --git a/src/ol/interaction/Extent.js b/src/ol/interaction/Extent.js index 43454729fc..99c275f4d6 100644 --- a/src/ol/interaction/Extent.js +++ b/src/ol/interaction/Extent.js @@ -82,10 +82,10 @@ const ExtentInteraction = function(opt_options) { /* Inherit ol.interaction.Pointer */ PointerInteraction.call(this, { - handleDownEvent: ExtentInteraction.handleDownEvent_, - handleDragEvent: ExtentInteraction.handleDragEvent_, - handleEvent: ExtentInteraction.handleEvent_, - handleUpEvent: ExtentInteraction.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleEvent: handleEvent, + handleUpEvent: handleUpEvent }); /** @@ -98,7 +98,7 @@ const ExtentInteraction = function(opt_options) { useSpatialIndex: false, wrapX: !!opt_options.wrapX }), - style: opt_options.boxStyle ? opt_options.boxStyle : ExtentInteraction.getDefaultExtentStyleFunction_(), + style: opt_options.boxStyle ? opt_options.boxStyle : getDefaultExtentStyleFunction(), updateWhileAnimating: true, updateWhileInteracting: true }); @@ -113,7 +113,7 @@ const ExtentInteraction = function(opt_options) { useSpatialIndex: false, wrapX: !!opt_options.wrapX }), - style: opt_options.pointerStyle ? opt_options.pointerStyle : ExtentInteraction.getDefaultPointerStyleFunction_(), + style: opt_options.pointerStyle ? opt_options.pointerStyle : getDefaultPointerStyleFunction(), updateWhileAnimating: true, updateWhileInteracting: true }); @@ -129,9 +129,8 @@ inherits(ExtentInteraction, PointerInteraction); * @param {ol.MapBrowserEvent} mapBrowserEvent Event. * @return {boolean} Propagate event? * @this {ol.interaction.Extent} - * @private */ -ExtentInteraction.handleEvent_ = function(mapBrowserEvent) { +function handleEvent(mapBrowserEvent) { if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) { return true; } @@ -143,15 +142,14 @@ ExtentInteraction.handleEvent_ = function(mapBrowserEvent) { PointerInteraction.handleEvent.call(this, mapBrowserEvent); //return false to stop propagation return false; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Event handled? * @this {ol.interaction.Extent} - * @private */ -ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) { +function handleDownEvent(mapBrowserEvent) { const pixel = mapBrowserEvent.pixel; const map = mapBrowserEvent.map; @@ -183,15 +181,15 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) { //snap to point if (x !== null && y !== null) { - this.pointerHandler_ = ExtentInteraction.getPointHandler_(getOpposingPoint(vertex)); + this.pointerHandler_ = getPointHandler(getOpposingPoint(vertex)); //snap to edge } else if (x !== null) { - this.pointerHandler_ = ExtentInteraction.getEdgeHandler_( + this.pointerHandler_ = getEdgeHandler( getOpposingPoint([x, extent[1]]), getOpposingPoint([x, extent[3]]) ); } else if (y !== null) { - this.pointerHandler_ = ExtentInteraction.getEdgeHandler_( + this.pointerHandler_ = getEdgeHandler( getOpposingPoint([extent[0], y]), getOpposingPoint([extent[2], y]) ); @@ -200,33 +198,31 @@ ExtentInteraction.handleDownEvent_ = function(mapBrowserEvent) { } else { vertex = map.getCoordinateFromPixel(pixel); this.setExtent([vertex[0], vertex[1], vertex[0], vertex[1]]); - this.pointerHandler_ = ExtentInteraction.getPointHandler_(vertex); + this.pointerHandler_ = getPointHandler(vertex); } return true; //event handled; start downup sequence -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Event handled? * @this {ol.interaction.Extent} - * @private */ -ExtentInteraction.handleDragEvent_ = function(mapBrowserEvent) { +function handleDragEvent(mapBrowserEvent) { if (this.pointerHandler_) { const pixelCoordinate = mapBrowserEvent.coordinate; this.setExtent(this.pointerHandler_(pixelCoordinate)); this.createOrUpdatePointerFeature_(pixelCoordinate); } return true; -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.Extent} - * @private */ -ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) { +function handleUpEvent(mapBrowserEvent) { this.pointerHandler_ = null; //If bbox is zero area, set to null; const extent = this.getExtent(); @@ -234,52 +230,48 @@ ExtentInteraction.handleUpEvent_ = function(mapBrowserEvent) { this.setExtent(null); } return false; //Stop handling downup sequence -}; +} /** * Returns the default style for the drawn bbox * * @return {ol.StyleFunction} Default Extent style - * @private */ -ExtentInteraction.getDefaultExtentStyleFunction_ = function() { +function getDefaultExtentStyleFunction() { const style = Style.createDefaultEditing(); return function(feature, resolution) { return style[GeometryType.POLYGON]; }; -}; +} /** * Returns the default style for the pointer * * @return {ol.StyleFunction} Default pointer style - * @private */ -ExtentInteraction.getDefaultPointerStyleFunction_ = function() { +function getDefaultPointerStyleFunction() { const style = Style.createDefaultEditing(); return function(feature, resolution) { return style[GeometryType.POINT]; }; -}; +} /** * @param {ol.Coordinate} fixedPoint corner that will be unchanged in the new extent * @returns {function (ol.Coordinate): ol.Extent} event handler - * @private */ -ExtentInteraction.getPointHandler_ = function(fixedPoint) { +function getPointHandler(fixedPoint) { return function(point) { return boundingExtent([fixedPoint, point]); }; -}; +} /** * @param {ol.Coordinate} fixedP1 first corner that will be unchanged in the new extent * @param {ol.Coordinate} fixedP2 second corner that will be unchanged in the new extent * @returns {function (ol.Coordinate): ol.Extent|null} event handler - * @private */ -ExtentInteraction.getEdgeHandler_ = function(fixedP1, fixedP2) { +function getEdgeHandler(fixedP1, fixedP2) { if (fixedP1[0] == fixedP2[0]) { return function(point) { return boundingExtent([fixedP1, [point[0], fixedP2[1]]]); @@ -291,21 +283,20 @@ ExtentInteraction.getEdgeHandler_ = function(fixedP1, fixedP2) { } else { return null; } -}; +} /** * @param {ol.Extent} extent extent * @returns {Array>} extent line segments - * @private */ -ExtentInteraction.getSegments_ = function(extent) { +function getSegments(extent) { return [ [[extent[0], extent[1]], [extent[0], extent[3]]], [[extent[0], extent[3]], [extent[2], extent[3]]], [[extent[2], extent[3]], [extent[2], extent[1]]], [[extent[2], extent[1]], [extent[0], extent[1]]] ]; -}; +} /** * @param {ol.Pixel} pixel cursor location @@ -322,7 +313,7 @@ ExtentInteraction.prototype.snapToVertex_ = function(pixel, map) { const extent = this.getExtent(); if (extent) { //convert extents to line segments and find the segment closest to pixelCoordinate - const segments = ExtentInteraction.getSegments_(extent); + const segments = getSegments(extent); segments.sort(sortByDistance); const closestSegment = segments[0]; diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 7c4bf026db..6ec3224024 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -46,10 +46,10 @@ import Style from '../style/Style.js'; const Modify = function(options) { PointerInteraction.call(this, { - handleDownEvent: Modify.handleDownEvent_, - handleDragEvent: Modify.handleDragEvent_, + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, handleEvent: Modify.handleEvent, - handleUpEvent: Modify.handleUpEvent_ + handleUpEvent: handleUpEvent }); /** @@ -592,20 +592,18 @@ Modify.prototype.createOrUpdateVertexFeature_ = function(coordinates) { * @param {ol.ModifySegmentDataType} a The first segment data. * @param {ol.ModifySegmentDataType} b The second segment data. * @return {number} The difference in indexes. - * @private */ -Modify.compareIndexes_ = function(a, b) { +function compareIndexes(a, b) { return a.index - b.index; -}; +} /** * @param {ol.MapBrowserPointerEvent} evt Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.Modify} - * @private */ -Modify.handleDownEvent_ = function(evt) { +function handleDownEvent(evt) { if (!this.condition_(evt)) { return false; } @@ -621,7 +619,7 @@ Modify.handleDownEvent_ = function(evt) { const vertexExtent = boundingExtent([vertex]); const segmentDataMatches = this.rBush_.getInExtent(vertexExtent); const componentSegments = {}; - segmentDataMatches.sort(Modify.compareIndexes_); + segmentDataMatches.sort(compareIndexes); for (let i = 0, ii = segmentDataMatches.length; i < ii; ++i) { const segmentDataMatch = segmentDataMatches[i]; const segment = segmentDataMatch.segment; @@ -636,7 +634,7 @@ Modify.handleDownEvent_ = function(evt) { if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE && segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { - const closestVertex = Modify.closestOnSegmentData_(pixelCoordinate, segmentDataMatch); + const closestVertex = closestOnSegmentData(pixelCoordinate, segmentDataMatch); if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) { this.dragSegments_.push([segmentDataMatch, 0]); componentSegments[uid][0] = segmentDataMatch; @@ -673,15 +671,14 @@ Modify.handleDownEvent_ = function(evt) { } } return !!this.vertexFeature_; -}; +} /** * @param {ol.MapBrowserPointerEvent} evt Event. * @this {ol.interaction.Modify} - * @private */ -Modify.handleDragEvent_ = function(evt) { +function handleDragEvent(evt) { this.ignoreNextSingleClick_ = false; this.willModifyFeatures_(evt); @@ -750,16 +747,15 @@ Modify.handleDragEvent_ = function(evt) { } } this.createOrUpdateVertexFeature_(vertex); -}; +} /** * @param {ol.MapBrowserPointerEvent} evt Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.Modify} - * @private */ -Modify.handleUpEvent_ = function(evt) { +function handleUpEvent(evt) { let segmentData; let geometry; for (let i = this.dragSegments_.length - 1; i >= 0; --i) { @@ -785,7 +781,7 @@ Modify.handleUpEvent_ = function(evt) { this.modified_ = false; } return false; -}; +} /** @@ -844,8 +840,8 @@ Modify.prototype.handlePointerMove_ = function(evt) { Modify.prototype.handlePointerAtPixel_ = function(pixel, map) { const pixelCoordinate = map.getCoordinateFromPixel(pixel); const sortByDistance = function(a, b) { - return Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, a) - - Modify.pointDistanceToSegmentDataSquared_(pixelCoordinate, b); + return pointDistanceToSegmentDataSquared(pixelCoordinate, a) - + pointDistanceToSegmentDataSquared(pixelCoordinate, b); }; const box = buffer(createOrUpdateFromCoordinate(pixelCoordinate), @@ -857,7 +853,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) { nodes.sort(sortByDistance); const node = nodes[0]; const closestSegment = node.segment; - let vertex = Modify.closestOnSegmentData_(pixelCoordinate, node); + let vertex = closestOnSegmentData(pixelCoordinate, node); const vertexPixel = map.getPixelFromCoordinate(vertex); let dist = coordinateDistance(pixel, vertexPixel); if (dist <= this.pixelTolerance_) { @@ -915,7 +911,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) { * segment we are calculating the distance to. * @return {number} The square of the distance between a point and a line segment. */ -Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentData) { +function pointDistanceToSegmentDataSquared(pointCoordinates, segmentData) { const geometry = segmentData.geometry; if (geometry.getType() === GeometryType.CIRCLE) { @@ -930,7 +926,7 @@ Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentDa } } return squaredDistanceToSegment(pointCoordinates, segmentData.segment); -}; +} /** * Returns the point closest to a given line segment. @@ -941,7 +937,7 @@ Modify.pointDistanceToSegmentDataSquared_ = function(pointCoordinates, segmentDa * segment which should contain the closest point. * @return {ol.Coordinate} The point closest to the specified line segment. */ -Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) { +function closestOnSegmentData(pointCoordinates, segmentData) { const geometry = segmentData.geometry; if (geometry.getType() === GeometryType.CIRCLE && @@ -949,7 +945,7 @@ Modify.closestOnSegmentData_ = function(pointCoordinates, segmentData) { return geometry.getClosestPoint(pointCoordinates); } return closestOnSegment(pointCoordinates, segmentData.segment); -}; +} /** diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index 43f404f6b3..a7dfe19d8e 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -18,6 +18,15 @@ import {clamp} from '../math.js'; const MAX_DELTA = 1; +/** + * @enum {string} + */ +export const Mode = { + TRACKPAD: 'trackpad', + WHEEL: 'wheel' +}; + + /** * @classdesc * Allows the user to zoom the map by scrolling the mouse wheel. @@ -91,7 +100,7 @@ const MouseWheelZoom = function(opt_options) { /** * @private - * @type {ol.interaction.MouseWheelZoom.Mode_|undefined} + * @type {ol.interaction.Mode|undefined} */ this.mode_ = undefined; @@ -183,11 +192,11 @@ MouseWheelZoom.handleEvent = function(mapBrowserEvent) { if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) { this.mode_ = Math.abs(delta) < 4 ? - MouseWheelZoom.Mode_.TRACKPAD : - MouseWheelZoom.Mode_.WHEEL; + Mode.TRACKPAD : + Mode.WHEEL; } - if (this.mode_ === MouseWheelZoom.Mode_.TRACKPAD) { + if (this.mode_ === Mode.TRACKPAD) { const view = map.getView(); if (this.trackpadTimeoutId_) { clearTimeout(this.trackpadTimeoutId_); @@ -296,12 +305,4 @@ MouseWheelZoom.prototype.setMouseAnchor = function(useAnchor) { }; -/** - * @enum {string} - * @private - */ -MouseWheelZoom.Mode_ = { - TRACKPAD: 'trackpad', - WHEEL: 'wheel' -}; export default MouseWheelZoom; diff --git a/src/ol/interaction/PinchRotate.js b/src/ol/interaction/PinchRotate.js index 83803c0e41..77c07a90d0 100644 --- a/src/ol/interaction/PinchRotate.js +++ b/src/ol/interaction/PinchRotate.js @@ -21,9 +21,9 @@ import RotationConstraint from '../RotationConstraint.js'; const PinchRotate = function(opt_options) { PointerInteraction.call(this, { - handleDownEvent: PinchRotate.handleDownEvent_, - handleDragEvent: PinchRotate.handleDragEvent_, - handleUpEvent: PinchRotate.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleUpEvent: handleUpEvent }); const options = opt_options || {}; @@ -72,9 +72,8 @@ inherits(PinchRotate, PointerInteraction); /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.PinchRotate} - * @private */ -PinchRotate.handleDragEvent_ = function(mapBrowserEvent) { +function handleDragEvent(mapBrowserEvent) { let rotationDelta = 0.0; const touch0 = this.targetPointers[0]; @@ -118,16 +117,15 @@ PinchRotate.handleDragEvent_ = function(mapBrowserEvent) { Interaction.rotateWithoutConstraints(view, rotation + rotationDelta, this.anchor_); } -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.PinchRotate} - * @private */ -PinchRotate.handleUpEvent_ = function(mapBrowserEvent) { +function handleUpEvent(mapBrowserEvent) { if (this.targetPointers.length < 2) { const map = mapBrowserEvent.map; const view = map.getView(); @@ -141,16 +139,15 @@ PinchRotate.handleUpEvent_ = function(mapBrowserEvent) { } else { return true; } -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.PinchRotate} - * @private */ -PinchRotate.handleDownEvent_ = function(mapBrowserEvent) { +function handleDownEvent(mapBrowserEvent) { if (this.targetPointers.length >= 2) { const map = mapBrowserEvent.map; this.anchor_ = null; @@ -164,11 +161,12 @@ PinchRotate.handleDownEvent_ = function(mapBrowserEvent) { } else { return false; } -}; +} /** * @inheritDoc */ PinchRotate.prototype.shouldStopEvent = FALSE; + export default PinchRotate; diff --git a/src/ol/interaction/PinchZoom.js b/src/ol/interaction/PinchZoom.js index 12b3c8a19d..6dcaf30c99 100644 --- a/src/ol/interaction/PinchZoom.js +++ b/src/ol/interaction/PinchZoom.js @@ -20,9 +20,9 @@ import PointerInteraction from '../interaction/Pointer.js'; const PinchZoom = function(opt_options) { PointerInteraction.call(this, { - handleDownEvent: PinchZoom.handleDownEvent_, - handleDragEvent: PinchZoom.handleDragEvent_, - handleUpEvent: PinchZoom.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleUpEvent: handleUpEvent }); const options = opt_options ? opt_options : {}; @@ -65,9 +65,8 @@ inherits(PinchZoom, PointerInteraction); /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.PinchZoom} - * @private */ -PinchZoom.handleDragEvent_ = function(mapBrowserEvent) { +function handleDragEvent(mapBrowserEvent) { let scaleDelta = 1.0; const touch0 = this.targetPointers[0]; @@ -112,16 +111,15 @@ PinchZoom.handleDragEvent_ = function(mapBrowserEvent) { // scale, bypass the resolution constraint map.render(); Interaction.zoomWithoutConstraints(view, newResolution, this.anchor_); -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.PinchZoom} - * @private */ -PinchZoom.handleUpEvent_ = function(mapBrowserEvent) { +function handleUpEvent(mapBrowserEvent) { if (this.targetPointers.length < 2) { const map = mapBrowserEvent.map; const view = map.getView(); @@ -141,16 +139,15 @@ PinchZoom.handleUpEvent_ = function(mapBrowserEvent) { } else { return true; } -}; +} /** * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.PinchZoom} - * @private */ -PinchZoom.handleDownEvent_ = function(mapBrowserEvent) { +function handleDownEvent(mapBrowserEvent) { if (this.targetPointers.length >= 2) { const map = mapBrowserEvent.map; this.anchor_ = null; @@ -163,7 +160,7 @@ PinchZoom.handleDownEvent_ = function(mapBrowserEvent) { } else { return false; } -}; +} /** diff --git a/src/ol/interaction/Select.js b/src/ol/interaction/Select.js index 261ca11bbe..593d4f3a7e 100644 --- a/src/ol/interaction/Select.js +++ b/src/ol/interaction/Select.js @@ -15,6 +15,20 @@ import {clear} from '../obj.js'; import VectorSource from '../source/Vector.js'; import Style from '../style/Style.js'; + +/** + * @enum {string} + */ +const SelectEventType = { + /** + * Triggered when feature(s) has been (de)selected. + * @event ol.interaction.Select.Event#select + * @api + */ + SELECT: 'select' +}; + + /** * @classdesc * Interaction for selecting vector features. By default, selected features are @@ -276,7 +290,7 @@ Select.handleEvent = function(mapBrowserEvent) { } if (selected.length > 0 || deselected.length > 0) { this.dispatchEvent( - new Select.Event(Select.EventType_.SELECT, + new Select.Event(SelectEventType.SELECT, selected, deselected, mapBrowserEvent)); } return pointerMove(mapBrowserEvent); @@ -373,7 +387,7 @@ Select.prototype.removeFeatureLayerAssociation_ = function(feature) { * Events emitted by {@link ol.interaction.Select} instances are instances of * this type. * - * @param {ol.interaction.Select.EventType_} type The event type. + * @param {ol.interaction.SelectEventType} type The event type. * @param {Array.} selected Selected features. * @param {Array.} deselected Deselected features. * @param {ol.MapBrowserEvent} mapBrowserEvent Associated @@ -406,19 +420,8 @@ Select.Event = function(type, selected, deselected, mapBrowserEvent) { */ this.mapBrowserEvent = mapBrowserEvent; }; + inherits(Select.Event, Event); -/** - * @enum {string} - * @private - */ -Select.EventType_ = { - /** - * Triggered when feature(s) has been (de)selected. - * @event ol.interaction.Select.Event#select - * @api - */ - SELECT: 'select' -}; export default Select; diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index b7f22c6bbc..7f9a9ac8e0 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -42,9 +42,9 @@ import RBush from '../structs/RBush.js'; const Snap = function(opt_options) { PointerInteraction.call(this, { - handleEvent: Snap.handleEvent_, + handleEvent: handleEvent, handleDownEvent: TRUE, - handleUpEvent: Snap.handleUpEvent_ + handleUpEvent: handleUpEvent }); const options = opt_options ? opt_options : {}; @@ -586,32 +586,30 @@ Snap.prototype.writePolygonGeometry_ = function(feature, geometry) { * @param {ol.MapBrowserEvent} evt A move event. * @return {boolean} Pass the event to other interactions. * @this {ol.interaction.Snap} - * @private */ -Snap.handleEvent_ = function(evt) { +export function handleEvent(evt) { const result = this.snapTo(evt.pixel, evt.coordinate, evt.map); if (result.snapped) { evt.coordinate = result.vertex.slice(0, 2); evt.pixel = result.vertexPixel; } return PointerInteraction.handleEvent.call(this, evt); -}; +} /** * @param {ol.MapBrowserPointerEvent} evt Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.Snap} - * @private */ -Snap.handleUpEvent_ = function(evt) { +function handleUpEvent(evt) { const featuresToUpdate = getValues(this.pendingFeatures_); if (featuresToUpdate.length) { featuresToUpdate.forEach(this.updateFeature_.bind(this)); this.pendingFeatures_ = {}; } return false; -}; +} /** @@ -627,4 +625,5 @@ Snap.sortByDistance = function(a, b) { squaredDistanceToSegment( this.pixelCoordinate_, b.segment); }; + export default Snap; diff --git a/src/ol/interaction/Translate.js b/src/ol/interaction/Translate.js index 826dc848de..7564086d93 100644 --- a/src/ol/interaction/Translate.js +++ b/src/ol/interaction/Translate.js @@ -24,10 +24,10 @@ import TranslateEventType from '../interaction/TranslateEventType.js'; */ const Translate = function(opt_options) { PointerInteraction.call(this, { - handleDownEvent: Translate.handleDownEvent_, - handleDragEvent: Translate.handleDragEvent_, - handleMoveEvent: Translate.handleMoveEvent_, - handleUpEvent: Translate.handleUpEvent_ + handleDownEvent: handleDownEvent, + handleDragEvent: handleDragEvent, + handleMoveEvent: handleMoveEvent, + handleUpEvent: handleUpEvent }); const options = opt_options ? opt_options : {}; @@ -92,13 +92,12 @@ inherits(Translate, PointerInteraction); * @param {ol.MapBrowserPointerEvent} event Event. * @return {boolean} Start drag sequence? * @this {ol.interaction.Translate} - * @private */ -Translate.handleDownEvent_ = function(event) { +function handleDownEvent(event) { this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map); if (!this.lastCoordinate_ && this.lastFeature_) { this.lastCoordinate_ = event.coordinate; - Translate.handleMoveEvent_.call(this, event); + handleMoveEvent.call(this, event); const features = this.features_ || new Collection([this.lastFeature_]); @@ -109,19 +108,18 @@ Translate.handleDownEvent_ = function(event) { return true; } return false; -}; +} /** * @param {ol.MapBrowserPointerEvent} event Event. * @return {boolean} Stop drag sequence? * @this {ol.interaction.Translate} - * @private */ -Translate.handleUpEvent_ = function(event) { +function handleUpEvent(event) { if (this.lastCoordinate_) { this.lastCoordinate_ = null; - Translate.handleMoveEvent_.call(this, event); + handleMoveEvent.call(this, event); const features = this.features_ || new Collection([this.lastFeature_]); @@ -132,15 +130,14 @@ Translate.handleUpEvent_ = function(event) { return true; } return false; -}; +} /** * @param {ol.MapBrowserPointerEvent} event Event. * @this {ol.interaction.Translate} - * @private */ -Translate.handleDragEvent_ = function(event) { +function handleDragEvent(event) { if (this.lastCoordinate_) { const newCoordinate = event.coordinate; const deltaX = newCoordinate[0] - this.lastCoordinate_[0]; @@ -160,15 +157,14 @@ Translate.handleDragEvent_ = function(event) { TranslateEventType.TRANSLATING, features, newCoordinate)); } -}; +} /** * @param {ol.MapBrowserEvent} event Event. * @this {ol.interaction.Translate} - * @private */ -Translate.handleMoveEvent_ = function(event) { +function handleMoveEvent(event) { const elem = event.map.getViewport(); // Change the cursor to grab/grabbing if hovering any of the features managed @@ -179,7 +175,7 @@ Translate.handleMoveEvent_ = function(event) { } else { elem.classList.remove('ol-grab', 'ol-grabbing'); } -}; +} /** @@ -292,5 +288,7 @@ Translate.Event = function(type, features, coordinate) { */ this.coordinate = coordinate; }; + inherits(Translate.Event, Event); + export default Translate; diff --git a/src/ol/source/Image.js b/src/ol/source/Image.js index 7e332ed484..df934ad189 100644 --- a/src/ol/source/Image.js +++ b/src/ol/source/Image.js @@ -11,6 +11,36 @@ import {equivalent} from '../proj.js'; import ReprojImage from '../reproj/Image.js'; import Source from '../source/Source.js'; + +/** + * @enum {string} + */ +const ImageSourceEventType = { + + /** + * Triggered when an image starts loading. + * @event ol.source.Image.Event#imageloadstart + * @api + */ + IMAGELOADSTART: 'imageloadstart', + + /** + * Triggered when an image finishes loading. + * @event ol.source.Image.Event#imageloadend + * @api + */ + IMAGELOADEND: 'imageloadend', + + /** + * Triggered if image loading results in an error. + * @event ol.source.Image.Event#imageloaderror + * @api + */ + IMAGELOADERROR: 'imageloaderror' + +}; + + /** * @classdesc * Abstract base class; normally only used for creating subclasses and not @@ -144,17 +174,17 @@ ImageSource.prototype.handleImageChange = function(event) { switch (image.getState()) { case ImageState.LOADING: this.dispatchEvent( - new ImageSource.Event(ImageSource.EventType_.IMAGELOADSTART, + new ImageSource.Event(ImageSourceEventType.IMAGELOADSTART, image)); break; case ImageState.LOADED: this.dispatchEvent( - new ImageSource.Event(ImageSource.EventType_.IMAGELOADEND, + new ImageSource.Event(ImageSourceEventType.IMAGELOADEND, image)); break; case ImageState.ERROR: this.dispatchEvent( - new ImageSource.Event(ImageSource.EventType_.IMAGELOADERROR, + new ImageSource.Event(ImageSourceEventType.IMAGELOADERROR, image)); break; default: @@ -200,32 +230,4 @@ ImageSource.Event = function(type, image) { inherits(ImageSource.Event, Event); -/** - * @enum {string} - * @private - */ -ImageSource.EventType_ = { - - /** - * Triggered when an image starts loading. - * @event ol.source.Image.Event#imageloadstart - * @api - */ - IMAGELOADSTART: 'imageloadstart', - - /** - * Triggered when an image finishes loading. - * @event ol.source.Image.Event#imageloadend - * @api - */ - IMAGELOADEND: 'imageloadend', - - /** - * Triggered if image loading results in an error. - * @event ol.source.Image.Event#imageloaderror - * @api - */ - IMAGELOADERROR: 'imageloaderror' - -}; export default ImageSource; diff --git a/src/ol/source/ImageWMS.js b/src/ol/source/ImageWMS.js index e1b1040ff7..e78a7ebe22 100644 --- a/src/ol/source/ImageWMS.js +++ b/src/ol/source/ImageWMS.js @@ -114,9 +114,8 @@ inherits(ImageWMS, ImageSource); /** * @const * @type {ol.Size} - * @private */ -ImageWMS.GETFEATUREINFO_IMAGE_SIZE_ = [101, 101]; +const GETFEATUREINFO_IMAGE_SIZE = [101, 101]; /** @@ -146,7 +145,7 @@ ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, proje } const extent = getForViewAndSize(coordinate, resolution, 0, - ImageWMS.GETFEATUREINFO_IMAGE_SIZE_); + GETFEATUREINFO_IMAGE_SIZE); const baseParams = { 'SERVICE': 'WMS', @@ -164,7 +163,7 @@ ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, proje baseParams[this.v13_ ? 'J' : 'Y'] = y; return this.getRequestUrl_( - extent, ImageWMS.GETFEATUREINFO_IMAGE_SIZE_, + extent, GETFEATUREINFO_IMAGE_SIZE, 1, sourceProjectionObj || projectionObj, baseParams); }; diff --git a/src/ol/source/Raster.js b/src/ol/source/Raster.js index b1133aaa39..c7440b691f 100644 --- a/src/ol/source/Raster.js +++ b/src/ol/source/Raster.js @@ -326,6 +326,14 @@ RasterSource.prototype.onWorkerComplete_ = function(frameState, err, output, dat }; +/** + * A reusable canvas context. + * @type {CanvasRenderingContext2D} + * @private + */ +let sharedContext = null; + + /** * Get image data from a renderer. * @param {ol.renderer.canvas.Layer} renderer Layer renderer. @@ -339,29 +347,21 @@ function getImageData(renderer, frameState, layerState) { } const width = frameState.size[0]; const height = frameState.size[1]; - if (!RasterSource.context_) { - RasterSource.context_ = createCanvasContext2D(width, height); + if (!sharedContext) { + sharedContext = createCanvasContext2D(width, height); } else { - const canvas = RasterSource.context_.canvas; + const canvas = sharedContext.canvas; if (canvas.width !== width || canvas.height !== height) { - RasterSource.context_ = createCanvasContext2D(width, height); + sharedContext = createCanvasContext2D(width, height); } else { - RasterSource.context_.clearRect(0, 0, width, height); + sharedContext.clearRect(0, 0, width, height); } } - renderer.composeFrame(frameState, layerState, RasterSource.context_); - return RasterSource.context_.getImageData(0, 0, width, height); + renderer.composeFrame(frameState, layerState, sharedContext); + return sharedContext.getImageData(0, 0, width, height); } -/** - * A reusable canvas context. - * @type {CanvasRenderingContext2D} - * @private - */ -RasterSource.context_ = null; - - /** * Get a list of layer states from a list of renderers. * @param {Array.} renderers Layer renderers. diff --git a/src/ol/source/TileDebug.js b/src/ol/source/TileDebug.js index c9424f29a5..ba10e7dce7 100644 --- a/src/ol/source/TileDebug.js +++ b/src/ol/source/TileDebug.js @@ -9,6 +9,72 @@ import {toSize} from '../size.js'; import TileSource from '../source/Tile.js'; import _ol_tilecoord_ from '../tilecoord.js'; + +/** + * @constructor + * @extends {ol.Tile} + * @param {ol.TileCoord} tileCoord Tile coordinate. + * @param {ol.Size} tileSize Tile size. + * @param {string} text Text. + */ +const LabeledTile = function(tileCoord, tileSize, text) { + + Tile.call(this, tileCoord, TileState.LOADED); + + /** + * @private + * @type {ol.Size} + */ + this.tileSize_ = tileSize; + + /** + * @private + * @type {string} + */ + this.text_ = text; + + /** + * @private + * @type {HTMLCanvasElement} + */ + this.canvas_ = null; + +}; +inherits(LabeledTile, Tile); + + +/** + * Get the image element for this tile. + * @return {HTMLCanvasElement} Image. + */ +LabeledTile.prototype.getImage = function() { + if (this.canvas_) { + return this.canvas_; + } else { + const tileSize = this.tileSize_; + const context = createCanvasContext2D(tileSize[0], tileSize[1]); + + context.strokeStyle = 'black'; + context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5); + + context.fillStyle = 'black'; + context.textAlign = 'center'; + context.textBaseline = 'middle'; + context.font = '24px sans-serif'; + context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2); + + this.canvas_ = context.canvas; + return context.canvas; + } +}; + + +/** + * @override + */ +LabeledTile.prototype.load = function() {}; + + /** * @classdesc * A pseudo tile source, which does not fetch tiles from a server, but renders @@ -42,82 +108,18 @@ inherits(TileDebug, TileSource); TileDebug.prototype.getTile = function(z, x, y) { const tileCoordKey = _ol_tilecoord_.getKeyZXY(z, x, y); if (this.tileCache.containsKey(tileCoordKey)) { - return /** @type {!ol.source.TileDebug.Tile_} */ (this.tileCache.get(tileCoordKey)); + return /** @type {!ol.source.LabeledTile} */ (this.tileCache.get(tileCoordKey)); } else { const tileSize = toSize(this.tileGrid.getTileSize(z)); const tileCoord = [z, x, y]; const textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord); const text = !textTileCoord ? '' : this.getTileCoordForTileUrlFunction(textTileCoord).toString(); - const tile = new TileDebug.Tile_(tileCoord, tileSize, text); + const tile = new LabeledTile(tileCoord, tileSize, text); this.tileCache.set(tileCoordKey, tile); return tile; } }; -/** - * @constructor - * @extends {ol.Tile} - * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.Size} tileSize Tile size. - * @param {string} text Text. - * @private - */ -TileDebug.Tile_ = function(tileCoord, tileSize, text) { - - Tile.call(this, tileCoord, TileState.LOADED); - - /** - * @private - * @type {ol.Size} - */ - this.tileSize_ = tileSize; - - /** - * @private - * @type {string} - */ - this.text_ = text; - - /** - * @private - * @type {HTMLCanvasElement} - */ - this.canvas_ = null; - -}; -inherits(TileDebug.Tile_, Tile); - - -/** - * Get the image element for this tile. - * @return {HTMLCanvasElement} Image. - */ -TileDebug.Tile_.prototype.getImage = function() { - if (this.canvas_) { - return this.canvas_; - } else { - const tileSize = this.tileSize_; - const context = createCanvasContext2D(tileSize[0], tileSize[1]); - - context.strokeStyle = 'black'; - context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5); - - context.fillStyle = 'black'; - context.textAlign = 'center'; - context.textBaseline = 'middle'; - context.font = '24px sans-serif'; - context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2); - - this.canvas_ = context.canvas; - return context.canvas; - } -}; - - -/** - * @override - */ -TileDebug.Tile_.prototype.load = function() {}; export default TileDebug; diff --git a/src/ol/source/TileUTFGrid.js b/src/ol/source/TileUTFGrid.js index caa243e0c7..f8c08ed28a 100644 --- a/src/ol/source/TileUTFGrid.js +++ b/src/ol/source/TileUTFGrid.js @@ -16,6 +16,239 @@ import TileSource from '../source/Tile.js'; import _ol_tilecoord_ from '../tilecoord.js'; import {createXYZ, extentFromProjection} from '../tilegrid.js'; + +/** + * @constructor + * @extends {ol.Tile} + * @param {ol.TileCoord} tileCoord Tile coordinate. + * @param {ol.TileState} state State. + * @param {string} src Image source URI. + * @param {ol.Extent} extent Extent of the tile. + * @param {boolean} preemptive Load the tile when visible (before it's needed). + * @param {boolean} jsonp Load the tile as a script. + */ +export const CustomTile = function(tileCoord, state, src, extent, preemptive, jsonp) { + + Tile.call(this, tileCoord, state); + + /** + * @private + * @type {string} + */ + this.src_ = src; + + /** + * @private + * @type {ol.Extent} + */ + this.extent_ = extent; + + /** + * @private + * @type {boolean} + */ + this.preemptive_ = preemptive; + + /** + * @private + * @type {Array.} + */ + this.grid_ = null; + + /** + * @private + * @type {Array.} + */ + this.keys_ = null; + + /** + * @private + * @type {Object.|undefined} + */ + this.data_ = null; + + + /** + * @private + * @type {boolean} + */ + this.jsonp_ = jsonp; + +}; +inherits(CustomTile, Tile); + + +/** + * Get the image element for this tile. + * @return {Image} Image. + */ +CustomTile.prototype.getImage = function() { + return null; +}; + + +/** + * Synchronously returns data at given coordinate (if available). + * @param {ol.Coordinate} coordinate Coordinate. + * @return {*} The data. + */ +CustomTile.prototype.getData = function(coordinate) { + if (!this.grid_ || !this.keys_) { + return null; + } + const xRelative = (coordinate[0] - this.extent_[0]) / + (this.extent_[2] - this.extent_[0]); + const yRelative = (coordinate[1] - this.extent_[1]) / + (this.extent_[3] - this.extent_[1]); + + const row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)]; + + if (typeof row !== 'string') { + return null; + } + + let code = row.charCodeAt(Math.floor(xRelative * row.length)); + if (code >= 93) { + code--; + } + if (code >= 35) { + code--; + } + code -= 32; + + let data = null; + if (code in this.keys_) { + const id = this.keys_[code]; + if (this.data_ && id in this.data_) { + data = this.data_[id]; + } else { + data = id; + } + } + return data; +}; + + +/** + * Calls the callback (synchronously by default) with the available data + * for given coordinate (or `null` if not yet loaded). + * @param {ol.Coordinate} coordinate Coordinate. + * @param {function(this: T, *)} callback Callback. + * @param {T=} opt_this The object to use as `this` in the callback. + * @param {boolean=} opt_request If `true` the callback is always async. + * The tile data is requested if not yet loaded. + * @template T + */ +CustomTile.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) { + if (this.state == TileState.IDLE && opt_request === true) { + listenOnce(this, EventType.CHANGE, function(e) { + callback.call(opt_this, this.getData(coordinate)); + }, this); + this.loadInternal_(); + } else { + if (opt_request === true) { + setTimeout(function() { + callback.call(opt_this, this.getData(coordinate)); + }.bind(this), 0); + } else { + callback.call(opt_this, this.getData(coordinate)); + } + } +}; + + +/** + * @inheritDoc + */ +CustomTile.prototype.getKey = function() { + return this.src_; +}; + + +/** + * @private + */ +CustomTile.prototype.handleError_ = function() { + this.state = TileState.ERROR; + this.changed(); +}; + + +/** + * @param {!UTFGridJSON} json UTFGrid data. + * @private + */ +CustomTile.prototype.handleLoad_ = function(json) { + this.grid_ = json.grid; + this.keys_ = json.keys; + this.data_ = json.data; + + this.state = TileState.EMPTY; + this.changed(); +}; + + +/** + * @private + */ +CustomTile.prototype.loadInternal_ = function() { + if (this.state == TileState.IDLE) { + this.state = TileState.LOADING; + if (this.jsonp_) { + requestJSONP(this.src_, this.handleLoad_.bind(this), + this.handleError_.bind(this)); + } else { + const client = new XMLHttpRequest(); + client.addEventListener('load', this.onXHRLoad_.bind(this)); + client.addEventListener('error', this.onXHRError_.bind(this)); + client.open('GET', this.src_); + client.send(); + } + } +}; + + +/** + * @private + * @param {Event} event The load event. + */ +CustomTile.prototype.onXHRLoad_ = function(event) { + const client = /** @type {XMLHttpRequest} */ (event.target); + // status will be 0 for file:// urls + if (!client.status || client.status >= 200 && client.status < 300) { + let response; + try { + response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText)); + } catch (err) { + this.handleError_(); + return; + } + this.handleLoad_(response); + } else { + this.handleError_(); + } +}; + + +/** + * @private + * @param {Event} event The error event. + */ +CustomTile.prototype.onXHRError_ = function(event) { + this.handleError_(); +}; + + +/** + * @override + */ +CustomTile.prototype.load = function() { + if (this.preemptive_) { + this.loadInternal_(); + } +}; + + /** * @classdesc * Layer source for UTFGrid interaction data loaded from TileJSON format. @@ -134,7 +367,7 @@ UTFGrid.prototype.forDataAtCoordinateAndResolution = function( if (this.tileGrid) { const tileCoord = this.tileGrid.getTileCoordForCoordAndResolution( coordinate, resolution); - const tile = /** @type {!ol.source.TileUTFGrid.Tile_} */(this.getTile( + const tile = /** @type {!ol.source.CustomTile} */(this.getTile( tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection())); tile.forDataAtCoordinate(coordinate, callback, null, opt_request); } else { @@ -222,7 +455,7 @@ UTFGrid.prototype.getTile = function(z, x, y, pixelRatio, projection) { const urlTileCoord = this.getTileCoordForTileUrlFunction(tileCoord, projection); const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection); - const tile = new UTFGrid.Tile_( + const tile = new CustomTile( tileCoord, tileUrl !== undefined ? TileState.IDLE : TileState.EMPTY, tileUrl !== undefined ? tileUrl : '', @@ -246,235 +479,4 @@ UTFGrid.prototype.useTile = function(z, x, y) { }; -/** - * @constructor - * @extends {ol.Tile} - * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. - * @param {string} src Image source URI. - * @param {ol.Extent} extent Extent of the tile. - * @param {boolean} preemptive Load the tile when visible (before it's needed). - * @param {boolean} jsonp Load the tile as a script. - * @private - */ -UTFGrid.Tile_ = function(tileCoord, state, src, extent, preemptive, jsonp) { - - Tile.call(this, tileCoord, state); - - /** - * @private - * @type {string} - */ - this.src_ = src; - - /** - * @private - * @type {ol.Extent} - */ - this.extent_ = extent; - - /** - * @private - * @type {boolean} - */ - this.preemptive_ = preemptive; - - /** - * @private - * @type {Array.} - */ - this.grid_ = null; - - /** - * @private - * @type {Array.} - */ - this.keys_ = null; - - /** - * @private - * @type {Object.|undefined} - */ - this.data_ = null; - - - /** - * @private - * @type {boolean} - */ - this.jsonp_ = jsonp; - -}; -inherits(UTFGrid.Tile_, Tile); - - -/** - * Get the image element for this tile. - * @return {Image} Image. - */ -UTFGrid.Tile_.prototype.getImage = function() { - return null; -}; - - -/** - * Synchronously returns data at given coordinate (if available). - * @param {ol.Coordinate} coordinate Coordinate. - * @return {*} The data. - */ -UTFGrid.Tile_.prototype.getData = function(coordinate) { - if (!this.grid_ || !this.keys_) { - return null; - } - const xRelative = (coordinate[0] - this.extent_[0]) / - (this.extent_[2] - this.extent_[0]); - const yRelative = (coordinate[1] - this.extent_[1]) / - (this.extent_[3] - this.extent_[1]); - - const row = this.grid_[Math.floor((1 - yRelative) * this.grid_.length)]; - - if (typeof row !== 'string') { - return null; - } - - let code = row.charCodeAt(Math.floor(xRelative * row.length)); - if (code >= 93) { - code--; - } - if (code >= 35) { - code--; - } - code -= 32; - - let data = null; - if (code in this.keys_) { - const id = this.keys_[code]; - if (this.data_ && id in this.data_) { - data = this.data_[id]; - } else { - data = id; - } - } - return data; -}; - - -/** - * Calls the callback (synchronously by default) with the available data - * for given coordinate (or `null` if not yet loaded). - * @param {ol.Coordinate} coordinate Coordinate. - * @param {function(this: T, *)} callback Callback. - * @param {T=} opt_this The object to use as `this` in the callback. - * @param {boolean=} opt_request If `true` the callback is always async. - * The tile data is requested if not yet loaded. - * @template T - */ -UTFGrid.Tile_.prototype.forDataAtCoordinate = function(coordinate, callback, opt_this, opt_request) { - if (this.state == TileState.IDLE && opt_request === true) { - listenOnce(this, EventType.CHANGE, function(e) { - callback.call(opt_this, this.getData(coordinate)); - }, this); - this.loadInternal_(); - } else { - if (opt_request === true) { - setTimeout(function() { - callback.call(opt_this, this.getData(coordinate)); - }.bind(this), 0); - } else { - callback.call(opt_this, this.getData(coordinate)); - } - } -}; - - -/** - * @inheritDoc - */ -UTFGrid.Tile_.prototype.getKey = function() { - return this.src_; -}; - - -/** - * @private - */ -UTFGrid.Tile_.prototype.handleError_ = function() { - this.state = TileState.ERROR; - this.changed(); -}; - - -/** - * @param {!UTFGridJSON} json UTFGrid data. - * @private - */ -UTFGrid.Tile_.prototype.handleLoad_ = function(json) { - this.grid_ = json.grid; - this.keys_ = json.keys; - this.data_ = json.data; - - this.state = TileState.EMPTY; - this.changed(); -}; - - -/** - * @private - */ -UTFGrid.Tile_.prototype.loadInternal_ = function() { - if (this.state == TileState.IDLE) { - this.state = TileState.LOADING; - if (this.jsonp_) { - requestJSONP(this.src_, this.handleLoad_.bind(this), - this.handleError_.bind(this)); - } else { - const client = new XMLHttpRequest(); - client.addEventListener('load', this.onXHRLoad_.bind(this)); - client.addEventListener('error', this.onXHRError_.bind(this)); - client.open('GET', this.src_); - client.send(); - } - } -}; - - -/** - * @private - * @param {Event} event The load event. - */ -UTFGrid.Tile_.prototype.onXHRLoad_ = function(event) { - const client = /** @type {XMLHttpRequest} */ (event.target); - // status will be 0 for file:// urls - if (!client.status || client.status >= 200 && client.status < 300) { - let response; - try { - response = /** @type {!UTFGridJSON} */(JSON.parse(client.responseText)); - } catch (err) { - this.handleError_(); - return; - } - this.handleLoad_(response); - } else { - this.handleError_(); - } -}; - - -/** - * @private - * @param {Event} event The error event. - */ -UTFGrid.Tile_.prototype.onXHRError_ = function(event) { - this.handleError_(); -}; - - -/** - * @override - */ -UTFGrid.Tile_.prototype.load = function() { - if (this.preemptive_) { - this.loadInternal_(); - } -}; export default UTFGrid; diff --git a/src/ol/source/Zoomify.js b/src/ol/source/Zoomify.js index d1ede7ff64..fc45850d5b 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -13,6 +13,72 @@ import {toSize} from '../size.js'; import TileImage from '../source/TileImage.js'; import TileGrid from '../tilegrid/TileGrid.js'; + +/** + * @enum {string} + */ +const TierSizeCalculation = { + DEFAULT: 'default', + TRUNCATED: 'truncated' +}; + + +/** + * @constructor + * @extends {ol.ImageTile} + * @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to. + * @param {ol.TileCoord} tileCoord Tile coordinate. + * @param {ol.TileState} state State. + * @param {string} src Image source URI. + * @param {?string} crossOrigin Cross origin. + * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. + * @param {olx.TileOptions=} opt_options Tile options. + */ +export const CustomTile = function( + tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) { + + ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options); + + /** + * @private + * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} + */ + this.zoomifyImage_ = null; + + /** + * @private + * @type {ol.Size} + */ + this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0])); +}; +inherits(CustomTile, ImageTile); + + +/** + * @inheritDoc + */ +CustomTile.prototype.getImage = function() { + if (this.zoomifyImage_) { + return this.zoomifyImage_; + } + const image = ImageTile.prototype.getImage.call(this); + if (this.state == TileState.LOADED) { + const tileSize = this.tileSize_; + if (image.width == tileSize[0] && image.height == tileSize[1]) { + this.zoomifyImage_ = image; + return image; + } else { + const context = createCanvasContext2D(tileSize[0], tileSize[1]); + context.drawImage(image, 0, 0); + this.zoomifyImage_ = context.canvas; + return context.canvas; + } + } else { + return image; + } +}; + + /** * @classdesc * Layer source for tile data in Zoomify format (both Zoomify and Internet @@ -30,7 +96,7 @@ const Zoomify = function(opt_options) { const size = options.size; const tierSizeCalculation = options.tierSizeCalculation !== undefined ? options.tierSizeCalculation : - Zoomify.TierSizeCalculation_.DEFAULT; + TierSizeCalculation.DEFAULT; const imageWidth = size[0]; const imageHeight = size[1]; @@ -40,7 +106,7 @@ const Zoomify = function(opt_options) { let tileSizeForTierSizeCalculation = tileSize; switch (tierSizeCalculation) { - case Zoomify.TierSizeCalculation_.DEFAULT: + case TierSizeCalculation.DEFAULT: while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) { tierSizeInTiles.push([ Math.ceil(imageWidth / tileSizeForTierSizeCalculation), @@ -49,7 +115,7 @@ const Zoomify = function(opt_options) { tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation; } break; - case Zoomify.TierSizeCalculation_.TRUNCATED: + case TierSizeCalculation.TRUNCATED: let width = imageWidth; let height = imageHeight; while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) { @@ -134,7 +200,7 @@ const Zoomify = function(opt_options) { const tileUrlFunction = createFromTileUrlFunctions(urls.map(createFromTemplate)); - const ZoomifyTileClass = Zoomify.Tile_.bind(null, tileGrid); + const ZoomifyTileClass = CustomTile.bind(null, tileGrid); TileImage.call(this, { attributions: options.attributions, @@ -152,68 +218,5 @@ const Zoomify = function(opt_options) { inherits(Zoomify, TileImage); -/** - * @constructor - * @extends {ol.ImageTile} - * @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to. - * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. - * @param {string} src Image source URI. - * @param {?string} crossOrigin Cross origin. - * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. - * @param {olx.TileOptions=} opt_options Tile options. - * @private - */ -Zoomify.Tile_ = function( - tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) { - ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options); - - /** - * @private - * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} - */ - this.zoomifyImage_ = null; - - /** - * @private - * @type {ol.Size} - */ - this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0])); -}; -inherits(Zoomify.Tile_, ImageTile); - - -/** - * @inheritDoc - */ -Zoomify.Tile_.prototype.getImage = function() { - if (this.zoomifyImage_) { - return this.zoomifyImage_; - } - const image = ImageTile.prototype.getImage.call(this); - if (this.state == TileState.LOADED) { - const tileSize = this.tileSize_; - if (image.width == tileSize[0] && image.height == tileSize[1]) { - this.zoomifyImage_ = image; - return image; - } else { - const context = createCanvasContext2D(tileSize[0], tileSize[1]); - context.drawImage(image, 0, 0); - this.zoomifyImage_ = context.canvas; - return context.canvas; - } - } else { - return image; - } -}; - -/** - * @enum {string} - * @private - */ -Zoomify.TierSizeCalculation_ = { - DEFAULT: 'default', - TRUNCATED: 'truncated' -}; export default Zoomify; diff --git a/src/ol/style/Style.js b/src/ol/style/Style.js index 54025be2cf..e6cb01eab9 100644 --- a/src/ol/style/Style.js +++ b/src/ol/style/Style.js @@ -305,9 +305,8 @@ Style.createFunction = function(obj) { /** * @type {Array.} - * @private */ -Style.default_ = null; +let defaultStyles = null; /** @@ -321,7 +320,7 @@ Style.defaultFunction = function(feature, resolution) { // browsers that do not support Canvas. (ol.style.Circle does // canvas.getContext('2d') at construction time, which will cause an.error // in such browsers.) - if (!Style.default_) { + if (!defaultStyles) { const fill = new Fill({ color: 'rgba(255,255,255,0.4)' }); @@ -329,7 +328,7 @@ Style.defaultFunction = function(feature, resolution) { color: '#3399CC', width: 1.25 }); - Style.default_ = [ + defaultStyles = [ new Style({ image: new CircleStyle({ fill: fill, @@ -341,7 +340,7 @@ Style.defaultFunction = function(feature, resolution) { }) ]; } - return Style.default_; + return defaultStyles; }; diff --git a/src/ol/style/Text.js b/src/ol/style/Text.js index 5de37b36e8..7c4b3a4776 100644 --- a/src/ol/style/Text.js +++ b/src/ol/style/Text.js @@ -4,6 +4,16 @@ import Fill from '../style/Fill.js'; import TextPlacement from '../style/TextPlacement.js'; + +/** + * The default fill color to use if no fill was set at construction time; a + * blackish `#333`. + * + * @const {string} + */ +const DEFAULT_FILL_COLOR = '#333'; + + /** * @classdesc * Set text style for vector features. @@ -63,7 +73,7 @@ const Text = function(opt_options) { * @type {ol.style.Fill} */ this.fill_ = options.fill !== undefined ? options.fill : - new Fill({color: Text.DEFAULT_FILL_COLOR_}); + new Fill({color: DEFAULT_FILL_COLOR}); /** * @private @@ -121,16 +131,6 @@ const Text = function(opt_options) { }; -/** - * The default fill color to use if no fill was set at construction time; a - * blackish `#333`. - * - * @const {string} - * @private - */ -Text.DEFAULT_FILL_COLOR_ = '#333'; - - /** * Clones the style. * @return {ol.style.Text} The cloned style. diff --git a/src/ol/tilegrid/TileGrid.js b/src/ol/tilegrid/TileGrid.js index 6e5dbbfc05..810d26f988 100644 --- a/src/ol/tilegrid/TileGrid.js +++ b/src/ol/tilegrid/TileGrid.js @@ -155,7 +155,7 @@ const TileGrid = function(options) { * @private * @type {ol.TileCoord} */ -TileGrid.tmpTileCoord_ = [0, 0, 0]; +const tmpTileCoord = [0, 0, 0]; /** @@ -325,7 +325,7 @@ TileGrid.prototype.getTileRangeExtent = function(z, tileRange, opt_extent) { * @return {ol.TileRange} Tile range. */ TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z, opt_tileRange) { - const tileCoord = TileGrid.tmpTileCoord_; + const tileCoord = tmpTileCoord; this.getTileCoordForXYAndZ_(extent[0], extent[1], z, false, tileCoord); const minX = tileCoord[1]; const minY = tileCoord[2]; diff --git a/test/spec/ol/interaction/mousewheelzoom.test.js b/test/spec/ol/interaction/mousewheelzoom.test.js index f52eb23cae..5f55163cc4 100644 --- a/test/spec/ol/interaction/mousewheelzoom.test.js +++ b/test/spec/ol/interaction/mousewheelzoom.test.js @@ -4,7 +4,7 @@ import View from '../../../../src/ol/View.js'; import Event from '../../../../src/ol/events/Event.js'; import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../../../../src/ol/has.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js'; -import MouseWheelZoom from '../../../../src/ol/interaction/MouseWheelZoom.js'; +import MouseWheelZoom, {Mode} from '../../../../src/ol/interaction/MouseWheelZoom.js'; describe('ol.interaction.MouseWheelZoom', function() { @@ -65,7 +65,7 @@ describe('ol.interaction.MouseWheelZoom', function() { if (FIREFOX) { it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function(done) { map.once('postrender', function() { - expect(interaction.mode_).to.be(MouseWheelZoom.Mode_.TRACKPAD); + expect(interaction.mode_).to.be(Mode.TRACKPAD); done(); }); const event = new MapBrowserEvent('wheel', map, { @@ -83,7 +83,7 @@ describe('ol.interaction.MouseWheelZoom', function() { if (!FIREFOX) { it('works in DOM_DELTA_PIXEL mode (trackpad)', function(done) { map.once('postrender', function() { - expect(interaction.mode_).to.be(MouseWheelZoom.Mode_.TRACKPAD); + expect(interaction.mode_).to.be(Mode.TRACKPAD); done(); }); const event = new MapBrowserEvent('wheel', map, { diff --git a/test/spec/ol/interaction/snap.test.js b/test/spec/ol/interaction/snap.test.js index 81e23717ae..3414ce0f74 100644 --- a/test/spec/ol/interaction/snap.test.js +++ b/test/spec/ol/interaction/snap.test.js @@ -5,7 +5,7 @@ import View from '../../../../src/ol/View.js'; import Circle from '../../../../src/ol/geom/Circle.js'; import Point from '../../../../src/ol/geom/Point.js'; import LineString from '../../../../src/ol/geom/LineString.js'; -import Snap from '../../../../src/ol/interaction/Snap.js'; +import Snap, {handleEvent} from '../../../../src/ol/interaction/Snap.js'; describe('ol.interaction.Snap', function() { @@ -19,7 +19,7 @@ describe('ol.interaction.Snap', function() { }); - describe('handleEvent_', function() { + describe('handleEvent', function() { let target, map; const width = 360; @@ -67,7 +67,7 @@ describe('ol.interaction.Snap', function() { coordinate: [0, 0], map: map }; - Snap.handleEvent_.call(snapInteraction, event); + handleEvent.call(snapInteraction, event); // check that the coordinate is in XY and not XYZ expect(event.coordinate).to.eql([0, 0]); }); @@ -86,7 +86,7 @@ describe('ol.interaction.Snap', function() { coordinate: [7, 4], map: map }; - Snap.handleEvent_.call(snapInteraction, event); + handleEvent.call(snapInteraction, event); expect(event.coordinate).to.eql([7, 0]); }); @@ -104,7 +104,7 @@ describe('ol.interaction.Snap', function() { coordinate: [7, 4], map: map }; - Snap.handleEvent_.call(snapInteraction, event); + handleEvent.call(snapInteraction, event); expect(event.coordinate).to.eql([10, 0]); }); @@ -121,7 +121,7 @@ describe('ol.interaction.Snap', function() { coordinate: [5, 5], map: map }; - Snap.handleEvent_.call(snapInteraction, event); + handleEvent.call(snapInteraction, event); expect(event.coordinate[0]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10); expect(event.coordinate[1]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10); @@ -143,7 +143,7 @@ describe('ol.interaction.Snap', function() { coordinate: [7, 4], map: map }; - Snap.handleEvent_.call(snapInteraction, event); + handleEvent.call(snapInteraction, event); expect(event.coordinate).to.eql([10, 0]); }); @@ -163,7 +163,7 @@ describe('ol.interaction.Snap', function() { coordinate: [7, 4], map: map }; - Snap.handleEvent_.call(snapInteraction, event); + handleEvent.call(snapInteraction, event); expect(event.coordinate).to.eql([10, 0]); }); @@ -186,7 +186,7 @@ describe('ol.interaction.Snap', function() { coordinate: [7, 4], map: map }; - Snap.handleEvent_.call(snapInteraction, event); + handleEvent.call(snapInteraction, event); expect(event.coordinate).to.eql([10, 0]); }); diff --git a/test/spec/ol/source/tileutfgrid.test.js b/test/spec/ol/source/tileutfgrid.test.js index 9fc18905d8..bf91a917bb 100644 --- a/test/spec/ol/source/tileutfgrid.test.js +++ b/test/spec/ol/source/tileutfgrid.test.js @@ -1,6 +1,6 @@ import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js'; import TileSource from '../../../../src/ol/source/Tile.js'; -import UTFGrid from '../../../../src/ol/source/TileUTFGrid.js'; +import UTFGrid, {CustomTile} from '../../../../src/ol/source/TileUTFGrid.js'; import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js'; @@ -228,7 +228,7 @@ describe('ol.source.TileUTFGrid', function() { const urlTileCoord = this.getTileCoordForTileUrlFunction(tileCoord, projection); const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection); - const tile = new UTFGrid.Tile_( + const tile = new CustomTile( tileCoord, tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY tileUrl !== undefined ? tileUrl : '', diff --git a/test/spec/ol/source/zoomify.test.js b/test/spec/ol/source/zoomify.test.js index 952ce43649..8eb71bf666 100644 --- a/test/spec/ol/source/zoomify.test.js +++ b/test/spec/ol/source/zoomify.test.js @@ -1,7 +1,7 @@ import {DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js'; import {listen} from '../../../../src/ol/events.js'; import Projection from '../../../../src/ol/proj/Projection.js'; -import Zoomify from '../../../../src/ol/source/Zoomify.js'; +import Zoomify, {CustomTile} from '../../../../src/ol/source/Zoomify.js'; import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js'; @@ -280,7 +280,7 @@ describe('ol.source.Zoomify', function() { it('returns expected tileClass instances via "getTile"', function() { const source = getZoomifySource(); const tile = source.getTile(0, 0, -1, 1, proj); - expect(tile).to.be.an(Zoomify.Tile_); + expect(tile).to.be.a(CustomTile); }); it('"tile.getImage" returns and caches an unloaded image', function() { diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index a5584a3459..678a374ec1 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1,5 +1,5 @@ import Map from '../../../src/ol/Map.js'; -import View from '../../../src/ol/View.js'; +import View, {createCenterConstraint, createResolutionConstraint, createRotationConstraint} from '../../../src/ol/View.js'; import ViewHint from '../../../src/ol/ViewHint.js'; import * as _ol_extent_ from '../../../src/ol/extent.js'; import Circle from '../../../src/ol/geom/Circle.js'; @@ -32,7 +32,7 @@ describe('ol.View', function() { describe('with no options', function() { it('gives a correct center constraint function', function() { const options = {}; - const fn = View.createCenterConstraint_(options); + const fn = createCenterConstraint(options); expect(fn([0, 0])).to.eql([0, 0]); expect(fn(undefined)).to.eql(undefined); expect(fn([42, -100])).to.eql([42, -100]); @@ -44,7 +44,7 @@ describe('ol.View', function() { const options = { extent: [0, 0, 1, 1] }; - const fn = View.createCenterConstraint_(options); + const fn = createCenterConstraint(options); expect(fn([0, 0])).to.eql([0, 0]); expect(fn([-10, 0])).to.eql([0, 0]); expect(fn([100, 100])).to.eql([1, 1]); @@ -58,7 +58,7 @@ describe('ol.View', function() { describe('with no options', function() { it('gives a correct resolution constraint function', function() { const options = {}; - const fn = View.createResolutionConstraint_(options).constraint; + const fn = createResolutionConstraint(options).constraint; expect(fn(156543.03392804097, 0, 0)) .to.roughlyEqual(156543.03392804097, 1e-9); expect(fn(78271.51696402048, 0, 0)) @@ -74,7 +74,7 @@ describe('ol.View', function() { maxZoom: 3, zoomFactor: 3 }; - const info = View.createResolutionConstraint_(options); + const info = createResolutionConstraint(options); const maxResolution = info.maxResolution; expect(maxResolution).to.eql(81); const minResolution = info.minResolution; @@ -94,7 +94,7 @@ describe('ol.View', function() { const options = { resolutions: [97, 76, 65, 54, 0.45] }; - const info = View.createResolutionConstraint_(options); + const info = createResolutionConstraint(options); const maxResolution = info.maxResolution; expect(maxResolution).to.eql(97); const minResolution = info.minResolution; @@ -112,7 +112,7 @@ describe('ol.View', function() { const defaultMaxRes = 156543.03392804097; function getConstraint(options) { - return View.createResolutionConstraint_(options).constraint; + return createResolutionConstraint(options).constraint; } it('works with only maxZoom', function() { @@ -179,7 +179,7 @@ describe('ol.View', function() { const defaultMaxRes = 156543.03392804097; function getConstraint(options) { - return View.createResolutionConstraint_(options).constraint; + return createResolutionConstraint(options).constraint; } it('works with only maxResolution', function() { @@ -248,7 +248,7 @@ describe('ol.View', function() { const defaultMaxRes = 156543.03392804097; function getConstraint(options) { - return View.createResolutionConstraint_(options).constraint; + return createResolutionConstraint(options).constraint; } it('respects maxResolution over minZoom', function() { @@ -292,7 +292,7 @@ describe('ol.View', function() { describe('create rotation constraint', function() { it('gives a correct rotation constraint function', function() { const options = {}; - const fn = View.createRotationConstraint_(options); + const fn = createRotationConstraint(options); expect(fn(0.01, 0)).to.eql(0); expect(fn(0.15, 0)).to.eql(0.15); });