diff --git a/examples/feature-animation.js b/examples/feature-animation.js index 1908d9acb1..439826721e 100644 --- a/examples/feature-animation.js +++ b/examples/feature-animation.js @@ -1,6 +1,6 @@ import Feature from '../src/ol/Feature.js'; import Map from '../src/ol/Map.js'; -import Observable from '../src/ol/Observable.js'; +import {unByKey} from '../src/ol/Observable.js'; import View from '../src/ol/View.js'; import {defaults as defaultControls} from '../src/ol/control.js'; import {easeOut} from '../src/ol/easing.js'; @@ -80,7 +80,7 @@ function flash(feature) { vectorContext.setStyle(style); vectorContext.drawGeometry(flashGeom); if (elapsed > duration) { - Observable.unByKey(listenerKey); + unByKey(listenerKey); return; } // tell OpenLayers to continue postcompose animation diff --git a/examples/measure.js b/examples/measure.js index 943053cdcf..abcea9abb2 100644 --- a/examples/measure.js +++ b/examples/measure.js @@ -1,5 +1,5 @@ import Map from '../src/ol/Map.js'; -import Observable from '../src/ol/Observable.js'; +import {unByKey} from '../src/ol/Observable.js'; import Overlay from '../src/ol/Overlay.js'; import {getArea, getLength} from '../src/ol/sphere.js'; import View from '../src/ol/View.js'; @@ -238,7 +238,7 @@ function addInteraction() { // unset tooltip so that a new one can be created measureTooltipElement = null; createMeasureTooltip(); - Observable.unByKey(listener); + unByKey(listener); }, this); } diff --git a/src/ol/Observable.js b/src/ol/Observable.js index d63526676f..19857e462b 100644 --- a/src/ol/Observable.js +++ b/src/ol/Observable.js @@ -41,7 +41,7 @@ inherits(Observable, EventTarget); * or `once()` (or an array of keys). * @api */ -Observable.unByKey = function(key) { +export function unByKey(key) { if (Array.isArray(key)) { for (let i = 0, ii = key.length; i < ii; ++i) { unlistenByKey(key[i]); @@ -49,7 +49,7 @@ Observable.unByKey = function(key) { } else { unlistenByKey(/** @type {ol.EventsKey} */ (key)); } -}; +} /** diff --git a/src/ol/TileRange.js b/src/ol/TileRange.js index 57f3930df3..8aaabaf6f4 100644 --- a/src/ol/TileRange.js +++ b/src/ol/TileRange.js @@ -45,7 +45,7 @@ const TileRange = function(minX, maxX, minY, maxY) { * @param {ol.TileRange|undefined} tileRange TileRange. * @return {ol.TileRange} Tile range. */ -TileRange.createOrUpdate = function(minX, maxX, minY, maxY, tileRange) { +export function createOrUpdate(minX, maxX, minY, maxY, tileRange) { if (tileRange !== undefined) { tileRange.minX = minX; tileRange.maxX = maxX; @@ -55,7 +55,7 @@ TileRange.createOrUpdate = function(minX, maxX, minY, maxY, tileRange) { } else { return new TileRange(minX, maxX, minY, maxY); } -}; +} /** diff --git a/src/ol/View.js b/src/ol/View.js index 34adb308d7..2fcd51bc33 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -339,7 +339,7 @@ View.prototype.animate = function(var_args) { animation.callback = callback; // check if animation is a no-op - if (View.isNoopAnimation(animation)) { + if (isNoopAnimation(animation)) { animation.complete = true; // we still push it onto the series for callback handling } else { @@ -1204,7 +1204,7 @@ export function createRotationConstraint(options) { * @param {ol.ViewAnimation} animation The animation. * @return {boolean} The animation involves no view change. */ -View.isNoopAnimation = function(animation) { +export function isNoopAnimation(animation) { if (animation.sourceCenter && animation.targetCenter) { if (!coordinatesEqual(animation.sourceCenter, animation.targetCenter)) { return false; @@ -1217,5 +1217,6 @@ View.isNoopAnimation = function(animation) { return false; } return true; -}; +} + export default View; diff --git a/src/ol/render/canvas/ReplayGroup.js b/src/ol/render/canvas/ReplayGroup.js index 21d31ce01c..d8d7df604b 100644 --- a/src/ol/render/canvas/ReplayGroup.js +++ b/src/ol/render/canvas/ReplayGroup.js @@ -204,7 +204,7 @@ export function getCircleArray(radius) { * @param {CanvasRenderingContext2D} context Context. * @param {number} rotation Rotation. */ -CanvasReplayGroup.replayDeclutter = function(declutterReplays, context, rotation) { +export function replayDeclutter(declutterReplays, context, rotation) { const zs = Object.keys(declutterReplays).map(Number).sort(numberSafeCompareFunction); const skippedFeatureUids = {}; for (let z = 0, zz = zs.length; z < zz; ++z) { @@ -215,7 +215,7 @@ CanvasReplayGroup.replayDeclutter = function(declutterReplays, context, rotation replay.replay(context, transform, rotation, skippedFeatureUids); } } -}; +} /** diff --git a/src/ol/render/canvas/TextReplay.js b/src/ol/render/canvas/TextReplay.js index 82db004ef8..e3131e23cf 100644 --- a/src/ol/render/canvas/TextReplay.js +++ b/src/ol/render/canvas/TextReplay.js @@ -143,17 +143,16 @@ inherits(CanvasTextReplay, CanvasReplay); * each line. * @return {number} Width of the whole text. */ -CanvasTextReplay.measureTextWidths = function(font, lines, widths) { +export function measureTextWidths(font, lines, widths) { const numLines = lines.length; let width = 0; - let currentWidth, i; - for (i = 0; i < numLines; ++i) { - currentWidth = measureTextWidth(font, lines[i]); + for (let i = 0; i < numLines; ++i) { + const currentWidth = measureTextWidth(font, lines[i]); width = Math.max(width, currentWidth); widths.push(currentWidth); } return width; -}; +} /** @@ -296,7 +295,7 @@ CanvasTextReplay.prototype.getImage = function(text, textKey, fillKey, strokeKey const lines = text.split('\n'); const numLines = lines.length; const widths = []; - const width = CanvasTextReplay.measureTextWidths(textState.font, lines, widths); + const width = measureTextWidths(textState.font, lines, widths); const lineHeight = measureTextHeight(textState.font); const height = lineHeight * numLines; const renderWidth = (width + strokeWidth); diff --git a/src/ol/renderer/canvas/VectorTileLayer.js b/src/ol/renderer/canvas/VectorTileLayer.js index 0550e8f86a..51cc0f6f5b 100644 --- a/src/ol/renderer/canvas/VectorTileLayer.js +++ b/src/ol/renderer/canvas/VectorTileLayer.js @@ -14,7 +14,7 @@ import {equivalent as equivalentProjection} from '../../proj.js'; import Units from '../../proj/Units.js'; import ReplayType from '../../render/ReplayType.js'; import {labelCache, rotateAtOffset} from '../../render/canvas.js'; -import CanvasReplayGroup from '../../render/canvas/ReplayGroup.js'; +import CanvasReplayGroup, {replayDeclutter} from '../../render/canvas/ReplayGroup.js'; import {ORDER} from '../../render/replay.js'; import RendererType from '../Type.js'; import CanvasTileLayerRenderer from '../canvas/TileLayer.js'; @@ -436,7 +436,7 @@ CanvasVectorTileLayerRenderer.prototype.postCompose = function(context, frameSta } } if (declutterReplays) { - CanvasReplayGroup.replayDeclutter(declutterReplays, context, rotation); + replayDeclutter(declutterReplays, context, rotation); } if (rotation) { rotateAtOffset(context, rotation, diff --git a/src/ol/tilegrid/TileGrid.js b/src/ol/tilegrid/TileGrid.js index 31b2c57f2f..cac0b7f314 100644 --- a/src/ol/tilegrid/TileGrid.js +++ b/src/ol/tilegrid/TileGrid.js @@ -3,12 +3,12 @@ */ import {DEFAULT_TILE_SIZE} from './common.js'; import {assert} from '../asserts.js'; -import TileRange from '../TileRange.js'; +import TileRange, {createOrUpdate as createOrUpdateTileRange} from '../TileRange.js'; import {isSorted, linearFindNearest} from '../array.js'; import {createOrUpdate, getTopLeft} from '../extent.js'; import {clamp} from '../math.js'; import {toSize} from '../size.js'; -import {createOrUpdate as tileCoordCreateOrUpdate} from '../tilecoord.js'; +import {createOrUpdate as createOrUpdateTileCoord} from '../tilecoord.js'; /** * @classdesc @@ -199,7 +199,7 @@ TileGrid.prototype.forEachTileCoordParentTileRange = function(tileCoord, callbac if (this.zoomFactor_ === 2) { x = Math.floor(x / 2); y = Math.floor(y / 2); - tileRange = TileRange.createOrUpdate(x, x, y, y, opt_tileRange); + tileRange = createOrUpdateTileRange(x, x, y, y, opt_tileRange); } else { tileRange = this.getTileRangeForExtentAndZ(tileCoordExtent, z, opt_tileRange); } @@ -288,7 +288,7 @@ TileGrid.prototype.getTileCoordChildTileRange = function(tileCoord, opt_tileRang if (this.zoomFactor_ === 2) { const minX = tileCoord[1] * 2; const minY = tileCoord[2] * 2; - return TileRange.createOrUpdate(minX, minX + 1, minY, minY + 1, opt_tileRange); + return createOrUpdateTileRange(minX, minX + 1, minY, minY + 1, opt_tileRange); } const tileCoordExtent = this.getTileCoordExtent(tileCoord, opt_extent); return this.getTileRangeForExtentAndZ( @@ -330,8 +330,7 @@ TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z, opt_tileRange const minX = tileCoord[1]; const minY = tileCoord[2]; this.getTileCoordForXYAndZ_(extent[2], extent[3], z, true, tileCoord); - return TileRange.createOrUpdate( - minX, tileCoord[1], minY, tileCoord[2], opt_tileRange); + return createOrUpdateTileRange(minX, tileCoord[1], minY, tileCoord[2], opt_tileRange); }; @@ -422,7 +421,7 @@ TileGrid.prototype.getTileCoordForXYAndResolution_ = function( tileCoordY = Math.floor(tileCoordY); } - return tileCoordCreateOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord); + return createOrUpdateTileCoord(z, tileCoordX, tileCoordY, opt_tileCoord); }; @@ -461,7 +460,7 @@ TileGrid.prototype.getTileCoordForXYAndZ_ = function(x, y, z, reverseIntersectio tileCoordY = Math.floor(tileCoordY); } - return tileCoordCreateOrUpdate(z, tileCoordX, tileCoordY, opt_tileCoord); + return createOrUpdateTileCoord(z, tileCoordX, tileCoordY, opt_tileCoord); }; diff --git a/test/spec/ol/observable.test.js b/test/spec/ol/observable.test.js index 4a469735f9..f9f1006d64 100644 --- a/test/spec/ol/observable.test.js +++ b/test/spec/ol/observable.test.js @@ -1,5 +1,5 @@ import EventTarget from '../../../src/ol/events/EventTarget.js'; -import Observable from '../../../src/ol/Observable.js'; +import Observable, {unByKey} from '../../../src/ol/Observable.js'; describe('ol.Observable', function() { @@ -138,7 +138,7 @@ describe('ol.Observable', function() { observable.dispatchEvent('foo'); expect(listener.calledOnce).to.be(true); - Observable.unByKey(key); + unByKey(key); observable.dispatchEvent('foo'); expect(listener.callCount).to.be(1); }); diff --git a/test/spec/ol/source/bingmaps.test.js b/test/spec/ol/source/bingmaps.test.js index 06361a6262..1823b89e67 100644 --- a/test/spec/ol/source/bingmaps.test.js +++ b/test/spec/ol/source/bingmaps.test.js @@ -1,6 +1,6 @@ import BingMaps from '../../../../src/ol/source/BingMaps.js'; import {quadKey} from '../../../../src/ol/tilecoord.js'; -import Observable from '../../../../src/ol/Observable.js'; +import {unByKey} from '../../../../src/ol/Observable.js'; describe('ol.source.BingMaps', function() { @@ -24,7 +24,7 @@ describe('ol.source.BingMaps', function() { const key = source.on('change', function() { if (source.getState() === 'ready') { - Observable.unByKey(key); + unByKey(key); tileGrid = source.getTileGrid(); done(); } diff --git a/test/spec/ol/source/tilejson.test.js b/test/spec/ol/source/tilejson.test.js index 912eafed26..8ce5cd43fb 100644 --- a/test/spec/ol/source/tilejson.test.js +++ b/test/spec/ol/source/tilejson.test.js @@ -1,6 +1,6 @@ import Source from '../../../../src/ol/source/Source.js'; import TileJSON from '../../../../src/ol/source/TileJSON.js'; -import Observable from '../../../../src/ol/Observable.js'; +import {unByKey} from '../../../../src/ol/Observable.js'; describe('ol.source.TileJSON', function() { @@ -115,7 +115,7 @@ describe('ol.source.TileJSON', function() { }); const key = source.on('change', function() { if (source.getState() === 'ready') { - Observable.unByKey(key); + unByKey(key); tileGrid = source.getTileGrid(); done(); } diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index c024db66b0..321c69667c 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1,5 +1,8 @@ import Map from '../../../src/ol/Map.js'; -import View, {createCenterConstraint, createResolutionConstraint, createRotationConstraint} from '../../../src/ol/View.js'; +import View, { + createCenterConstraint, createResolutionConstraint, createRotationConstraint, + isNoopAnimation +} from '../../../src/ol/View.js'; import ViewHint from '../../../src/ol/ViewHint.js'; import {createEmpty} from '../../../src/ol/extent.js'; import Circle from '../../../src/ol/geom/Circle.js'; @@ -1485,7 +1488,7 @@ describe('ol.View.isNoopAnimation()', function() { cases.forEach(function(c, i) { it('works for case ' + i, function() { - const noop = View.isNoopAnimation(c.animation); + const noop = isNoopAnimation(c.animation); expect(noop).to.equal(c.noop); }); });