From 00f891c3f9622aad7ccce0fd6f617350597dec1d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:06:50 -0700 Subject: [PATCH 01/19] Named exports from ol/source/WMTS --- examples/reprojection.js | 4 ++-- examples/wmts-hidpi.js | 4 ++-- examples/wmts-layer-from-capabilities.js | 4 ++-- src/ol/source/WMTS.js | 5 +++-- test/spec/ol/source/wmts.test.js | 26 ++++++++++++------------ 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/examples/reprojection.js b/examples/reprojection.js index ca57e6e115..20ba191795 100644 --- a/examples/reprojection.js +++ b/examples/reprojection.js @@ -8,7 +8,7 @@ import {register} from '../src/ol/proj/proj4.js'; import OSM from '../src/ol/source/OSM.js'; import TileImage from '../src/ol/source/TileImage.js'; import TileWMS from '../src/ol/source/TileWMS.js'; -import WMTS from '../src/ol/source/WMTS.js'; +import WMTS, {optionsFromCapabilities} from '../src/ol/source/WMTS.js'; import XYZ from '../src/ol/source/XYZ.js'; import TileGrid from '../src/ol/tilegrid/TileGrid.js'; import proj4 from 'proj4'; @@ -104,7 +104,7 @@ fetch(url).then(function(response) { return response.text(); }).then(function(text) { const result = parser.read(text); - const options = WMTS.optionsFromCapabilities(result, { + const options = optionsFromCapabilities(result, { layer: 'OSM_Land_Mask', matrixSet: 'EPSG3413_250m' }); diff --git a/examples/wmts-hidpi.js b/examples/wmts-hidpi.js index 27255c8110..4371df9458 100644 --- a/examples/wmts-hidpi.js +++ b/examples/wmts-hidpi.js @@ -3,7 +3,7 @@ import View from '../src/ol/View.js'; import WMTSCapabilities from '../src/ol/format/WMTSCapabilities.js'; import {DEVICE_PIXEL_RATIO} from '../src/ol/has.js'; import TileLayer from '../src/ol/layer/Tile.js'; -import WMTS from '../src/ol/source/WMTS.js'; +import WMTS, {optionsFromCapabilities} from '../src/ol/source/WMTS.js'; const capabilitiesUrl = 'https://www.basemap.at/wmts/1.0.0/WMTSCapabilities.xml'; @@ -27,7 +27,7 @@ fetch(capabilitiesUrl).then(function(response) { return response.text(); }).then(function(text) { const result = new WMTSCapabilities().read(text); - const options = WMTS.optionsFromCapabilities(result, { + const options = optionsFromCapabilities(result, { layer: layer, matrixSet: 'google3857', style: 'normal' diff --git a/examples/wmts-layer-from-capabilities.js b/examples/wmts-layer-from-capabilities.js index 49924110bd..d7c4cfa48f 100644 --- a/examples/wmts-layer-from-capabilities.js +++ b/examples/wmts-layer-from-capabilities.js @@ -3,7 +3,7 @@ import View from '../src/ol/View.js'; import WMTSCapabilities from '../src/ol/format/WMTSCapabilities.js'; import TileLayer from '../src/ol/layer/Tile.js'; import OSM from '../src/ol/source/OSM.js'; -import WMTS from '../src/ol/source/WMTS.js'; +import WMTS, {optionsFromCapabilities} from '../src/ol/source/WMTS.js'; const parser = new WMTSCapabilities(); let map; @@ -12,7 +12,7 @@ fetch('data/WMTSCapabilities.xml').then(function(response) { return response.text(); }).then(function(text) { const result = parser.read(text); - const options = WMTS.optionsFromCapabilities(result, { + const options = optionsFromCapabilities(result, { layer: 'layer-7328', matrixSet: 'EPSG:3857' }); diff --git a/src/ol/source/WMTS.js b/src/ol/source/WMTS.js index a95f994c74..8f2d2e7ffb 100644 --- a/src/ol/source/WMTS.js +++ b/src/ol/source/WMTS.js @@ -309,7 +309,7 @@ WMTS.prototype.updateDimensions = function(dimensions) { * @return {?olx.source.WMTSOptions} WMTS source options object or `null` if the layer was not found. * @api */ -WMTS.optionsFromCapabilities = function(wmtsCap, config) { +export function optionsFromCapabilities(wmtsCap, config) { const layers = wmtsCap['Contents']['Layer']; const l = find(layers, function(elt, index, array) { return elt['Identifier'] == config['layer']; @@ -476,5 +476,6 @@ WMTS.optionsFromCapabilities = function(wmtsCap, config) { wrapX: wrapX, crossOrigin: config['crossOrigin'] }; -}; +} + export default WMTS; diff --git a/test/spec/ol/source/wmts.test.js b/test/spec/ol/source/wmts.test.js index 99512f90a8..f79f53b64a 100644 --- a/test/spec/ol/source/wmts.test.js +++ b/test/spec/ol/source/wmts.test.js @@ -2,7 +2,7 @@ import WMTSCapabilities from '../../../../src/ol/format/WMTSCapabilities.js'; import {get as getProjection} from '../../../../src/ol/proj.js'; import Projection from '../../../../src/ol/proj/Projection.js'; import WMTSTileGrid from '../../../../src/ol/tilegrid/WMTS.js'; -import WMTS from '../../../../src/ol/source/WMTS.js'; +import WMTS, {optionsFromCapabilities} from '../../../../src/ol/source/WMTS.js'; describe('ol.source.WMTS', function() { @@ -23,7 +23,7 @@ describe('ol.source.WMTS', function() { }); it('returns null if the layer was not found in the capabilities', function() { - const options = WMTS.optionsFromCapabilities(capabilities, { + const options = optionsFromCapabilities(capabilities, { layer: 'invalid' }); @@ -31,7 +31,7 @@ describe('ol.source.WMTS', function() { }); it('passes the crossOrigin option', function() { - const options = WMTS.optionsFromCapabilities(capabilities, { + const options = optionsFromCapabilities(capabilities, { layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857', crossOrigin: '' @@ -42,7 +42,7 @@ describe('ol.source.WMTS', function() { it('can create KVP options from spec/ol/format/wmts/ogcsample.xml', function() { - const options = WMTS.optionsFromCapabilities( + const options = optionsFromCapabilities( capabilities, {layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'}); @@ -74,7 +74,7 @@ describe('ol.source.WMTS', function() { it('can create REST options from spec/ol/format/wmts/ogcsample.xml', function() { - const options = WMTS.optionsFromCapabilities(capabilities, { + const options = optionsFromCapabilities(capabilities, { layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857', requestEncoding: 'REST' @@ -105,7 +105,7 @@ describe('ol.source.WMTS', function() { }); it('can find a MatrixSet by SRS identifier', function() { - const options = WMTS.optionsFromCapabilities(capabilities, { + const options = optionsFromCapabilities(capabilities, { layer: 'BlueMarbleNextGeneration', projection: 'EPSG:3857', requestEncoding: 'REST' @@ -116,7 +116,7 @@ describe('ol.source.WMTS', function() { }); it('can find a MatrixSet by equivalent SRS identifier', function() { - const options = WMTS.optionsFromCapabilities(capabilities, { + const options = optionsFromCapabilities(capabilities, { layer: 'BlueMarbleNextGeneration', projection: 'EPSG:900913', requestEncoding: 'REST' @@ -127,7 +127,7 @@ describe('ol.source.WMTS', function() { }); it('can find the default MatrixSet', function() { - const options = WMTS.optionsFromCapabilities(capabilities, { + const options = optionsFromCapabilities(capabilities, { layer: 'BlueMarbleNextGeneration', requestEncoding: 'REST' }); @@ -137,7 +137,7 @@ describe('ol.source.WMTS', function() { }); it('uses the projection of the default MatrixSet if the config\'s projection is not supported', function() { - const options = WMTS.optionsFromCapabilities(capabilities, { + const options = optionsFromCapabilities(capabilities, { layer: 'BlueMarbleNextGeneration', projection: new Projection({ code: 'EPSG:2056', @@ -153,7 +153,7 @@ describe('ol.source.WMTS', function() { const tmpXml = content.replace(//g, ''); const tmpCapabilities = parser.read(tmpXml); expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined); - const options = WMTS.optionsFromCapabilities(tmpCapabilities, + const options = optionsFromCapabilities(tmpCapabilities, {layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'}); expect(options.layer).to.be.eql('BlueMarbleNextGeneration'); expect(options.matrixSet).to.be.eql('google3857'); @@ -166,7 +166,7 @@ describe('ol.source.WMTS', function() { const tmpCapabilities = parser.read(tmpXml); expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined); expect(tmpCapabilities['Contents']['Layer'][0]['ResourceURL']).to.be(undefined); - const options = WMTS.optionsFromCapabilities(tmpCapabilities, + const options = optionsFromCapabilities(tmpCapabilities, {layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'}); expect(options.layer).to.be.eql('BlueMarbleNextGeneration'); expect(options.matrixSet).to.be.eql('google3857'); @@ -247,7 +247,7 @@ describe('ol.source.WMTS', function() { it('can create KVP options from spec/ol/format/wmts/arcgis.xml', function() { - const options = WMTS.optionsFromCapabilities( + const options = optionsFromCapabilities( capabilities, { layer: 'Demographics_USA_Population_Density', requestEncoding: 'KVP', @@ -263,7 +263,7 @@ describe('ol.source.WMTS', function() { it('can create REST options from spec/ol/format/wmts/arcgis.xml', function() { - const options = WMTS.optionsFromCapabilities( + const options = optionsFromCapabilities( capabilities, { layer: 'Demographics_USA_Population_Density', matrixSet: 'default028mm' From 9b75dc949f7141a8796c0627052f287aa839de18 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:09:37 -0700 Subject: [PATCH 02/19] Named exports from ol/source/Vector --- src/ol/interaction/Snap.js | 6 ++-- src/ol/source/Vector.js | 62 ++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index c0f796e74b..c918144fcb 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -13,7 +13,7 @@ import GeometryType from '../geom/GeometryType.js'; import {fromCircle} from '../geom/Polygon.js'; import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js'; import {getValues} from '../obj.js'; -import VectorSource from '../source/Vector.js'; +import {VectorSourceEvent} from '../source/Vector.js'; import VectorEventType from '../source/VectorEventType.js'; import RBush from '../structs/RBush.js'; @@ -219,7 +219,7 @@ Snap.prototype.getFeatures_ = function() { */ Snap.prototype.handleFeatureAdd_ = function(evt) { let feature; - if (evt instanceof VectorSource.Event) { + if (evt instanceof VectorSourceEvent) { feature = evt.feature; } else if (evt instanceof CollectionEvent) { feature = evt.element; @@ -234,7 +234,7 @@ Snap.prototype.handleFeatureAdd_ = function(evt) { */ Snap.prototype.handleFeatureRemove_ = function(evt) { let feature; - if (evt instanceof VectorSource.Event) { + if (evt instanceof VectorSourceEvent) { feature = evt.feature; } else if (evt instanceof CollectionEvent) { feature = evt.element; diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index 20f2f256c8..5479cc65c2 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -21,6 +21,33 @@ import SourceState from '../source/State.js'; import VectorEventType from '../source/VectorEventType.js'; import RBush from '../structs/RBush.js'; + +/** + * @classdesc + * Events emitted by {@link ol.source.Vector} instances are instances of this + * type. + * + * @constructor + * @extends {ol.events.Event} + * @implements {oli.source.Vector.Event} + * @param {string} type Type. + * @param {ol.Feature=} opt_feature Feature. + */ +export const VectorSourceEvent = function(type, opt_feature) { + + Event.call(this, type); + + /** + * The feature being added or removed. + * @type {ol.Feature|undefined} + * @api + */ + this.feature = opt_feature; + +}; +inherits(VectorSourceEvent, Event); + + /** * @classdesc * Provides a source of features for vector layers. Vector features provided @@ -191,7 +218,7 @@ VectorSource.prototype.addFeatureInternal = function(feature) { } this.dispatchEvent( - new VectorSource.Event(VectorEventType.ADDFEATURE, feature)); + new VectorSourceEvent(VectorEventType.ADDFEATURE, feature)); }; @@ -283,7 +310,7 @@ VectorSource.prototype.addFeaturesInternal = function(features) { } for (let i = 0, length = newFeatures.length; i < length; i++) { - this.dispatchEvent(new VectorSource.Event(VectorEventType.ADDFEATURE, newFeatures[i])); + this.dispatchEvent(new VectorSourceEvent(VectorEventType.ADDFEATURE, newFeatures[i])); } }; @@ -364,7 +391,7 @@ VectorSource.prototype.clear = function(opt_fast) { this.loadedExtentsRtree_.clear(); this.nullGeometryFeatures_ = {}; - const clearEvent = new VectorSource.Event(VectorEventType.CLEAR); + const clearEvent = new VectorSourceEvent(VectorEventType.CLEAR); this.dispatchEvent(clearEvent); this.changed(); }; @@ -709,7 +736,7 @@ VectorSource.prototype.handleFeatureChange_ = function(event) { } } this.changed(); - this.dispatchEvent(new VectorSource.Event( + this.dispatchEvent(new VectorSourceEvent( VectorEventType.CHANGEFEATURE, feature)); }; @@ -805,7 +832,7 @@ VectorSource.prototype.removeFeatureInternal = function(feature) { } else { delete this.undefIdIndex_[featureKey]; } - this.dispatchEvent(new VectorSource.Event( + this.dispatchEvent(new VectorSourceEvent( VectorEventType.REMOVEFEATURE, feature)); }; @@ -840,29 +867,4 @@ VectorSource.prototype.setLoader = function(loader) { this.loader_ = loader; }; - -/** - * @classdesc - * Events emitted by {@link ol.source.Vector} instances are instances of this - * type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.source.Vector.Event} - * @param {string} type Type. - * @param {ol.Feature=} opt_feature Feature. - */ -VectorSource.Event = function(type, opt_feature) { - - Event.call(this, type); - - /** - * The feature being added or removed. - * @type {ol.Feature|undefined} - * @api - */ - this.feature = opt_feature; - -}; -inherits(VectorSource.Event, Event); export default VectorSource; From 57d2e7721d77ac7616f95af14522b96599e3c604 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:10:57 -0700 Subject: [PATCH 03/19] Remove static member from TileImage --- src/ol/source/TileImage.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ol/source/TileImage.js b/src/ol/source/TileImage.js index 1c567a0848..d630746da0 100644 --- a/src/ol/source/TileImage.js +++ b/src/ol/source/TileImage.js @@ -35,7 +35,7 @@ const TileImage = function(options) { state: options.state, tileGrid: options.tileGrid, tileLoadFunction: options.tileLoadFunction ? - options.tileLoadFunction : TileImage.defaultTileLoadFunction, + options.tileLoadFunction : defaultTileLoadFunction, tilePixelRatio: options.tilePixelRatio, tileUrlFunction: options.tileUrlFunction, url: options.url, @@ -365,7 +365,8 @@ TileImage.prototype.setTileGridForProjection = function(projection, tilegrid) { * @param {ol.ImageTile} imageTile Image tile. * @param {string} src Source. */ -TileImage.defaultTileLoadFunction = function(imageTile, src) { +function defaultTileLoadFunction(imageTile, src) { imageTile.getImage().src = src; -}; +} + export default TileImage; From e3f15e1d247104a4f9ba3a4756d78a5652b50db4 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:12:37 -0700 Subject: [PATCH 04/19] Named exports from ol/source/Tile --- src/ol/source/Tile.js | 5 +++-- src/ol/source/UrlTile.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ol/source/Tile.js b/src/ol/source/Tile.js index 72e0758364..232b23c89f 100644 --- a/src/ol/source/Tile.js +++ b/src/ol/source/Tile.js @@ -317,7 +317,7 @@ TileSource.prototype.useTile = nullFunction; * @param {string} type Type. * @param {ol.Tile} tile The tile. */ -TileSource.Event = function(type, tile) { +export const TileSourceEvent = function(type, tile) { Event.call(this, type); @@ -329,5 +329,6 @@ TileSource.Event = function(type, tile) { this.tile = tile; }; -inherits(TileSource.Event, Event); +inherits(TileSourceEvent, Event); + export default TileSource; diff --git a/src/ol/source/UrlTile.js b/src/ol/source/UrlTile.js index 0f27e23a7a..e3cfd1312e 100644 --- a/src/ol/source/UrlTile.js +++ b/src/ol/source/UrlTile.js @@ -4,7 +4,7 @@ import {getUid, inherits} from '../index.js'; import TileState from '../TileState.js'; import {expandUrl, createFromTemplates, nullTileUrlFunction} from '../tileurlfunction.js'; -import TileSource from '../source/Tile.js'; +import TileSource, {TileSourceEvent} from '../source/Tile.js'; import TileEventType from '../source/TileEventType.js'; import {getKeyZXY} from '../tilecoord.js'; @@ -130,7 +130,7 @@ UrlTile.prototype.handleTileChange = function(event) { TileEventType.TILELOADEND : undefined; } if (type != undefined) { - this.dispatchEvent(new TileSource.Event(type, tile)); + this.dispatchEvent(new TileSourceEvent(type, tile)); } }; From 7ab83f2722480809a71f14102a26b74c12354e70 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:17:07 -0700 Subject: [PATCH 05/19] Remove static members from Stamen --- src/ol/source/Stamen.js | 82 +++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/src/ol/source/Stamen.js b/src/ol/source/Stamen.js index 7434c70b47..d15cfe7933 100644 --- a/src/ol/source/Stamen.js +++ b/src/ol/source/Stamen.js @@ -5,58 +5,23 @@ import {inherits} from '../index.js'; import OSM from '../source/OSM.js'; import XYZ from '../source/XYZ.js'; -/** - * @classdesc - * Layer source for the Stamen tile server. - * - * @constructor - * @extends {ol.source.XYZ} - * @param {olx.source.StamenOptions} options Stamen options. - * @api - */ -const Stamen = function(options) { - const i = options.layer.indexOf('-'); - const provider = i == -1 ? options.layer : options.layer.slice(0, i); - const providerConfig = Stamen.ProviderConfig[provider]; - - const layerConfig = Stamen.LayerConfig[options.layer]; - - const url = options.url !== undefined ? options.url : - 'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer + - '/{z}/{x}/{y}.' + layerConfig.extension; - - XYZ.call(this, { - attributions: Stamen.ATTRIBUTIONS, - cacheSize: options.cacheSize, - crossOrigin: 'anonymous', - maxZoom: options.maxZoom != undefined ? options.maxZoom : providerConfig.maxZoom, - minZoom: options.minZoom != undefined ? options.minZoom : providerConfig.minZoom, - opaque: layerConfig.opaque, - reprojectionErrorThreshold: options.reprojectionErrorThreshold, - tileLoadFunction: options.tileLoadFunction, - url: url, - wrapX: options.wrapX - }); -}; - -inherits(Stamen, XYZ); - /** * @const * @type {Array.} */ -Stamen.ATTRIBUTIONS = [ +const ATTRIBUTIONS = [ 'Map tiles by Stamen Design, ' + 'under CC BY' + ' 3.0.', OSM.ATTRIBUTION ]; + /** * @type {Object.} */ -Stamen.LayerConfig = { +const LayerConfig = { 'terrain': { extension: 'jpg', opaque: true @@ -103,10 +68,11 @@ Stamen.LayerConfig = { } }; + /** * @type {Object.} */ -Stamen.ProviderConfig = { +const ProviderConfig = { 'terrain': { minZoom: 4, maxZoom: 18 @@ -120,4 +86,42 @@ Stamen.ProviderConfig = { maxZoom: 16 } }; + + +/** + * @classdesc + * Layer source for the Stamen tile server. + * + * @constructor + * @extends {ol.source.XYZ} + * @param {olx.source.StamenOptions} options Stamen options. + * @api + */ +const Stamen = function(options) { + const i = options.layer.indexOf('-'); + const provider = i == -1 ? options.layer : options.layer.slice(0, i); + const providerConfig = ProviderConfig[provider]; + + const layerConfig = LayerConfig[options.layer]; + + const url = options.url !== undefined ? options.url : + 'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer + + '/{z}/{x}/{y}.' + layerConfig.extension; + + XYZ.call(this, { + attributions: ATTRIBUTIONS, + cacheSize: options.cacheSize, + crossOrigin: 'anonymous', + maxZoom: options.maxZoom != undefined ? options.maxZoom : providerConfig.maxZoom, + minZoom: options.minZoom != undefined ? options.minZoom : providerConfig.minZoom, + opaque: layerConfig.opaque, + reprojectionErrorThreshold: options.reprojectionErrorThreshold, + tileLoadFunction: options.tileLoadFunction, + url: url, + wrapX: options.wrapX + }); +}; + +inherits(Stamen, XYZ); + export default Stamen; From 33d91f1b89d467233fa0dbd5b4fcff10cd9835fb Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:19:05 -0700 Subject: [PATCH 06/19] Remove static members from Raster --- src/ol/source/Raster.js | 86 ++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/ol/source/Raster.js b/src/ol/source/Raster.js index bc2543184d..be27c28e6c 100644 --- a/src/ol/source/Raster.js +++ b/src/ol/source/Raster.js @@ -42,6 +42,47 @@ const RasterEventType = { }; +/** + * @classdesc + * Events emitted by {@link ol.source.Raster} instances are instances of this + * type. + * + * @constructor + * @extends {ol.events.Event} + * @implements {oli.source.RasterEvent} + * @param {string} type Type. + * @param {olx.FrameState} frameState The frame state. + * @param {Object} data An object made available to operations. + */ +const RasterSourceEvent = function(type, frameState, data) { + Event.call(this, type); + + /** + * The raster extent. + * @type {ol.Extent} + * @api + */ + this.extent = frameState.extent; + + /** + * The pixel resolution (map units per pixel). + * @type {number} + * @api + */ + this.resolution = frameState.viewState.resolution / frameState.pixelRatio; + + /** + * An object made available to all operations. This can be used by operations + * as a storage object (e.g. for calculating statistics). + * @type {Object} + * @api + */ + this.data = data; + +}; +inherits(RasterSourceEvent, Event); + + /** * @classdesc * A source that transforms data from any number of input sources using an @@ -282,7 +323,7 @@ RasterSource.prototype.processSources_ = function() { } const data = {}; - this.dispatchEvent(new RasterSource.Event(RasterEventType.BEFOREOPERATIONS, frameState, data)); + this.dispatchEvent(new RasterSourceEvent(RasterEventType.BEFOREOPERATIONS, frameState, data)); this.worker_.process(imageDatas, data, this.onWorkerComplete_.bind(this, frameState)); }; @@ -322,7 +363,7 @@ RasterSource.prototype.onWorkerComplete_ = function(frameState, err, output, dat this.changed(); this.renderedRevision_ = this.getRevision(); - this.dispatchEvent(new RasterSource.Event(RasterEventType.AFTEROPERATIONS, frameState, data)); + this.dispatchEvent(new RasterSourceEvent(RasterEventType.AFTEROPERATIONS, frameState, data)); }; @@ -427,47 +468,6 @@ function createTileRenderer(source) { } -/** - * @classdesc - * Events emitted by {@link ol.source.Raster} instances are instances of this - * type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.source.RasterEvent} - * @param {string} type Type. - * @param {olx.FrameState} frameState The frame state. - * @param {Object} data An object made available to operations. - */ -RasterSource.Event = function(type, frameState, data) { - Event.call(this, type); - - /** - * The raster extent. - * @type {ol.Extent} - * @api - */ - this.extent = frameState.extent; - - /** - * The pixel resolution (map units per pixel). - * @type {number} - * @api - */ - this.resolution = frameState.viewState.resolution / frameState.pixelRatio; - - /** - * An object made available to all operations. This can be used by operations - * as a storage object (e.g. for calculating statistics). - * @type {Object} - * @api - */ - this.data = data; - -}; -inherits(RasterSource.Event, Event); - - /** * @override */ From 42cf5f8511f10b69528e9a9febc99b9bd99ce044 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:23:05 -0700 Subject: [PATCH 07/19] Named exports from ol/source/OSM --- examples/igc.js | 4 ++-- examples/localized-openstreetmap.js | 6 +++--- src/ol/source/OSM.js | 26 ++++++++++++++------------ src/ol/source/Stamen.js | 4 ++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/igc.js b/examples/igc.js index 275a736ebd..1f993eb506 100644 --- a/examples/igc.js +++ b/examples/igc.js @@ -7,7 +7,7 @@ import LineString from '../src/ol/geom/LineString.js'; import Point from '../src/ol/geom/Point.js'; import TileLayer from '../src/ol/layer/Tile.js'; import VectorLayer from '../src/ol/layer/Vector.js'; -import OSM from '../src/ol/source/OSM.js'; +import OSM, {ATTRIBUTION} from '../src/ol/source/OSM.js'; import VectorSource from '../src/ol/source/Vector.js'; import CircleStyle from '../src/ol/style/Circle.js'; import Fill from '../src/ol/style/Fill.js'; @@ -86,7 +86,7 @@ const map = new Map({ source: new OSM({ attributions: [ 'All maps © OpenCycleMap', - OSM.ATTRIBUTION + ATTRIBUTION ], url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' + '?apikey=0e6fc415256d4fbb9b5166a718591d71' diff --git a/examples/localized-openstreetmap.js b/examples/localized-openstreetmap.js index cea87b8b9d..562cfcf540 100644 --- a/examples/localized-openstreetmap.js +++ b/examples/localized-openstreetmap.js @@ -2,14 +2,14 @@ import Map from '../src/ol/Map.js'; import View from '../src/ol/View.js'; import {defaults as defaultControls} from '../src/ol/control.js'; import TileLayer from '../src/ol/layer/Tile.js'; -import OSM from '../src/ol/source/OSM.js'; +import OSM, {ATTRIBUTION} from '../src/ol/source/OSM.js'; const openCycleMapLayer = new TileLayer({ source: new OSM({ attributions: [ 'All maps © OpenCycleMap', - OSM.ATTRIBUTION + ATTRIBUTION ], url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' + '?apikey=0e6fc415256d4fbb9b5166a718591d71' @@ -20,7 +20,7 @@ const openSeaMapLayer = new TileLayer({ source: new OSM({ attributions: [ 'All maps © OpenSeaMap', - OSM.ATTRIBUTION + ATTRIBUTION ], opaque: false, url: 'https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png' diff --git a/src/ol/source/OSM.js b/src/ol/source/OSM.js index f934d0762f..a583bc5ffc 100644 --- a/src/ol/source/OSM.js +++ b/src/ol/source/OSM.js @@ -4,6 +4,19 @@ import {inherits} from '../index.js'; import XYZ from '../source/XYZ.js'; + +/** + * The attribution containing a link to the OpenStreetMap Copyright and License + * page. + * @const + * @type {string} + * @api + */ +export const ATTRIBUTION = '© ' + + 'OpenStreetMap ' + + 'contributors.'; + + /** * @classdesc * Layer source for the OpenStreetMap tile server. @@ -21,7 +34,7 @@ const OSM = function(opt_options) { if (options.attributions !== undefined) { attributions = options.attributions; } else { - attributions = [OSM.ATTRIBUTION]; + attributions = [ATTRIBUTION]; } const crossOrigin = options.crossOrigin !== undefined ? @@ -46,15 +59,4 @@ const OSM = function(opt_options) { inherits(OSM, XYZ); - -/** - * The attribution containing a link to the OpenStreetMap Copyright and License - * page. - * @const - * @type {string} - * @api - */ -OSM.ATTRIBUTION = '© ' + - 'OpenStreetMap ' + - 'contributors.'; export default OSM; diff --git a/src/ol/source/Stamen.js b/src/ol/source/Stamen.js index d15cfe7933..a691162587 100644 --- a/src/ol/source/Stamen.js +++ b/src/ol/source/Stamen.js @@ -2,7 +2,7 @@ * @module ol/source/Stamen */ import {inherits} from '../index.js'; -import OSM from '../source/OSM.js'; +import {ATTRIBUTION as OSM_ATTRIBUTION} from '../source/OSM.js'; import XYZ from '../source/XYZ.js'; @@ -14,7 +14,7 @@ const ATTRIBUTIONS = [ 'Map tiles by Stamen Design, ' + 'under CC BY' + ' 3.0.', - OSM.ATTRIBUTION + OSM_ATTRIBUTION ]; From 12eccdc52dad6af8857c9cbead6849e6a3e9dbe3 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:24:24 -0700 Subject: [PATCH 08/19] Remove static members from ImageMapGuide --- src/ol/source/ImageMapGuide.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ol/source/ImageMapGuide.js b/src/ol/source/ImageMapGuide.js index 59eb0b5249..1068840ac5 100644 --- a/src/ol/source/ImageMapGuide.js +++ b/src/ol/source/ImageMapGuide.js @@ -173,7 +173,7 @@ ImageMapGuide.prototype.getImageLoadFunction = function() { * @param {number} dpi The display resolution. * @return {number} The computed map scale. */ -ImageMapGuide.getScale = function(extent, size, metersPerUnit, dpi) { +function getScale(extent, size, metersPerUnit, dpi) { const mcsW = getWidth(extent); const mcsH = getHeight(extent); const devW = size[0]; @@ -184,7 +184,7 @@ ImageMapGuide.getScale = function(extent, size, metersPerUnit, dpi) { } else { return mcsH * metersPerUnit / (devH * mpp); // height limited } -}; +} /** @@ -207,7 +207,7 @@ ImageMapGuide.prototype.updateParams = function(params) { * @return {string} The mapagent map image request URL. */ ImageMapGuide.prototype.getUrl = function(baseUrl, params, extent, size, projection) { - const scale = ImageMapGuide.getScale(extent, size, + const scale = getScale(extent, size, this.metersPerUnit_, this.displayDpi_); const center = getCenter(extent); const baseParams = { From 2188c5fa9105223b424f89abec72fe770aaf72d4 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:27:23 -0700 Subject: [PATCH 09/19] Remove static members from ImageSource --- src/ol/source/Image.js | 62 ++++++++++++++++---------------- src/ol/source/ImageArcGISRest.js | 4 +-- src/ol/source/ImageMapGuide.js | 4 +-- src/ol/source/ImageStatic.js | 4 +-- src/ol/source/ImageWMS.js | 4 +-- test/spec/ol/imagetile.test.js | 10 +++--- test/spec/ol/tilequeue.test.js | 4 +-- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/ol/source/Image.js b/src/ol/source/Image.js index df934ad189..4f0f3c3f08 100644 --- a/src/ol/source/Image.js +++ b/src/ol/source/Image.js @@ -41,6 +41,32 @@ const ImageSourceEventType = { }; +/** + * @classdesc + * Events emitted by {@link ol.source.Image} instances are instances of this + * type. + * + * @constructor + * @extends {ol.events.Event} + * @implements {oli.source.ImageEvent} + * @param {string} type Type. + * @param {ol.Image} image The image. + */ +const ImageSourceEvent = function(type, image) { + + Event.call(this, type); + + /** + * The image related to the event. + * @type {ol.Image} + * @api + */ + this.image = image; + +}; +inherits(ImageSourceEvent, Event); + + /** * @classdesc * Abstract base class; normally only used for creating subclasses and not @@ -174,17 +200,17 @@ ImageSource.prototype.handleImageChange = function(event) { switch (image.getState()) { case ImageState.LOADING: this.dispatchEvent( - new ImageSource.Event(ImageSourceEventType.IMAGELOADSTART, + new ImageSourceEvent(ImageSourceEventType.IMAGELOADSTART, image)); break; case ImageState.LOADED: this.dispatchEvent( - new ImageSource.Event(ImageSourceEventType.IMAGELOADEND, + new ImageSourceEvent(ImageSourceEventType.IMAGELOADEND, image)); break; case ImageState.ERROR: this.dispatchEvent( - new ImageSource.Event(ImageSourceEventType.IMAGELOADERROR, + new ImageSourceEvent(ImageSourceEventType.IMAGELOADERROR, image)); break; default: @@ -199,35 +225,9 @@ ImageSource.prototype.handleImageChange = function(event) { * @param {ol.Image} image Image. * @param {string} src Source. */ -ImageSource.defaultImageLoadFunction = function(image, src) { +export function defaultImageLoadFunction(image, src) { image.getImage().src = src; -}; - - -/** - * @classdesc - * Events emitted by {@link ol.source.Image} instances are instances of this - * type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.source.ImageEvent} - * @param {string} type Type. - * @param {ol.Image} image The image. - */ -ImageSource.Event = function(type, image) { - - Event.call(this, type); - - /** - * The image related to the event. - * @type {ol.Image} - * @api - */ - this.image = image; - -}; -inherits(ImageSource.Event, Event); +} export default ImageSource; diff --git a/src/ol/source/ImageArcGISRest.js b/src/ol/source/ImageArcGISRest.js index 6a4b5e600d..c2461985b4 100644 --- a/src/ol/source/ImageArcGISRest.js +++ b/src/ol/source/ImageArcGISRest.js @@ -8,7 +8,7 @@ import {listen} from '../events.js'; import EventType from '../events/EventType.js'; import {containsExtent, getHeight, getWidth} from '../extent.js'; import {assign} from '../obj.js'; -import ImageSource from '../source/Image.js'; +import ImageSource, {defaultImageLoadFunction} from '../source/Image.js'; import {appendParams} from '../uri.js'; /** @@ -60,7 +60,7 @@ const ImageArcGISRest = function(opt_options) { * @type {ol.ImageLoadFunctionType} */ this.imageLoadFunction_ = options.imageLoadFunction !== undefined ? - options.imageLoadFunction : ImageSource.defaultImageLoadFunction; + options.imageLoadFunction : defaultImageLoadFunction; /** diff --git a/src/ol/source/ImageMapGuide.js b/src/ol/source/ImageMapGuide.js index 1068840ac5..841004f5e5 100644 --- a/src/ol/source/ImageMapGuide.js +++ b/src/ol/source/ImageMapGuide.js @@ -7,7 +7,7 @@ import {listen} from '../events.js'; import EventType from '../events/EventType.js'; import {containsExtent, getCenter, getHeight, getWidth, scaleFromCenter} from '../extent.js'; import {assign} from '../obj.js'; -import ImageSource from '../source/Image.js'; +import ImageSource, {defaultImageLoadFunction} from '../source/Image.js'; import {appendParams} from '../uri.js'; /** @@ -58,7 +58,7 @@ const ImageMapGuide = function(options) { * @type {ol.ImageLoadFunctionType} */ this.imageLoadFunction_ = options.imageLoadFunction !== undefined ? - options.imageLoadFunction : ImageSource.defaultImageLoadFunction; + options.imageLoadFunction : defaultImageLoadFunction; /** * @private diff --git a/src/ol/source/ImageStatic.js b/src/ol/source/ImageStatic.js index 0481f3109b..304b5ace52 100644 --- a/src/ol/source/ImageStatic.js +++ b/src/ol/source/ImageStatic.js @@ -9,7 +9,7 @@ import {listen} from '../events.js'; import EventType from '../events/EventType.js'; import {intersects, getHeight, getWidth} from '../extent.js'; import {get as getProjection} from '../proj.js'; -import ImageSource from '../source/Image.js'; +import ImageSource, {defaultImageLoadFunction} from '../source/Image.js'; /** * @classdesc @@ -28,7 +28,7 @@ const Static = function(options) { const /** @type {ol.ImageLoadFunctionType} */ imageLoadFunction = options.imageLoadFunction !== undefined ? - options.imageLoadFunction : ImageSource.defaultImageLoadFunction; + options.imageLoadFunction : defaultImageLoadFunction; ImageSource.call(this, { attributions: options.attributions, diff --git a/src/ol/source/ImageWMS.js b/src/ol/source/ImageWMS.js index e78a7ebe22..f0d2c4a858 100644 --- a/src/ol/source/ImageWMS.js +++ b/src/ol/source/ImageWMS.js @@ -12,7 +12,7 @@ import {containsExtent, getCenter, getForViewAndSize, getHeight, getWidth} from import {assign} from '../obj.js'; import {get as getProjection, transform} from '../proj.js'; import {calculateSourceResolution} from '../reproj.js'; -import ImageSource from '../source/Image.js'; +import ImageSource, {defaultImageLoadFunction} from '../source/Image.js'; import WMSServerType from '../source/WMSServerType.js'; import {compareVersions} from '../string.js'; import {appendParams} from '../uri.js'; @@ -55,7 +55,7 @@ const ImageWMS = function(opt_options) { * @type {ol.ImageLoadFunctionType} */ this.imageLoadFunction_ = options.imageLoadFunction !== undefined ? - options.imageLoadFunction : ImageSource.defaultImageLoadFunction; + options.imageLoadFunction : defaultImageLoadFunction; /** * @private diff --git a/test/spec/ol/imagetile.test.js b/test/spec/ol/imagetile.test.js index fb897ecde2..eb35ed9f18 100644 --- a/test/spec/ol/imagetile.test.js +++ b/test/spec/ol/imagetile.test.js @@ -2,7 +2,7 @@ import ImageTile from '../../../src/ol/ImageTile.js'; import TileState from '../../../src/ol/TileState.js'; import {listen, unlistenByKey} from '../../../src/ol/events.js'; import EventType from '../../../src/ol/events/EventType.js'; -import ImageSource from '../../../src/ol/source/Image.js'; +import {defaultImageLoadFunction} from '../../../src/ol/source/Image.js'; describe('ol.ImageTile', function() { @@ -13,7 +13,7 @@ describe('ol.ImageTile', function() { const tileCoord = [0, 0, 0]; const state = TileState.IDLE; const src = 'spec/ol/data/osm-0-0-0.png'; - const tileLoadFunction = ImageSource.defaultImageLoadFunction; + const tileLoadFunction = defaultImageLoadFunction; const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); let previousState = tile.getState(); @@ -38,7 +38,7 @@ describe('ol.ImageTile', function() { const tileCoord = [0, 0, 0]; const state = TileState.ERROR; const src = 'spec/ol/data/osm-0-0-0.png'; - const tileLoadFunction = ImageSource.defaultImageLoadFunction; + const tileLoadFunction = defaultImageLoadFunction; const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); let previousState = tile.getState(); @@ -63,7 +63,7 @@ describe('ol.ImageTile', function() { const tileCoord = [0, 0, 0]; const state = TileState.IDLE; const src = 'spec/ol/data/osm-0-0-99.png'; - const tileLoadFunction = ImageSource.defaultImageLoadFunction; + const tileLoadFunction = defaultImageLoadFunction; const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); const key = listen(tile, EventType.CHANGE, function(event) { @@ -89,7 +89,7 @@ describe('ol.ImageTile', function() { const tileCoord = [0, 0, 0]; const state = TileState.IDLE; const src = 'spec/ol/data/osm-0-0-0.png'; - const tileLoadFunction = ImageSource.defaultImageLoadFunction; + const tileLoadFunction = defaultImageLoadFunction; const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction); tile.load(); expect(tile.getState()).to.be(TileState.LOADING); diff --git a/test/spec/ol/tilequeue.test.js b/test/spec/ol/tilequeue.test.js index 865e78a602..c92e02a34a 100644 --- a/test/spec/ol/tilequeue.test.js +++ b/test/spec/ol/tilequeue.test.js @@ -2,7 +2,7 @@ import ImageTile from '../../../src/ol/ImageTile.js'; import Tile from '../../../src/ol/Tile.js'; import TileQueue from '../../../src/ol/TileQueue.js'; import TileState from '../../../src/ol/TileState.js'; -import ImageSource from '../../../src/ol/source/Image.js'; +import {defaultImageLoadFunction} from '../../../src/ol/source/Image.js'; import {DROP} from '../../../src/ol/structs/PriorityQueue.js'; @@ -32,7 +32,7 @@ describe('ol.TileQueue', function() { 'yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; const tileLoadFunction = opt_tileLoadFunction ? - opt_tileLoadFunction : ImageSource.defaultImageLoadFunction; + opt_tileLoadFunction : defaultImageLoadFunction; return new ImageTile(tileCoord, state, src, null, tileLoadFunction); } From c5bf6f1c6f06e4092670690465bb6757317eb564 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:30:03 -0700 Subject: [PATCH 10/19] Remove static members from BingMaps --- src/ol/source/BingMaps.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ol/source/BingMaps.js b/src/ol/source/BingMaps.js index 3b0e8d3e06..5bb46b29e0 100644 --- a/src/ol/source/BingMaps.js +++ b/src/ol/source/BingMaps.js @@ -83,9 +83,8 @@ inherits(BingMaps, TileImage); * Terms Of Use. * @const * @type {string} - * @api */ -BingMaps.TOS_ATTRIBUTION = '' + 'Terms of Use'; @@ -197,7 +196,7 @@ BingMaps.prototype.handleImageryMetadataResponse = function(response) { } }); - attributions.push(BingMaps.TOS_ATTRIBUTION); + attributions.push(TOS_ATTRIBUTION); return attributions; }); } From ef926490174f9c586e456f818e5efd9cac5c12af Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:41:48 -0700 Subject: [PATCH 11/19] Remove static members from Units --- src/ol/proj.js | 6 +++--- src/ol/proj/Projection.js | 4 ++-- src/ol/proj/Units.js | 13 +++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ol/proj.js b/src/ol/proj.js index d16bc58480..7ffce664ea 100644 --- a/src/ol/proj.js +++ b/src/ol/proj.js @@ -7,7 +7,7 @@ import {modulo} from './math.js'; import {toEPSG4326, fromEPSG4326, PROJECTIONS as EPSG3857_PROJECTIONS} from './proj/epsg3857.js'; import {PROJECTIONS as EPSG4326_PROJECTIONS} from './proj/epsg4326.js'; import Projection from './proj/Projection.js'; -import Units from './proj/Units.js'; +import Units, {METERS_PER_UNIT} from './proj/Units.js'; import * as projections from './proj/projections.js'; import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransformFunc} from './proj/transforms.js'; @@ -18,7 +18,7 @@ import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransfo * @type {Object.} * @api */ -export const METERS_PER_UNIT = Units.METERS_PER_UNIT; +export {METERS_PER_UNIT}; /** @@ -147,7 +147,7 @@ export function getPointResolution(projection, resolution, point, opt_units) { const height = getDistance(vertices.slice(4, 6), vertices.slice(6, 8)); pointResolution = (width + height) / 2; const metersPerUnit = opt_units ? - Units.METERS_PER_UNIT[opt_units] : + METERS_PER_UNIT[opt_units] : projection.getMetersPerUnit(); if (metersPerUnit !== undefined) { pointResolution /= metersPerUnit; diff --git a/src/ol/proj/Projection.js b/src/ol/proj/Projection.js index f1184a124c..80008d2cc5 100644 --- a/src/ol/proj/Projection.js +++ b/src/ol/proj/Projection.js @@ -1,7 +1,7 @@ /** * @module ol/proj/Projection */ -import Units from '../proj/Units.js'; +import {METERS_PER_UNIT} from '../proj/Units.js'; /** * @classdesc @@ -153,7 +153,7 @@ Projection.prototype.getUnits = function() { * @api */ Projection.prototype.getMetersPerUnit = function() { - return this.metersPerUnit_ || Units.METERS_PER_UNIT[this.units_]; + return this.metersPerUnit_ || METERS_PER_UNIT[this.units_]; }; diff --git a/src/ol/proj/Units.js b/src/ol/proj/Units.js index d41eb17de8..25b8041517 100644 --- a/src/ol/proj/Units.js +++ b/src/ol/proj/Units.js @@ -1,6 +1,7 @@ /** * @module ol/proj/Units */ + /** * Projection units: `'degrees'`, `'ft'`, `'m'`, `'pixels'`, `'tile-pixels'` or * `'us-ft'`. @@ -22,11 +23,11 @@ const Units = { * @type {Object.} * @api */ -Units.METERS_PER_UNIT = {}; +export const METERS_PER_UNIT = {}; // use the radius of the Normal sphere -Units.METERS_PER_UNIT[Units.DEGREES] = - 2 * Math.PI * 6370997 / 360; -Units.METERS_PER_UNIT[Units.FEET] = 0.3048; -Units.METERS_PER_UNIT[Units.METERS] = 1; -Units.METERS_PER_UNIT[Units.USFEET] = 1200 / 3937; +METERS_PER_UNIT[Units.DEGREES] = 2 * Math.PI * 6370997 / 360; +METERS_PER_UNIT[Units.FEET] = 0.3048; +METERS_PER_UNIT[Units.METERS] = 1; +METERS_PER_UNIT[Units.USFEET] = 1200 / 3937; + export default Units; From 4e6cf58de1a46fb1a3970b93fe6b50f41d73202f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:48:53 -0700 Subject: [PATCH 12/19] Remove static members from BaseObject --- src/ol/Feature.js | 8 ++-- src/ol/Geolocation.js | 6 +-- src/ol/Object.js | 75 +++++++++++++++++---------------- src/ol/Overlay.js | 12 +++--- src/ol/PluggableMap.js | 10 ++--- src/ol/control/MousePosition.js | 4 +- src/ol/control/OverviewMap.js | 6 +-- src/ol/control/ScaleLine.js | 4 +- src/ol/interaction/Draw.js | 4 +- src/ol/interaction/Translate.js | 4 +- src/ol/layer/Group.js | 4 +- src/ol/layer/Heatmap.js | 8 ++-- src/ol/layer/Layer.js | 4 +- 13 files changed, 76 insertions(+), 73 deletions(-) diff --git a/src/ol/Feature.js b/src/ol/Feature.js index fa0de7875f..8cf65df0c7 100644 --- a/src/ol/Feature.js +++ b/src/ol/Feature.js @@ -5,7 +5,7 @@ import {assert} from './asserts.js'; import {listen, unlisten, unlistenByKey} from './events.js'; import EventType from './events/EventType.js'; import {inherits} from './index.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import Geometry from './geom/Geometry.js'; import Style from './style/Style.js'; @@ -90,7 +90,7 @@ const Feature = function(opt_geometryOrProperties) { this.geometryChangeKey_ = null; listen( - this, BaseObject.getChangeEventType(this.geometryName_), + this, getChangeEventType(this.geometryName_), this.handleGeometryChanged_, this); if (opt_geometryOrProperties !== undefined) { @@ -266,11 +266,11 @@ Feature.prototype.setId = function(id) { */ Feature.prototype.setGeometryName = function(name) { unlisten( - this, BaseObject.getChangeEventType(this.geometryName_), + this, getChangeEventType(this.geometryName_), this.handleGeometryChanged_, this); this.geometryName_ = name; listen( - this, BaseObject.getChangeEventType(this.geometryName_), + this, getChangeEventType(this.geometryName_), this.handleGeometryChanged_, this); this.handleGeometryChanged_(); }; diff --git a/src/ol/Geolocation.js b/src/ol/Geolocation.js index c3a0671983..4cebf5ea81 100644 --- a/src/ol/Geolocation.js +++ b/src/ol/Geolocation.js @@ -3,7 +3,7 @@ */ import {inherits} from './index.js'; import GeolocationProperty from './GeolocationProperty.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import {listen} from './events.js'; import EventType from './events/EventType.js'; import {circular as circularPolygon} from './geom/Polygon.js'; @@ -79,10 +79,10 @@ const Geolocation = function(opt_options) { this.watchId_ = undefined; listen( - this, BaseObject.getChangeEventType(GeolocationProperty.PROJECTION), + this, getChangeEventType(GeolocationProperty.PROJECTION), this.handleProjectionChanged_, this); listen( - this, BaseObject.getChangeEventType(GeolocationProperty.TRACKING), + this, getChangeEventType(GeolocationProperty.TRACKING), this.handleTrackingChanged_, this); if (options.projection !== undefined) { diff --git a/src/ol/Object.js b/src/ol/Object.js index 67ccb3c354..2a51192d43 100644 --- a/src/ol/Object.js +++ b/src/ol/Object.js @@ -7,6 +7,40 @@ import Observable from './Observable.js'; import Event from './events/Event.js'; import {assign} from './obj.js'; + +/** + * @classdesc + * Events emitted by {@link ol.Object} instances are instances of this type. + * + * @param {string} type The event type. + * @param {string} key The property name. + * @param {*} oldValue The old value for `key`. + * @extends {ol.events.Event} + * @implements {oli.Object.Event} + * @constructor + */ +const BaseObjectEvent = function(type, key, oldValue) { + Event.call(this, type); + + /** + * The name of the property whose value is changing. + * @type {string} + * @api + */ + this.key = key; + + /** + * The old value. To get the new value use `e.target.get(e.key)` where + * `e` is the event object. + * @type {*} + * @api + */ + this.oldValue = oldValue; + +}; +inherits(BaseObjectEvent, Event); + + /** * @classdesc * Abstract base class; normally only used for creating subclasses and not @@ -85,11 +119,11 @@ const changeEventTypeCache = {}; * @param {string} key Key name. * @return {string} Change name. */ -BaseObject.getChangeEventType = function(key) { +export function getChangeEventType(key) { return changeEventTypeCache.hasOwnProperty(key) ? changeEventTypeCache[key] : (changeEventTypeCache[key] = 'change:' + key); -}; +} /** @@ -133,10 +167,10 @@ BaseObject.prototype.getProperties = function() { */ BaseObject.prototype.notify = function(key, oldValue) { let eventType; - eventType = BaseObject.getChangeEventType(key); - this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue)); + eventType = getChangeEventType(key); + this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue)); eventType = ObjectEventType.PROPERTYCHANGE; - this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue)); + this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue)); }; @@ -191,35 +225,4 @@ BaseObject.prototype.unset = function(key, opt_silent) { }; -/** - * @classdesc - * Events emitted by {@link ol.Object} instances are instances of this type. - * - * @param {string} type The event type. - * @param {string} key The property name. - * @param {*} oldValue The old value for `key`. - * @extends {ol.events.Event} - * @implements {oli.Object.Event} - * @constructor - */ -BaseObject.Event = function(type, key, oldValue) { - Event.call(this, type); - - /** - * The name of the property whose value is changing. - * @type {string} - * @api - */ - this.key = key; - - /** - * The old value. To get the new value use `e.target.get(e.key)` where - * `e` is the event object. - * @type {*} - * @api - */ - this.oldValue = oldValue; - -}; -inherits(BaseObject.Event, Event); export default BaseObject; diff --git a/src/ol/Overlay.js b/src/ol/Overlay.js index a4a01a125a..b739ae480b 100644 --- a/src/ol/Overlay.js +++ b/src/ol/Overlay.js @@ -3,7 +3,7 @@ */ import {inherits} from './index.js'; import MapEventType from './MapEventType.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import OverlayPositioning from './OverlayPositioning.js'; import {CLASS_SELECTABLE} from './css.js'; import {removeNode, removeChildren, outerWidth, outerHeight} from './dom.js'; @@ -126,23 +126,23 @@ const Overlay = function(options) { this.mapPostrenderListenerKey = null; listen( - this, BaseObject.getChangeEventType(Property.ELEMENT), + this, getChangeEventType(Property.ELEMENT), this.handleElementChanged, this); listen( - this, BaseObject.getChangeEventType(Property.MAP), + this, getChangeEventType(Property.MAP), this.handleMapChanged, this); listen( - this, BaseObject.getChangeEventType(Property.OFFSET), + this, getChangeEventType(Property.OFFSET), this.handleOffsetChanged, this); listen( - this, BaseObject.getChangeEventType(Property.POSITION), + this, getChangeEventType(Property.POSITION), this.handlePositionChanged, this); listen( - this, BaseObject.getChangeEventType(Property.POSITIONING), + this, getChangeEventType(Property.POSITIONING), this.handlePositioningChanged, this); if (options.element !== undefined) { diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index 83c1869fce..36780ba8cd 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -10,7 +10,7 @@ import MapBrowserEventType from './MapBrowserEventType.js'; import MapEvent from './MapEvent.js'; import MapEventType from './MapEventType.js'; import MapProperty from './MapProperty.js'; -import BaseObject from './Object.js'; +import BaseObject, {getChangeEventType} from './Object.js'; import ObjectEventType from './ObjectEventType.js'; import TileQueue from './TileQueue.js'; import View from './View.js'; @@ -346,13 +346,13 @@ const PluggableMap = function(options) { this.skippedFeatureUids_ = {}; listen( - this, BaseObject.getChangeEventType(MapProperty.LAYERGROUP), + this, getChangeEventType(MapProperty.LAYERGROUP), this.handleLayerGroupChanged_, this); - listen(this, BaseObject.getChangeEventType(MapProperty.VIEW), + listen(this, getChangeEventType(MapProperty.VIEW), this.handleViewChanged_, this); - listen(this, BaseObject.getChangeEventType(MapProperty.SIZE), + listen(this, getChangeEventType(MapProperty.SIZE), this.handleSizeChanged_, this); - listen(this, BaseObject.getChangeEventType(MapProperty.TARGET), + listen(this, getChangeEventType(MapProperty.TARGET), this.handleTargetChanged_, this); // setProperties will trigger the rendering of the map if the map diff --git a/src/ol/control/MousePosition.js b/src/ol/control/MousePosition.js index d7311769f9..65e62beca1 100644 --- a/src/ol/control/MousePosition.js +++ b/src/ol/control/MousePosition.js @@ -5,7 +5,7 @@ import {inherits} from '../index.js'; import {listen} from '../events.js'; import EventType from '../events/EventType.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import Control from '../control/Control.js'; import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js'; @@ -48,7 +48,7 @@ const MousePosition = function(opt_options) { }); listen(this, - BaseObject.getChangeEventType(PROJECTION), + getChangeEventType(PROJECTION), this.handleProjectionChanged_, this); if (options.coordinateFormat) { diff --git a/src/ol/control/OverviewMap.js b/src/ol/control/OverviewMap.js index e052e0d6bb..d0ac6ebaaa 100644 --- a/src/ol/control/OverviewMap.js +++ b/src/ol/control/OverviewMap.js @@ -6,7 +6,7 @@ import Collection from '../Collection.js'; import PluggableMap from '../PluggableMap.js'; import MapEventType from '../MapEventType.js'; import MapProperty from '../MapProperty.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import ObjectEventType from '../ObjectEventType.js'; import Overlay from '../Overlay.js'; import OverlayPositioning from '../OverlayPositioning.js'; @@ -270,7 +270,7 @@ OverviewMap.prototype.handleMapPropertyChange_ = function(event) { */ OverviewMap.prototype.bindView_ = function(view) { listen(view, - BaseObject.getChangeEventType(ViewProperty.ROTATION), + getChangeEventType(ViewProperty.ROTATION), this.handleRotationChanged_, this); }; @@ -282,7 +282,7 @@ OverviewMap.prototype.bindView_ = function(view) { */ OverviewMap.prototype.unbindView_ = function(view) { unlisten(view, - BaseObject.getChangeEventType(ViewProperty.ROTATION), + getChangeEventType(ViewProperty.ROTATION), this.handleRotationChanged_, this); }; diff --git a/src/ol/control/ScaleLine.js b/src/ol/control/ScaleLine.js index 00091a8eb0..15efa83991 100644 --- a/src/ol/control/ScaleLine.js +++ b/src/ol/control/ScaleLine.js @@ -2,7 +2,7 @@ * @module ol/control/ScaleLine */ import {inherits} from '../index.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {assert} from '../asserts.js'; import Control from '../control/Control.js'; import ScaleLineUnits from '../control/ScaleLineUnits.js'; @@ -98,7 +98,7 @@ const ScaleLine = function(opt_options) { }); listen( - this, BaseObject.getChangeEventType(UNITS), + this, getChangeEventType(UNITS), this.handleUnitsChanged_, this); this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) || diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 632651b878..7f0a1e5935 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -6,7 +6,7 @@ import EventType from '../events/EventType.js'; import Feature from '../Feature.js'; import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js'; import {listen} from '../events.js'; import Event from '../events/Event.js'; @@ -365,7 +365,7 @@ const Draw = function(options) { } listen(this, - BaseObject.getChangeEventType(InteractionProperty.ACTIVE), + getChangeEventType(InteractionProperty.ACTIVE), this.updateState_, this); }; diff --git a/src/ol/interaction/Translate.js b/src/ol/interaction/Translate.js index 7564086d93..b0fc3100ca 100644 --- a/src/ol/interaction/Translate.js +++ b/src/ol/interaction/Translate.js @@ -3,7 +3,7 @@ */ import {inherits} from '../index.js'; import Collection from '../Collection.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {listen} from '../events.js'; import Event from '../events/Event.js'; import {TRUE} from '../functions.js'; @@ -80,7 +80,7 @@ const Translate = function(opt_options) { this.lastFeature_ = null; listen(this, - BaseObject.getChangeEventType(InteractionProperty.ACTIVE), + getChangeEventType(InteractionProperty.ACTIVE), this.handleActiveChanged_, this); }; diff --git a/src/ol/layer/Group.js b/src/ol/layer/Group.js index 3a4c516e53..99035973f9 100644 --- a/src/ol/layer/Group.js +++ b/src/ol/layer/Group.js @@ -4,7 +4,7 @@ import {getUid, inherits} from '../index.js'; import Collection from '../Collection.js'; import CollectionEventType from '../CollectionEventType.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import ObjectEventType from '../ObjectEventType.js'; import {assert} from '../asserts.js'; import {listen, unlistenByKey} from '../events.js'; @@ -58,7 +58,7 @@ const LayerGroup = function(opt_options) { this.listenerKeys_ = {}; listen(this, - BaseObject.getChangeEventType(Property.LAYERS), + getChangeEventType(Property.LAYERS), this.handleLayersChanged_, this); if (layers) { diff --git a/src/ol/layer/Heatmap.js b/src/ol/layer/Heatmap.js index c30749dd00..ec8474503e 100644 --- a/src/ol/layer/Heatmap.js +++ b/src/ol/layer/Heatmap.js @@ -3,7 +3,7 @@ */ import {listen} from '../events.js'; import {inherits} from '../index.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import {createCanvasContext2D} from '../dom.js'; import VectorLayer from '../layer/Vector.js'; import {clamp} from '../math.js'; @@ -81,7 +81,7 @@ const Heatmap = function(opt_options) { this.styleCache_ = null; listen(this, - BaseObject.getChangeEventType(Property.GRADIENT), + getChangeEventType(Property.GRADIENT), this.handleGradientChanged_, this); this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT); @@ -91,10 +91,10 @@ const Heatmap = function(opt_options) { this.setRadius(options.radius !== undefined ? options.radius : 8); listen(this, - BaseObject.getChangeEventType(Property.BLUR), + getChangeEventType(Property.BLUR), this.handleStyleChanged_, this); listen(this, - BaseObject.getChangeEventType(Property.RADIUS), + getChangeEventType(Property.RADIUS), this.handleStyleChanged_, this); this.handleStyleChanged_(); diff --git a/src/ol/layer/Layer.js b/src/ol/layer/Layer.js index 20b4207bd3..412e99a865 100644 --- a/src/ol/layer/Layer.js +++ b/src/ol/layer/Layer.js @@ -4,7 +4,7 @@ import {listen, unlistenByKey} from '../events.js'; import EventType from '../events/EventType.js'; import {getUid, inherits} from '../index.js'; -import BaseObject from '../Object.js'; +import {getChangeEventType} from '../Object.js'; import BaseLayer from '../layer/Base.js'; import LayerProperty from '../layer/Property.js'; import {assign} from '../obj.js'; @@ -63,7 +63,7 @@ const Layer = function(options) { } listen(this, - BaseObject.getChangeEventType(LayerProperty.SOURCE), + getChangeEventType(LayerProperty.SOURCE), this.handleSourcePropertyChange_, this); const source = options.source ? options.source : null; From e0a99c43dc04bd642f54ea2f37120fce96483dfa Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:59:48 -0700 Subject: [PATCH 13/19] Remove static members from Translate --- src/ol/interaction/Translate.js | 104 +++++++++++++-------- src/ol/interaction/TranslateEventType.js | 27 ------ test/spec/ol/interaction/translate.test.js | 10 +- 3 files changed, 70 insertions(+), 71 deletions(-) delete mode 100644 src/ol/interaction/TranslateEventType.js diff --git a/src/ol/interaction/Translate.js b/src/ol/interaction/Translate.js index b0fc3100ca..4fee69a746 100644 --- a/src/ol/interaction/Translate.js +++ b/src/ol/interaction/Translate.js @@ -10,7 +10,67 @@ import {TRUE} from '../functions.js'; import {includes} from '../array.js'; import PointerInteraction from '../interaction/Pointer.js'; import InteractionProperty from '../interaction/Property.js'; -import TranslateEventType from '../interaction/TranslateEventType.js'; + + +/** + * @enum {string} + */ +const TranslateEventType = { + /** + * Triggered upon feature translation start. + * @event TranslateEvent#translatestart + * @api + */ + TRANSLATESTART: 'translatestart', + /** + * Triggered upon feature translation. + * @event TranslateEvent#translating + * @api + */ + TRANSLATING: 'translating', + /** + * Triggered upon feature translation end. + * @event TranslateEvent#translateend + * @api + */ + TRANSLATEEND: 'translateend' +}; + + +/** + * @classdesc + * Events emitted by {@link ol.interaction.Translate} instances are instances of + * this type. + * + * @constructor + * @extends {ol.events.Event} + * @implements {oli.interaction.TranslateEvent} + * @param {ol.interaction.TranslateEventType} type Type. + * @param {ol.Collection.} features The features translated. + * @param {ol.Coordinate} coordinate The event coordinate. + */ +export const TranslateEvent = function(type, features, coordinate) { + + Event.call(this, type); + + /** + * The features being translated. + * @type {ol.Collection.} + * @api + */ + this.features = features; + + /** + * The coordinate of the drag event. + * @const + * @type {ol.Coordinate} + * @api + */ + this.coordinate = coordinate; +}; + +inherits(TranslateEvent, Event); + /** * @classdesc @@ -18,7 +78,7 @@ import TranslateEventType from '../interaction/TranslateEventType.js'; * * @constructor * @extends {ol.interaction.Pointer} - * @fires ol.interaction.Translate.Event + * @fires ol.interaction.TranslateEvent * @param {olx.interaction.TranslateOptions=} opt_options Options. * @api */ @@ -102,7 +162,7 @@ function handleDownEvent(event) { const features = this.features_ || new Collection([this.lastFeature_]); this.dispatchEvent( - new Translate.Event( + new TranslateEvent( TranslateEventType.TRANSLATESTART, features, event.coordinate)); return true; @@ -124,7 +184,7 @@ function handleUpEvent(event) { const features = this.features_ || new Collection([this.lastFeature_]); this.dispatchEvent( - new Translate.Event( + new TranslateEvent( TranslateEventType.TRANSLATEEND, features, event.coordinate)); return true; @@ -153,7 +213,7 @@ function handleDragEvent(event) { this.lastCoordinate_ = newCoordinate; this.dispatchEvent( - new Translate.Event( + new TranslateEvent( TranslateEventType.TRANSLATING, features, newCoordinate)); } @@ -257,38 +317,4 @@ Translate.prototype.updateState_ = function(oldMap) { }; -/** - * @classdesc - * Events emitted by {@link ol.interaction.Translate} instances are instances of - * this type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.interaction.TranslateEvent} - * @param {ol.interaction.TranslateEventType} type Type. - * @param {ol.Collection.} features The features translated. - * @param {ol.Coordinate} coordinate The event coordinate. - */ -Translate.Event = function(type, features, coordinate) { - - Event.call(this, type); - - /** - * The features being translated. - * @type {ol.Collection.} - * @api - */ - this.features = features; - - /** - * The coordinate of the drag event. - * @const - * @type {ol.Coordinate} - * @api - */ - this.coordinate = coordinate; -}; - -inherits(Translate.Event, Event); - export default Translate; diff --git a/src/ol/interaction/TranslateEventType.js b/src/ol/interaction/TranslateEventType.js deleted file mode 100644 index 8ce3894526..0000000000 --- a/src/ol/interaction/TranslateEventType.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * @module ol/interaction/TranslateEventType - */ - -/** - * @enum {string} - */ -export default { - /** - * Triggered upon feature translation start. - * @event ol.interaction.Translate.Event#translatestart - * @api - */ - TRANSLATESTART: 'translatestart', - /** - * Triggered upon feature translation. - * @event ol.interaction.Translate.Event#translating - * @api - */ - TRANSLATING: 'translating', - /** - * Triggered upon feature translation end. - * @event ol.interaction.Translate.Event#translateend - * @api - */ - TRANSLATEEND: 'translateend' -}; diff --git a/test/spec/ol/interaction/translate.test.js b/test/spec/ol/interaction/translate.test.js index c274b4c7c1..dfc065d66a 100644 --- a/test/spec/ol/interaction/translate.test.js +++ b/test/spec/ol/interaction/translate.test.js @@ -4,7 +4,7 @@ import Map from '../../../../src/ol/Map.js'; import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js'; import View from '../../../../src/ol/View.js'; import Point from '../../../../src/ol/geom/Point.js'; -import Translate from '../../../../src/ol/interaction/Translate.js'; +import Translate, {TranslateEvent} from '../../../../src/ol/interaction/Translate.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; @@ -80,7 +80,7 @@ describe('ol.interaction.Translate', function() { * modifications. Helper function to * @param {ol.Feature} feature Translated feature. * @param {ol.interaction.Translate} interaction The interaction. - * @return {Array} events + * @return {Array} events */ function trackEvents(feature, interaction) { const events = []; @@ -100,7 +100,7 @@ describe('ol.interaction.Translate', function() { * Validates the event array to verify proper event sequence. Checks * that first and last event are correct TranslateEvents and that feature * modifications event are in between. - * @param {Array} events The events. + * @param {Array} events The events. * @param {Array} features The features. */ function validateEvents(events, features) { @@ -109,11 +109,11 @@ describe('ol.interaction.Translate', function() { const endevent = events[events.length - 1]; // first event should be translatestart - expect(startevent).to.be.an(Translate.Event); + expect(startevent).to.be.an(TranslateEvent); expect(startevent.type).to.eql('translatestart'); // last event should be translateend - expect(endevent).to.be.an(Translate.Event); + expect(endevent).to.be.an(TranslateEvent); expect(endevent.type).to.eql('translateend'); // make sure we get change events to events array From dfefe7d4657dea2008c6b159ea3e55d4cad722dc Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 09:03:46 -0700 Subject: [PATCH 14/19] Remove static members from Snap --- src/ol/interaction/Snap.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index c918144fcb..51f7b95a0c 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -120,7 +120,7 @@ const Snap = function(opt_options) { * @type {function(ol.SnapSegmentDataType, ol.SnapSegmentDataType): number} * @private */ - this.sortByDistance_ = Snap.sortByDistance.bind(this); + this.sortByDistance_ = sortByDistance.bind(this); /** @@ -616,11 +616,10 @@ function handleUpEvent(evt) { * @return {number} The difference in distance. * @this {ol.interaction.Snap} */ -Snap.sortByDistance = function(a, b) { - return squaredDistanceToSegment( - this.pixelCoordinate_, a.segment) - - squaredDistanceToSegment( - this.pixelCoordinate_, b.segment); -}; +function sortByDistance(a, b) { + const deltaA = squaredDistanceToSegment(this.pixelCoordinate_, a.segment); + const deltaB = squaredDistanceToSegment(this.pixelCoordinate_, b.segment); + return deltaA - deltaB; +} export default Snap; From 064c5644e7e1d0e4fbd3cb1c31a20c6ddef02d7c Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 09:06:57 -0700 Subject: [PATCH 15/19] Remove static members from Select --- src/ol/interaction/Select.js | 96 ++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/ol/interaction/Select.js b/src/ol/interaction/Select.js index ba27efdc45..4bef1e1c5d 100644 --- a/src/ol/interaction/Select.js +++ b/src/ol/interaction/Select.js @@ -22,13 +22,55 @@ import {createEditingStyle} from '../style/Style.js'; const SelectEventType = { /** * Triggered when feature(s) has been (de)selected. - * @event ol.interaction.Select.Event#select + * @event SelectEvent#select * @api */ SELECT: 'select' }; +/** + * @classdesc + * Events emitted by {@link ol.interaction.Select} instances are instances of + * this type. + * + * @param {SelectEventType} type The event type. + * @param {Array.} selected Selected features. + * @param {Array.} deselected Deselected features. + * @param {ol.MapBrowserEvent} mapBrowserEvent Associated + * {@link ol.MapBrowserEvent}. + * @implements {oli.SelectEvent} + * @extends {ol.events.Event} + * @constructor + */ +const SelectEvent = function(type, selected, deselected, mapBrowserEvent) { + Event.call(this, type); + + /** + * Selected features array. + * @type {Array.} + * @api + */ + this.selected = selected; + + /** + * Deselected features array. + * @type {Array.} + * @api + */ + this.deselected = deselected; + + /** + * Associated {@link ol.MapBrowserEvent}. + * @type {ol.MapBrowserEvent} + * @api + */ + this.mapBrowserEvent = mapBrowserEvent; +}; + +inherits(SelectEvent, Event); + + /** * @classdesc * Interaction for selecting vector features. By default, selected features are @@ -44,7 +86,7 @@ const SelectEventType = { * @constructor * @extends {ol.interaction.Interaction} * @param {olx.interaction.SelectOptions=} opt_options Options. - * @fires ol.interaction.Select.Event + * @fires SelectEvent * @api */ const Select = function(opt_options) { @@ -104,7 +146,7 @@ const Select = function(opt_options) { wrapX: options.wrapX }), style: options.style ? options.style : - Select.getDefaultStyleFunction(), + getDefaultStyleFunction(), updateWhileAnimating: true, updateWhileInteracting: true }); @@ -289,7 +331,7 @@ function handleEvent(mapBrowserEvent) { } if (selected.length > 0 || deselected.length > 0) { this.dispatchEvent( - new Select.Event(SelectEventType.SELECT, + new SelectEvent(SelectEventType.SELECT, selected, deselected, mapBrowserEvent)); } return pointerMove(mapBrowserEvent); @@ -333,7 +375,7 @@ Select.prototype.setMap = function(map) { /** * @return {ol.StyleFunction} Styles. */ -Select.getDefaultStyleFunction = function() { +function getDefaultStyleFunction() { const styles = createEditingStyle(); extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]); extend(styles[GeometryType.GEOMETRY_COLLECTION], styles[GeometryType.LINE_STRING]); @@ -344,7 +386,7 @@ Select.getDefaultStyleFunction = function() { } return styles[feature.getGeometry().getType()]; }; -}; +} /** @@ -381,46 +423,4 @@ Select.prototype.removeFeatureLayerAssociation_ = function(feature) { }; -/** - * @classdesc - * Events emitted by {@link ol.interaction.Select} instances are instances of - * this type. - * - * @param {ol.interaction.SelectEventType} type The event type. - * @param {Array.} selected Selected features. - * @param {Array.} deselected Deselected features. - * @param {ol.MapBrowserEvent} mapBrowserEvent Associated - * {@link ol.MapBrowserEvent}. - * @implements {oli.SelectEvent} - * @extends {ol.events.Event} - * @constructor - */ -Select.Event = function(type, selected, deselected, mapBrowserEvent) { - Event.call(this, type); - - /** - * Selected features array. - * @type {Array.} - * @api - */ - this.selected = selected; - - /** - * Deselected features array. - * @type {Array.} - * @api - */ - this.deselected = deselected; - - /** - * Associated {@link ol.MapBrowserEvent}. - * @type {ol.MapBrowserEvent} - * @api - */ - this.mapBrowserEvent = mapBrowserEvent; -}; - -inherits(Select.Event, Event); - - export default Select; From 78e0cb294cbd108eaf75d1e59c7b56b3b18a8346 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 09:10:51 -0700 Subject: [PATCH 16/19] Remove static members from Pointer --- src/ol/interaction/Pointer.js | 69 ++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/ol/interaction/Pointer.js b/src/ol/interaction/Pointer.js index 716eaef346..5f3cbd96be 100644 --- a/src/ol/interaction/Pointer.js +++ b/src/ol/interaction/Pointer.js @@ -8,6 +8,37 @@ import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js'; import Interaction from '../interaction/Interaction.js'; import {getValues} from '../obj.js'; + +/** + * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. + * @this {ol.interaction.Pointer} + */ +const handleDragEvent = nullFunction; + + +/** + * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. + * @return {boolean} Capture dragging. + * @this {ol.interaction.Pointer} + */ +const handleUpEvent = FALSE; + + +/** + * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. + * @return {boolean} Capture dragging. + * @this {ol.interaction.Pointer} + */ +const handleDownEvent = FALSE; + + +/** + * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. + * @this {ol.interaction.Pointer} + */ +const handleMoveEvent = nullFunction; + + /** * @classdesc * Base class that calls user-defined functions on `down`, `move` and `up` @@ -36,28 +67,28 @@ const PointerInteraction = function(opt_options) { * @private */ this.handleDownEvent_ = options.handleDownEvent ? - options.handleDownEvent : PointerInteraction.handleDownEvent; + options.handleDownEvent : handleDownEvent; /** * @type {function(ol.MapBrowserPointerEvent)} * @private */ this.handleDragEvent_ = options.handleDragEvent ? - options.handleDragEvent : PointerInteraction.handleDragEvent; + options.handleDragEvent : handleDragEvent; /** * @type {function(ol.MapBrowserPointerEvent)} * @private */ this.handleMoveEvent_ = options.handleMoveEvent ? - options.handleMoveEvent : PointerInteraction.handleMoveEvent; + options.handleMoveEvent : handleMoveEvent; /** * @type {function(ol.MapBrowserPointerEvent):boolean} * @private */ this.handleUpEvent_ = options.handleUpEvent ? - options.handleUpEvent : PointerInteraction.handleUpEvent; + options.handleUpEvent : handleUpEvent; /** * @type {boolean} @@ -134,36 +165,6 @@ PointerInteraction.prototype.updateTrackedPointers_ = function(mapBrowserEvent) }; -/** - * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. - * @this {ol.interaction.Pointer} - */ -PointerInteraction.handleDragEvent = nullFunction; - - -/** - * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. - * @return {boolean} Capture dragging. - * @this {ol.interaction.Pointer} - */ -PointerInteraction.handleUpEvent = FALSE; - - -/** - * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. - * @return {boolean} Capture dragging. - * @this {ol.interaction.Pointer} - */ -PointerInteraction.handleDownEvent = FALSE; - - -/** - * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. - * @this {ol.interaction.Pointer} - */ -PointerInteraction.handleMoveEvent = nullFunction; - - /** * Handles the {@link ol.MapBrowserEvent map browser event} and may call into * other functions, if event sequences like e.g. 'drag' or 'down-up' etc. are From 3f944ef76eb6e5a768810d752b06a91bfd0ea223 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 09:18:44 -0700 Subject: [PATCH 17/19] Remove static members from Modify --- src/ol/interaction/Modify.js | 132 ++++++++++++++---------- src/ol/interaction/ModifyEventType.js | 21 ---- test/spec/ol/interaction/modify.test.js | 10 +- 3 files changed, 82 insertions(+), 81 deletions(-) delete mode 100644 src/ol/interaction/ModifyEventType.js diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 555d415a7c..99175c1c20 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -16,7 +16,6 @@ import {always, primaryAction, altKeyOnly, singleClick} from '../events/conditio import {boundingExtent, buffer, createOrUpdateFromCoordinate} from '../extent.js'; import GeometryType from '../geom/GeometryType.js'; import Point from '../geom/Point.js'; -import ModifyEventType from '../interaction/ModifyEventType.js'; import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js'; import VectorLayer from '../layer/Vector.js'; import VectorSource from '../source/Vector.js'; @@ -24,6 +23,61 @@ import VectorEventType from '../source/VectorEventType.js'; import RBush from '../structs/RBush.js'; import {createEditingStyle} from '../style/Style.js'; + +/** + * @enum {string} + */ +const ModifyEventType = { + /** + * Triggered upon feature modification start + * @event ModifyEvent#modifystart + * @api + */ + MODIFYSTART: 'modifystart', + /** + * Triggered upon feature modification end + * @event ModifyEvent#modifyend + * @api + */ + MODIFYEND: 'modifyend' +}; + + +/** + * @classdesc + * Events emitted by {@link ol.interaction.Modify} instances are instances of + * this type. + * + * @constructor + * @extends {ol.events.Event} + * @implements {oli.ModifyEvent} + * @param {ModifyEventType} type Type. + * @param {ol.Collection.} features The features modified. + * @param {ol.MapBrowserPointerEvent} mapBrowserPointerEvent Associated + * {@link ol.MapBrowserPointerEvent}. + */ +export const ModifyEvent = function(type, features, mapBrowserPointerEvent) { + + Event.call(this, type); + + /** + * The features being modified. + * @type {ol.Collection.} + * @api + */ + this.features = features; + + /** + * Associated {@link ol.MapBrowserEvent}. + * @type {ol.MapBrowserEvent} + * @api + */ + this.mapBrowserEvent = mapBrowserPointerEvent; +}; + +inherits(ModifyEvent, Event); + + /** * @classdesc * Interaction for modifying feature geometries. To modify features that have @@ -40,7 +94,7 @@ import {createEditingStyle} from '../style/Style.js'; * @constructor * @extends {ol.interaction.Pointer} * @param {olx.interaction.ModifyOptions} options Options. - * @fires ol.interaction.Modify.Event + * @fires ol.interaction.ModifyEvent * @api */ const Modify = function(options) { @@ -161,7 +215,7 @@ const Modify = function(options) { wrapX: !!options.wrapX }), style: options.style ? options.style : - Modify.getDefaultStyleFunction(), + getDefaultStyleFunction(), updateWhileAnimating: true, updateWhileInteracting: true }); @@ -229,16 +283,18 @@ inherits(Modify, PointerInteraction); /** - * @define {number} The segment index assigned to a circle's center when + * The segment index assigned to a circle's center when * breaking up a cicrle into ModifySegmentDataType segments. + * @type {number} */ -Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX = 0; +const CIRCLE_CENTER_INDEX = 0; /** - * @define {number} The segment index assigned to a circle's circumference when + * The segment index assigned to a circle's circumference when * breaking up a circle into ModifySegmentDataType segments. + * @type {number} */ -Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX = 1; +const CIRCLE_CIRCUMFERENCE_INDEX = 1; /** @@ -266,7 +322,7 @@ Modify.prototype.addFeature_ = function(feature) { Modify.prototype.willModifyFeatures_ = function(evt) { if (!this.modified_) { this.modified_ = true; - this.dispatchEvent(new Modify.Event( + this.dispatchEvent(new ModifyEvent( ModifyEventType.MODIFYSTART, this.features_, evt)); } }; @@ -525,9 +581,9 @@ Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) { /** * We convert a circle into two segments. The segment at index - * {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX} is the + * {@link CIRCLE_CENTER_INDEX} is the * circle's center (a point). The segment at index - * {@link ol.interaction.Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX} is + * {@link CIRCLE_CIRCUMFERENCE_INDEX} is * the circumference, and is not a line segment. * * @param {ol.Feature} feature Feature. @@ -539,13 +595,13 @@ Modify.prototype.writeCircleGeometry_ = function(feature, geometry) { const centerSegmentData = /** @type {ol.ModifySegmentDataType} */ ({ feature: feature, geometry: geometry, - index: Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX, + index: CIRCLE_CENTER_INDEX, segment: [coordinates, coordinates] }); const circumferenceSegmentData = /** @type {ol.ModifySegmentDataType} */ ({ feature: feature, geometry: geometry, - index: Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX, + index: CIRCLE_CIRCUMFERENCE_INDEX, segment: [coordinates, coordinates] }); const featureSegments = [centerSegmentData, circumferenceSegmentData]; @@ -631,7 +687,7 @@ function handleDownEvent(evt) { componentSegments[uid] = new Array(2); } if (segmentDataMatch.geometry.getType() === GeometryType.CIRCLE && - segmentDataMatch.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { + segmentDataMatch.index === CIRCLE_CIRCUMFERENCE_INDEX) { const closestVertex = closestOnSegmentData(pixelCoordinate, segmentDataMatch); if (coordinatesEqual(closestVertex, vertex) && !componentSegments[uid][0]) { @@ -727,7 +783,7 @@ function handleDragEvent(evt) { break; case GeometryType.CIRCLE: segment[0] = segment[1] = vertex; - if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CENTER_INDEX) { + if (segmentData.index === CIRCLE_CENTER_INDEX) { this.changingFeature_ = true; geometry.setCenter(vertex); this.changingFeature_ = false; @@ -775,7 +831,7 @@ function handleUpEvent(evt) { } } if (this.modified_) { - this.dispatchEvent(new Modify.Event( + this.dispatchEvent(new ModifyEvent( ModifyEventType.MODIFYEND, this.features_, evt)); this.modified_ = false; } @@ -856,7 +912,7 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) { const vertexSegments = {}; if (node.geometry.getType() === GeometryType.CIRCLE && - node.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { + node.index === CIRCLE_CIRCUMFERENCE_INDEX) { this.snappedToVertex_ = true; this.createOrUpdateVertexFeature_(vertex); @@ -912,7 +968,7 @@ function pointDistanceToSegmentDataSquared(pointCoordinates, segmentData) { if (geometry.getType() === GeometryType.CIRCLE) { const circleGeometry = /** @type {ol.geom.Circle} */ (geometry); - if (segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { + if (segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) { const distanceToCenterSquared = squaredCoordinateDistance(circleGeometry.getCenter(), pointCoordinates); const distanceToCircumference = @@ -936,7 +992,7 @@ function closestOnSegmentData(pointCoordinates, segmentData) { const geometry = segmentData.geometry; if (geometry.getType() === GeometryType.CIRCLE && - segmentData.index === Modify.MODIFY_SEGMENT_CIRCLE_CIRCUMFERENCE_INDEX) { + segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) { return geometry.getClosestPoint(pointCoordinates); } return closestOnSegment(pointCoordinates, segmentData.segment); @@ -1018,7 +1074,7 @@ Modify.prototype.removePoint = function() { const evt = this.lastPointerEvent_; this.willModifyFeatures_(evt); this.removeVertex_(); - this.dispatchEvent(new Modify.Event(ModifyEventType.MODIFYEND, this.features_, evt)); + this.dispatchEvent(new ModifyEvent(ModifyEventType.MODIFYEND, this.features_, evt)); this.modified_ = false; return true; } @@ -1179,46 +1235,12 @@ Modify.prototype.updateSegmentIndices_ = function( /** * @return {ol.StyleFunction} Styles. */ -Modify.getDefaultStyleFunction = function() { +function getDefaultStyleFunction() { const style = createEditingStyle(); return function(feature, resolution) { return style[GeometryType.POINT]; }; -}; +} -/** - * @classdesc - * Events emitted by {@link ol.interaction.Modify} instances are instances of - * this type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.ModifyEvent} - * @param {ol.interaction.ModifyEventType} type Type. - * @param {ol.Collection.} features The features modified. - * @param {ol.MapBrowserPointerEvent} mapBrowserPointerEvent Associated - * {@link ol.MapBrowserPointerEvent}. - */ -Modify.Event = function(type, features, mapBrowserPointerEvent) { - - Event.call(this, type); - - /** - * The features being modified. - * @type {ol.Collection.} - * @api - */ - this.features = features; - - /** - * Associated {@link ol.MapBrowserEvent}. - * @type {ol.MapBrowserEvent} - * @api - */ - this.mapBrowserEvent = mapBrowserPointerEvent; -}; - -inherits(Modify.Event, Event); - export default Modify; diff --git a/src/ol/interaction/ModifyEventType.js b/src/ol/interaction/ModifyEventType.js deleted file mode 100644 index 9f7a582251..0000000000 --- a/src/ol/interaction/ModifyEventType.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @module ol/interaction/ModifyEventType - */ - -/** - * @enum {string} - */ -export default { - /** - * Triggered upon feature modification start - * @event ol.interaction.Modify.Event#modifystart - * @api - */ - MODIFYSTART: 'modifystart', - /** - * Triggered upon feature modification end - * @event ol.interaction.Modify.Event#modifyend - * @api - */ - MODIFYEND: 'modifyend' -}; diff --git a/test/spec/ol/interaction/modify.test.js b/test/spec/ol/interaction/modify.test.js index 46cea4b711..b951feace1 100644 --- a/test/spec/ol/interaction/modify.test.js +++ b/test/spec/ol/interaction/modify.test.js @@ -9,7 +9,7 @@ import Circle from '../../../../src/ol/geom/Circle.js'; import LineString from '../../../../src/ol/geom/LineString.js'; import Point from '../../../../src/ol/geom/Point.js'; import Polygon from '../../../../src/ol/geom/Polygon.js'; -import Modify from '../../../../src/ol/interaction/Modify.js'; +import Modify, {ModifyEvent} from '../../../../src/ol/interaction/Modify.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; import VectorSource from '../../../../src/ol/source/Vector.js'; @@ -101,7 +101,7 @@ describe('ol.interaction.Modify', function() { * modifications. Helper function to * @param {ol.Feature} feature Modified feature. * @param {ol.interaction.Modify} interaction The interaction. - * @return {Array} events + * @return {Array} events */ function trackEvents(feature, interaction) { const events = []; @@ -121,7 +121,7 @@ describe('ol.interaction.Modify', function() { * Validates the event array to verify proper event sequence. Checks * that first and last event are correct ModifyEvents and that feature * modifications event are in between. - * @param {Array} events The events. + * @param {Array} events The events. * @param {Array} features The features. */ function validateEvents(events, features) { @@ -130,11 +130,11 @@ describe('ol.interaction.Modify', function() { const endevent = events[events.length - 1]; // first event should be modifystary - expect(startevent).to.be.an(Modify.Event); + expect(startevent).to.be.a(ModifyEvent); expect(startevent.type).to.eql('modifystart'); // last event should be modifyend - expect(endevent).to.be.an(Modify.Event); + expect(endevent).to.be.a(ModifyEvent); expect(endevent.type).to.eql('modifyend'); // make sure we get change events to events array From 244fbbbb8dc705a0a2425a8b99a78a82497af327 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 10:17:21 -0700 Subject: [PATCH 18/19] Remove some of the static members from Interaction --- src/ol/interaction/DragRotate.js | 5 ++--- src/ol/interaction/DragRotateAndZoom.js | 9 ++++----- src/ol/interaction/Interaction.js | 19 +++++++++---------- src/ol/interaction/PinchRotate.js | 5 ++--- src/ol/interaction/PinchZoom.js | 7 +++---- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/ol/interaction/DragRotate.js b/src/ol/interaction/DragRotate.js index 65916b323e..689a60554a 100644 --- a/src/ol/interaction/DragRotate.js +++ b/src/ol/interaction/DragRotate.js @@ -6,7 +6,7 @@ import {disable} from '../rotationconstraint.js'; import ViewHint from '../ViewHint.js'; import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js'; import {FALSE} from '../functions.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {rotate} from '../interaction/Interaction.js'; import PointerInteraction from '../interaction/Pointer.js'; /** @@ -96,8 +96,7 @@ function handleUpEvent(mapBrowserEvent) { const view = map.getView(); view.setHint(ViewHint.INTERACTING, -1); const rotation = view.getRotation(); - Interaction.rotate(view, rotation, - undefined, this.duration_); + rotate(view, rotation, undefined, this.duration_); return false; } diff --git a/src/ol/interaction/DragRotateAndZoom.js b/src/ol/interaction/DragRotateAndZoom.js index 482b6fc54a..39a68a52f0 100644 --- a/src/ol/interaction/DragRotateAndZoom.js +++ b/src/ol/interaction/DragRotateAndZoom.js @@ -5,7 +5,7 @@ import {inherits} from '../index.js'; import {disable} from '../rotationconstraint.js'; import ViewHint from '../ViewHint.js'; import {shiftKeyOnly, mouseOnly} from '../events/condition.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {rotate, zoom, zoomWithoutConstraints} from '../interaction/Interaction.js'; import PointerInteraction from '../interaction/Pointer.js'; /** @@ -93,7 +93,7 @@ function handleDragEvent(mapBrowserEvent) { this.lastAngle_ = theta; if (this.lastMagnitude_ !== undefined) { const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); - Interaction.zoomWithoutConstraints(view, resolution); + zoomWithoutConstraints(view, resolution); } if (this.lastMagnitude_ !== undefined) { this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; @@ -116,9 +116,8 @@ function handleUpEvent(mapBrowserEvent) { const view = map.getView(); view.setHint(ViewHint.INTERACTING, -1); const direction = this.lastScaleDelta_ - 1; - Interaction.rotate(view, view.getRotation()); - Interaction.zoom(view, view.getResolution(), - undefined, this.duration_, direction); + rotate(view, view.getRotation()); + zoom(view, view.getResolution(), undefined, this.duration_, direction); this.lastScaleDelta_ = 0; return false; } diff --git a/src/ol/interaction/Interaction.js b/src/ol/interaction/Interaction.js index 604f9433fb..893d64f989 100644 --- a/src/ol/interaction/Interaction.js +++ b/src/ol/interaction/Interaction.js @@ -132,11 +132,11 @@ Interaction.pan = function(view, delta, opt_duration) { * @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {number=} opt_duration Duration. */ -Interaction.rotate = function(view, rotation, opt_anchor, opt_duration) { +export function rotate(view, rotation, opt_anchor, opt_duration) { rotation = view.constrainRotation(rotation, 0); Interaction.rotateWithoutConstraints( view, rotation, opt_anchor, opt_duration); -}; +} /** @@ -177,11 +177,10 @@ Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_ * will select the nearest resolution. If not defined 0 is * assumed. */ -Interaction.zoom = function(view, resolution, opt_anchor, opt_duration, opt_direction) { +export function zoom(view, resolution, opt_anchor, opt_duration, opt_direction) { resolution = view.constrainResolution(resolution, 0, opt_direction); - Interaction.zoomWithoutConstraints( - view, resolution, opt_anchor, opt_duration); -}; + zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration); +} /** @@ -218,8 +217,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) { ]; } - Interaction.zoomWithoutConstraints( - view, resolution, opt_anchor, opt_duration); + zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration); }; @@ -229,7 +227,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) { * @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {number=} opt_duration Duration. */ -Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_duration) { +export function zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration) { if (resolution) { const currentResolution = view.getResolution(); const currentCenter = view.getCenter(); @@ -249,5 +247,6 @@ Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_ view.setResolution(resolution); } } -}; +} + export default Interaction; diff --git a/src/ol/interaction/PinchRotate.js b/src/ol/interaction/PinchRotate.js index 88dfe0dd49..9948f51fb4 100644 --- a/src/ol/interaction/PinchRotate.js +++ b/src/ol/interaction/PinchRotate.js @@ -4,7 +4,7 @@ import {inherits} from '../index.js'; import ViewHint from '../ViewHint.js'; import {FALSE} from '../functions.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {rotate} from '../interaction/Interaction.js'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js'; import {disable} from '../rotationconstraint.js'; @@ -132,8 +132,7 @@ function handleUpEvent(mapBrowserEvent) { view.setHint(ViewHint.INTERACTING, -1); if (this.rotating_) { const rotation = view.getRotation(); - Interaction.rotate( - view, rotation, this.anchor_, this.duration_); + rotate(view, rotation, this.anchor_, this.duration_); } return false; } else { diff --git a/src/ol/interaction/PinchZoom.js b/src/ol/interaction/PinchZoom.js index 13989c7538..ea69a9d363 100644 --- a/src/ol/interaction/PinchZoom.js +++ b/src/ol/interaction/PinchZoom.js @@ -4,7 +4,7 @@ import {inherits} from '../index.js'; import ViewHint from '../ViewHint.js'; import {FALSE} from '../functions.js'; -import Interaction from '../interaction/Interaction.js'; +import {zoom, zoomWithoutConstraints} from '../interaction/Interaction.js'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js'; /** @@ -110,7 +110,7 @@ function handleDragEvent(mapBrowserEvent) { // scale, bypass the resolution constraint map.render(); - Interaction.zoomWithoutConstraints(view, newResolution, this.anchor_); + zoomWithoutConstraints(view, newResolution, this.anchor_); } @@ -132,8 +132,7 @@ function handleUpEvent(mapBrowserEvent) { // direction not to zoom out/in if user was pinching in/out. // Direction is > 0 if pinching out, and < 0 if pinching in. const direction = this.lastScaleDelta_ - 1; - Interaction.zoom(view, resolution, - this.anchor_, this.duration_, direction); + zoom(view, resolution, this.anchor_, this.duration_, direction); } return false; } else { From 1404e9d61df9ccdce26f44cea5ac891f70e72b7e Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 12:42:37 -0700 Subject: [PATCH 19/19] Remove remaining static members from Interaction --- src/ol/interaction/DoubleClickZoom.js | 4 +- src/ol/interaction/DragRotate.js | 5 +-- src/ol/interaction/DragRotateAndZoom.js | 5 +-- src/ol/interaction/Interaction.js | 15 +++---- src/ol/interaction/KeyboardPan.js | 4 +- src/ol/interaction/KeyboardZoom.js | 5 +-- src/ol/interaction/MouseWheelZoom.js | 5 +-- src/ol/interaction/PinchRotate.js | 5 +-- .../ol/interaction/dragrotateandzoom.test.js | 19 +++++--- test/spec/ol/interaction/interaction.test.js | 26 +++++------ test/spec/ol/interaction/keyboardpan.test.js | 23 +++++++--- test/spec/ol/interaction/keyboardzoom.test.js | 19 +++++--- .../ol/interaction/mousewheelzoom.test.js | 44 ++++++++++++------- 13 files changed, 102 insertions(+), 77 deletions(-) diff --git a/src/ol/interaction/DoubleClickZoom.js b/src/ol/interaction/DoubleClickZoom.js index 83f9547ec4..8aee3830f1 100644 --- a/src/ol/interaction/DoubleClickZoom.js +++ b/src/ol/interaction/DoubleClickZoom.js @@ -3,7 +3,7 @@ */ import {inherits} from '../index.js'; import MapBrowserEventType from '../MapBrowserEventType.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {zoomByDelta} from '../interaction/Interaction.js'; /** * @classdesc @@ -54,7 +54,7 @@ function handleEvent(mapBrowserEvent) { const anchor = mapBrowserEvent.coordinate; const delta = browserEvent.shiftKey ? -this.delta_ : this.delta_; const view = map.getView(); - Interaction.zoomByDelta(view, delta, anchor, this.duration_); + zoomByDelta(view, delta, anchor, this.duration_); mapBrowserEvent.preventDefault(); stopEvent = true; } diff --git a/src/ol/interaction/DragRotate.js b/src/ol/interaction/DragRotate.js index 689a60554a..b1d4f897d6 100644 --- a/src/ol/interaction/DragRotate.js +++ b/src/ol/interaction/DragRotate.js @@ -6,7 +6,7 @@ import {disable} from '../rotationconstraint.js'; import ViewHint from '../ViewHint.js'; import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js'; import {FALSE} from '../functions.js'; -import Interaction, {rotate} from '../interaction/Interaction.js'; +import {rotate, rotateWithoutConstraints} from '../interaction/Interaction.js'; import PointerInteraction from '../interaction/Pointer.js'; /** @@ -75,8 +75,7 @@ function handleDragEvent(mapBrowserEvent) { if (this.lastAngle_ !== undefined) { const delta = theta - this.lastAngle_; const rotation = view.getRotation(); - Interaction.rotateWithoutConstraints( - view, rotation - delta); + rotateWithoutConstraints(view, rotation - delta); } this.lastAngle_ = theta; } diff --git a/src/ol/interaction/DragRotateAndZoom.js b/src/ol/interaction/DragRotateAndZoom.js index 39a68a52f0..6513fe4187 100644 --- a/src/ol/interaction/DragRotateAndZoom.js +++ b/src/ol/interaction/DragRotateAndZoom.js @@ -5,7 +5,7 @@ import {inherits} from '../index.js'; import {disable} from '../rotationconstraint.js'; import ViewHint from '../ViewHint.js'; import {shiftKeyOnly, mouseOnly} from '../events/condition.js'; -import Interaction, {rotate, zoom, zoomWithoutConstraints} from '../interaction/Interaction.js'; +import {rotate, rotateWithoutConstraints, zoom, zoomWithoutConstraints} from '../interaction/Interaction.js'; import PointerInteraction from '../interaction/Pointer.js'; /** @@ -87,8 +87,7 @@ function handleDragEvent(mapBrowserEvent) { const view = map.getView(); if (view.getConstraints().rotation !== disable && this.lastAngle_ !== undefined) { const angleDelta = theta - this.lastAngle_; - Interaction.rotateWithoutConstraints( - view, view.getRotation() - angleDelta); + rotateWithoutConstraints(view, view.getRotation() - angleDelta); } this.lastAngle_ = theta; if (this.lastMagnitude_ !== undefined) { diff --git a/src/ol/interaction/Interaction.js b/src/ol/interaction/Interaction.js index 893d64f989..5cf730339b 100644 --- a/src/ol/interaction/Interaction.js +++ b/src/ol/interaction/Interaction.js @@ -108,7 +108,7 @@ Interaction.prototype.setMap = function(map) { * @param {ol.Coordinate} delta Delta. * @param {number=} opt_duration Duration. */ -Interaction.pan = function(view, delta, opt_duration) { +export function pan(view, delta, opt_duration) { const currentCenter = view.getCenter(); if (currentCenter) { const center = view.constrainCenter( @@ -123,7 +123,7 @@ Interaction.pan = function(view, delta, opt_duration) { view.setCenter(center); } } -}; +} /** @@ -134,8 +134,7 @@ Interaction.pan = function(view, delta, opt_duration) { */ export function rotate(view, rotation, opt_anchor, opt_duration) { rotation = view.constrainRotation(rotation, 0); - Interaction.rotateWithoutConstraints( - view, rotation, opt_anchor, opt_duration); + rotateWithoutConstraints(view, rotation, opt_anchor, opt_duration); } @@ -145,7 +144,7 @@ export function rotate(view, rotation, opt_anchor, opt_duration) { * @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {number=} opt_duration Duration. */ -Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_duration) { +export function rotateWithoutConstraints(view, rotation, opt_anchor, opt_duration) { if (rotation !== undefined) { const currentRotation = view.getRotation(); const currentCenter = view.getCenter(); @@ -160,7 +159,7 @@ Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_ view.rotate(rotation, opt_anchor); } } -}; +} /** @@ -189,7 +188,7 @@ export function zoom(view, resolution, opt_anchor, opt_duration, opt_direction) * @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {number=} opt_duration Duration. */ -Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) { +export function zoomByDelta(view, delta, opt_anchor, opt_duration) { const currentResolution = view.getResolution(); let resolution = view.constrainResolution(currentResolution, delta, 0); @@ -218,7 +217,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) { } zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration); -}; +} /** diff --git a/src/ol/interaction/KeyboardPan.js b/src/ol/interaction/KeyboardPan.js index d5897a14ed..2c8ed1b4c7 100644 --- a/src/ol/interaction/KeyboardPan.js +++ b/src/ol/interaction/KeyboardPan.js @@ -6,7 +6,7 @@ import {rotate as rotateCoordinate} from '../coordinate.js'; import EventType from '../events/EventType.js'; import KeyCode from '../events/KeyCode.js'; import {noModifierKeys, targetNotEditable} from '../events/condition.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {pan} from '../interaction/Interaction.js'; /** * @classdesc @@ -100,7 +100,7 @@ function handleEvent(mapBrowserEvent) { } const delta = [deltaX, deltaY]; rotateCoordinate(delta, view.getRotation()); - Interaction.pan(view, delta, this.duration_); + pan(view, delta, this.duration_); mapBrowserEvent.preventDefault(); stopEvent = true; } diff --git a/src/ol/interaction/KeyboardZoom.js b/src/ol/interaction/KeyboardZoom.js index 8d0e7af699..0ffeae3935 100644 --- a/src/ol/interaction/KeyboardZoom.js +++ b/src/ol/interaction/KeyboardZoom.js @@ -4,7 +4,7 @@ import {inherits} from '../index.js'; import EventType from '../events/EventType.js'; import {targetNotEditable} from '../events/condition.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {zoomByDelta} from '../interaction/Interaction.js'; /** * @classdesc @@ -73,8 +73,7 @@ function handleEvent(mapBrowserEvent) { const map = mapBrowserEvent.map; const delta = (charCode == '+'.charCodeAt(0)) ? this.delta_ : -this.delta_; const view = map.getView(); - Interaction.zoomByDelta( - view, delta, undefined, this.duration_); + zoomByDelta(view, delta, undefined, this.duration_); mapBrowserEvent.preventDefault(); stopEvent = true; } diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index 7b9edbe9bd..cb97653d19 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -7,7 +7,7 @@ import {always} from '../events/condition.js'; import {easeOut} from '../easing.js'; import EventType from '../events/EventType.js'; import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../has.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {zoomByDelta} from '../interaction/Interaction.js'; import {clamp} from '../math.js'; @@ -280,8 +280,7 @@ MouseWheelZoom.prototype.handleWheelZoom_ = function(map) { } const maxDelta = MAX_DELTA; const delta = clamp(this.delta_, -maxDelta, maxDelta); - Interaction.zoomByDelta(view, -delta, this.lastAnchor_, - this.duration_); + zoomByDelta(view, -delta, this.lastAnchor_, this.duration_); this.mode_ = undefined; this.delta_ = 0; this.lastAnchor_ = null; diff --git a/src/ol/interaction/PinchRotate.js b/src/ol/interaction/PinchRotate.js index 9948f51fb4..09c9a40711 100644 --- a/src/ol/interaction/PinchRotate.js +++ b/src/ol/interaction/PinchRotate.js @@ -4,7 +4,7 @@ import {inherits} from '../index.js'; import ViewHint from '../ViewHint.js'; import {FALSE} from '../functions.js'; -import Interaction, {rotate} from '../interaction/Interaction.js'; +import {rotate, rotateWithoutConstraints} from '../interaction/Interaction.js'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js'; import {disable} from '../rotationconstraint.js'; @@ -114,8 +114,7 @@ function handleDragEvent(mapBrowserEvent) { if (this.rotating_) { const rotation = view.getRotation(); map.render(); - Interaction.rotateWithoutConstraints(view, - rotation + rotationDelta, this.anchor_); + rotateWithoutConstraints(view, rotation + rotationDelta, this.anchor_); } } diff --git a/test/spec/ol/interaction/dragrotateandzoom.test.js b/test/spec/ol/interaction/dragrotateandzoom.test.js index 197d13bc80..b8d91435bd 100644 --- a/test/spec/ol/interaction/dragrotateandzoom.test.js +++ b/test/spec/ol/interaction/dragrotateandzoom.test.js @@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js'; import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js'; import View from '../../../../src/ol/View.js'; import DragRotateAndZoom from '../../../../src/ol/interaction/DragRotateAndZoom.js'; -import Interaction from '../../../../src/ol/interaction/Interaction.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; import VectorSource from '../../../../src/ol/source/Vector.js'; @@ -62,22 +61,30 @@ describe('ol.interaction.DragRotateAndZoom', function() { new PointerEvent('pointermove', {clientX: 20, clientY: 10}, {pointerType: 'mouse'}), true); interaction.lastAngle_ = Math.PI; - const spy = sinon.spy(Interaction, 'rotateWithoutConstraints'); + + let view = map.getView(); + let spy = sinon.spy(view, 'rotate'); interaction.handleDragEvent_(event); expect(spy.callCount).to.be(1); expect(interaction.lastAngle_).to.be(-0.8308214428190254); - map.setView(new View({ + view.rotate.restore(); + + view = new View({ projection: 'EPSG:4326', center: [0, 0], resolution: 1, enableRotation: false - })); + }); + map.setView(view); + event = new MapBrowserPointerEvent('pointermove', map, new PointerEvent('pointermove', {clientX: 24, clientY: 16}, {pointerType: 'mouse'}), true); + + spy = sinon.spy(view, 'rotate'); interaction.handleDragEvent_(event); - expect(spy.callCount).to.be(1); - Interaction.rotateWithoutConstraints.restore(); + expect(spy.callCount).to.be(0); + view.rotate.restore(); }); }); diff --git a/test/spec/ol/interaction/interaction.test.js b/test/spec/ol/interaction/interaction.test.js index 01d0ca0500..4dc69c7ef3 100644 --- a/test/spec/ol/interaction/interaction.test.js +++ b/test/spec/ol/interaction/interaction.test.js @@ -1,7 +1,7 @@ import Map from '../../../../src/ol/Map.js'; import View from '../../../../src/ol/View.js'; import EventTarget from '../../../../src/ol/events/EventTarget.js'; -import Interaction from '../../../../src/ol/interaction/Interaction.js'; +import Interaction, {zoomByDelta} from '../../../../src/ol/interaction/Interaction.js'; describe('ol.interaction.Interaction', function() { @@ -64,16 +64,16 @@ describe('ol.interaction.Interaction', function() { resolutions: [4, 2, 1, 0.5, 0.25] }); - Interaction.zoomByDelta(view, 1); + zoomByDelta(view, 1); expect(view.getResolution()).to.be(0.5); - Interaction.zoomByDelta(view, -1); + zoomByDelta(view, -1); expect(view.getResolution()).to.be(1); - Interaction.zoomByDelta(view, 2); + zoomByDelta(view, 2); expect(view.getResolution()).to.be(0.25); - Interaction.zoomByDelta(view, -2); + zoomByDelta(view, -2); expect(view.getResolution()).to.be(1); }); @@ -84,16 +84,16 @@ describe('ol.interaction.Interaction', function() { resolutions: [4, 2, 1, 0.5, 0.25] }); - Interaction.zoomByDelta(view, 1, [10, 10]); + zoomByDelta(view, 1, [10, 10]); expect(view.getCenter()).to.eql([5, 5]); - Interaction.zoomByDelta(view, -1, [0, 0]); + zoomByDelta(view, -1, [0, 0]); expect(view.getCenter()).to.eql([10, 10]); - Interaction.zoomByDelta(view, 2, [0, 0]); + zoomByDelta(view, 2, [0, 0]); expect(view.getCenter()).to.eql([2.5, 2.5]); - Interaction.zoomByDelta(view, -2, [0, 0]); + zoomByDelta(view, -2, [0, 0]); expect(view.getCenter()).to.eql([10, 10]); }); @@ -105,16 +105,16 @@ describe('ol.interaction.Interaction', function() { resolutions: [4, 2, 1, 0.5, 0.25] }); - Interaction.zoomByDelta(view, 1, [10, 10]); + zoomByDelta(view, 1, [10, 10]); expect(view.getCenter()).to.eql([2.5, 2.5]); - Interaction.zoomByDelta(view, -1, [0, 0]); + zoomByDelta(view, -1, [0, 0]); expect(view.getCenter()).to.eql([2.5, 2.5]); - Interaction.zoomByDelta(view, 2, [10, 10]); + zoomByDelta(view, 2, [10, 10]); expect(view.getCenter()).to.eql([2.5, 2.5]); - Interaction.zoomByDelta(view, -2, [0, 0]); + zoomByDelta(view, -2, [0, 0]); expect(view.getCenter()).to.eql([2.5, 2.5]); }); }); diff --git a/test/spec/ol/interaction/keyboardpan.test.js b/test/spec/ol/interaction/keyboardpan.test.js index 68c8484ac0..59f3b7db49 100644 --- a/test/spec/ol/interaction/keyboardpan.test.js +++ b/test/spec/ol/interaction/keyboardpan.test.js @@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js'; import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js'; import View from '../../../../src/ol/View.js'; import Event from '../../../../src/ol/events/Event.js'; -import Interaction from '../../../../src/ol/interaction/Interaction.js'; describe('ol.interaction.KeyboardPan', function() { let map; @@ -24,25 +23,35 @@ describe('ol.interaction.KeyboardPan', function() { describe('handleEvent()', function() { it('pans on arrow keys', function() { - const spy = sinon.spy(Interaction, 'pan'); + const view = map.getView(); + const spy = sinon.spy(view, 'animate'); const event = new MapBrowserEvent('keydown', map, { type: 'keydown', target: map.getTargetElement(), preventDefault: Event.prototype.preventDefault }); + event.originalEvent.keyCode = 40; // DOWN map.handleMapBrowserEvent(event); + expect(spy.getCall(0).args[0].center).to.eql([0, -128]); + view.setCenter([0, 0]); + event.originalEvent.keyCode = 38; // UP map.handleMapBrowserEvent(event); + expect(spy.getCall(1).args[0].center).to.eql([0, 128]); + view.setCenter([0, 0]); + event.originalEvent.keyCode = 37; // LEFT map.handleMapBrowserEvent(event); + expect(spy.getCall(2).args[0].center).to.eql([-128, 0]); + view.setCenter([0, 0]); + event.originalEvent.keyCode = 39; // RIGHT map.handleMapBrowserEvent(event); - expect(spy.getCall(0).args[1]).to.eql([0, -128]); - expect(spy.getCall(1).args[1]).to.eql([0, 128]); - expect(spy.getCall(2).args[1]).to.eql([-128, 0]); - expect(spy.getCall(3).args[1]).to.eql([128, 0]); - Interaction.pan.restore(); + expect(spy.getCall(3).args[0].center).to.eql([128, 0]); + view.setCenter([0, 0]); + + view.animate.restore(); }); }); diff --git a/test/spec/ol/interaction/keyboardzoom.test.js b/test/spec/ol/interaction/keyboardzoom.test.js index e40f5ef69e..8989ba9256 100644 --- a/test/spec/ol/interaction/keyboardzoom.test.js +++ b/test/spec/ol/interaction/keyboardzoom.test.js @@ -2,7 +2,6 @@ import Map from '../../../../src/ol/Map.js'; import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js'; import View from '../../../../src/ol/View.js'; import Event from '../../../../src/ol/events/Event.js'; -import Interaction from '../../../../src/ol/interaction/Interaction.js'; describe('ol.interaction.KeyboardZoom', function() { let map; @@ -12,8 +11,8 @@ describe('ol.interaction.KeyboardZoom', function() { target: createMapDiv(100, 100), view: new View({ center: [0, 0], - resolutions: [1], - zoom: 0 + resolutions: [4, 2, 1], + zoom: 1 }) }); map.renderSync(); @@ -24,19 +23,25 @@ describe('ol.interaction.KeyboardZoom', function() { describe('handleEvent()', function() { it('zooms on + and - keys', function() { - const spy = sinon.spy(Interaction, 'zoomByDelta'); + const view = map.getView(); + const spy = sinon.spy(view, 'animate'); const event = new MapBrowserEvent('keydown', map, { type: 'keydown', target: map.getTargetElement(), preventDefault: Event.prototype.preventDefault }); + event.originalEvent.charCode = '+'.charCodeAt(0); map.handleMapBrowserEvent(event); + expect(spy.getCall(0).args[0].resolution).to.eql(1); + view.setResolution(2); + event.originalEvent.charCode = '-'.charCodeAt(0); map.handleMapBrowserEvent(event); - expect(spy.getCall(0).args[1]).to.eql(1); - expect(spy.getCall(1).args[1]).to.eql(-1); - Interaction.zoomByDelta.restore(); + expect(spy.getCall(1).args[0].resolution).to.eql(4); + view.setResolution(2); + + view.animate.restore(); }); }); diff --git a/test/spec/ol/interaction/mousewheelzoom.test.js b/test/spec/ol/interaction/mousewheelzoom.test.js index 5f55163cc4..4488e95120 100644 --- a/test/spec/ol/interaction/mousewheelzoom.test.js +++ b/test/spec/ol/interaction/mousewheelzoom.test.js @@ -3,7 +3,6 @@ import MapBrowserEvent from '../../../../src/ol/MapBrowserEvent.js'; 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, {Mode} from '../../../../src/ol/interaction/MouseWheelZoom.js'; @@ -33,13 +32,13 @@ describe('ol.interaction.MouseWheelZoom', function() { describe('timeout duration', function() { let clock; beforeEach(function() { - sinon.spy(Interaction, 'zoomByDelta'); + sinon.spy(interaction, 'handleWheelZoom_'); clock = sinon.useFakeTimers(); }); afterEach(function() { clock.restore(); - Interaction.zoomByDelta.restore(); + interaction.handleWheelZoom_.restore(); }); it('works with the defaut value', function(done) { @@ -48,12 +47,14 @@ describe('ol.interaction.MouseWheelZoom', function() { target: map.getViewport(), preventDefault: Event.prototype.preventDefault }); + map.handleMapBrowserEvent(event); clock.tick(50); // default timeout is 80 ms, not called yet - expect(Interaction.zoomByDelta.called).to.be(false); + expect(interaction.handleWheelZoom_.called).to.be(false); + clock.tick(30); - expect(Interaction.zoomByDelta.called).to.be(true); + expect(interaction.handleWheelZoom_.called).to.be(true); done(); }); @@ -98,21 +99,25 @@ describe('ol.interaction.MouseWheelZoom', function() { }); } - describe('spying on ol.interaction.Interaction.zoomByDelta', function() { + describe('spying on view.animate()', function() { + let view; beforeEach(function() { - sinon.spy(Interaction, 'zoomByDelta'); + view = map.getView(); + sinon.spy(view, 'animate'); }); + afterEach(function() { - Interaction.zoomByDelta.restore(); + view.animate.restore(); }); it('works in DOM_DELTA_LINE mode (wheel)', function(done) { map.once('postrender', function() { - const call = Interaction.zoomByDelta.getCall(0); - expect(call.args[1]).to.be(-1); - expect(call.args[2]).to.eql([0, 0]); + const call = view.animate.getCall(0); + expect(call.args[0].resolution).to.be(2); + expect(call.args[0].anchor).to.eql([0, 0]); done(); }); + const event = new MapBrowserEvent('wheel', map, { type: 'wheel', deltaMode: WheelEvent.DOM_DELTA_LINE, @@ -121,17 +126,19 @@ describe('ol.interaction.MouseWheelZoom', function() { preventDefault: Event.prototype.preventDefault }); event.coordinate = [0, 0]; + map.handleMapBrowserEvent(event); }); if (SAFARI) { it('works on Safari (wheel)', function(done) { map.once('postrender', function() { - const call = Interaction.zoomByDelta.getCall(0); - expect(call.args[1]).to.be(-1); - expect(call.args[2]).to.eql([0, 0]); + const call = view.animate.getCall(0); + expect(call.args[0].resolution).to.be(2); + expect(call.args[0].anchor).to.eql([0, 0]); done(); }); + const event = new MapBrowserEvent('mousewheel', map, { type: 'mousewheel', wheelDeltaY: -50, @@ -139,6 +146,7 @@ describe('ol.interaction.MouseWheelZoom', function() { preventDefault: Event.prototype.preventDefault }); event.coordinate = [0, 0]; + map.handleMapBrowserEvent(event); }); } @@ -146,11 +154,12 @@ describe('ol.interaction.MouseWheelZoom', function() { if (!SAFARI) { it('works on other browsers (wheel)', function(done) { map.once('postrender', function() { - const call = Interaction.zoomByDelta.getCall(0); - expect(call.args[1]).to.be(-1); - expect(call.args[2]).to.eql([0, 0]); + const call = view.animate.getCall(0); + expect(call.args[0].resolution).to.be(2); + expect(call.args[0].anchor).to.eql([0, 0]); done(); }); + const event = new MapBrowserEvent('mousewheel', map, { type: 'mousewheel', wheelDeltaY: -120, @@ -158,6 +167,7 @@ describe('ol.interaction.MouseWheelZoom', function() { preventDefault: Event.prototype.preventDefault }); event.coordinate = [0, 0]; + map.handleMapBrowserEvent(event); }); }