From 7f2f789d7f7f81fc4e4ab75355eaf0bc1bc48a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 16 Jul 2022 23:10:23 +0200 Subject: [PATCH 1/5] Remove deprecated 'image' render mode option --- src/ol/layer/VectorTile.js | 6 ------ src/ol/layer/VectorTileRenderType.js | 8 -------- 2 files changed, 14 deletions(-) diff --git a/src/ol/layer/VectorTile.js b/src/ol/layer/VectorTile.js index 1a6be48eae..5c0238c68d 100644 --- a/src/ol/layer/VectorTile.js +++ b/src/ol/layer/VectorTile.js @@ -126,12 +126,6 @@ class VectorTileLayer extends BaseVectorLayer { */ this.un; - if (options.renderMode === VectorTileRenderType.IMAGE) { - //FIXME deprecated - remove this check in v7. - //eslint-disable-next-line - console.warn('renderMode: "image" is deprecated. Option ignored.') - options.renderMode = undefined; - } const renderMode = options.renderMode || VectorTileRenderType.HYBRID; assert( renderMode == VectorTileRenderType.HYBRID || diff --git a/src/ol/layer/VectorTileRenderType.js b/src/ol/layer/VectorTileRenderType.js index e5710fe897..7a8ce37fa9 100644 --- a/src/ol/layer/VectorTileRenderType.js +++ b/src/ol/layer/VectorTileRenderType.js @@ -8,14 +8,6 @@ * @api */ export default { - /** - * Vector tiles are rendered as images. Great performance, but - * point symbols and texts are always rotated with the view and pixels are - * scaled during zoom animations - * @api - * @deprecated - */ - IMAGE: 'image', /** * Polygon and line elements are rendered as images, so pixels * are scaled during zoom animations. Point symbols and texts are accurately From 361f1ab83778eba81c14b2a5659dfbc7e15a1a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 16 Jul 2022 23:11:02 +0200 Subject: [PATCH 2/5] Replace VectorTileRenderType enum with typedef --- src/ol/layer/MapboxVector.js | 2 +- src/ol/layer/VectorTile.js | 20 +++++++------- src/ol/layer/VectorTileRenderType.js | 26 ------------------- src/ol/renderer/canvas/VectorTileLayer.js | 9 +++---- .../renderer/canvas/vectortilelayer.test.js | 3 +-- .../main.js | 3 +-- .../main.js | 3 +-- 7 files changed, 18 insertions(+), 48 deletions(-) delete mode 100644 src/ol/layer/VectorTileRenderType.js diff --git a/src/ol/layer/MapboxVector.js b/src/ol/layer/MapboxVector.js index d1928b41da..9c151f7d5a 100644 --- a/src/ol/layer/MapboxVector.js +++ b/src/ol/layer/MapboxVector.js @@ -81,7 +81,7 @@ class ErrorEvent extends BaseEvent { * Recommended value: Vector tiles are usually generated with a buffer, so this value should match * the largest possible buffer of the used tiles. It should be at least the size of the largest * point symbol or line width. - * @property {import("./VectorTileRenderType.js").default|string} [renderMode='hybrid'] Render mode for vector tiles: + * @property {import("./VectorTile.js").VectorTileRenderType} [renderMode='hybrid'] Render mode for vector tiles: * * `'hybrid'`: Polygon and line elements are rendered as images, so pixels are scaled during zoom * animations. Point symbols and texts are accurately rendered as vectors and can stay upright on * rotated views. diff --git a/src/ol/layer/VectorTile.js b/src/ol/layer/VectorTile.js index 5c0238c68d..eed3e67d3a 100644 --- a/src/ol/layer/VectorTile.js +++ b/src/ol/layer/VectorTile.js @@ -4,7 +4,6 @@ import BaseVectorLayer from './BaseVector.js'; import CanvasVectorTileLayerRenderer from '../renderer/canvas/VectorTileLayer.js'; import TileProperty from './TileProperty.js'; -import VectorTileRenderType from './VectorTileRenderType.js'; import {assert} from '../asserts.js'; /*** @@ -17,6 +16,10 @@ import {assert} from '../asserts.js'; * 'change:source'|'change:preload'|'change:useInterimTilesOnError'|import("../render/EventType").LayerRenderEventTypes, Return>} VectorTileLayerOnSignature */ +/** + * @typedef {'hybrid' | 'vector'} VectorTileRenderType + */ + /** * @typedef {Object} Options * @property {string} [className='ol-layer'] A CSS class name to set to the layer element. @@ -44,7 +47,7 @@ import {assert} from '../asserts.js'; * Recommended value: Vector tiles are usually generated with a buffer, so this value should match * the largest possible buffer of the used tiles. It should be at least the size of the largest * point symbol or line width. - * @property {import("./VectorTileRenderType.js").default|string} [renderMode='hybrid'] Render mode for vector tiles: + * @property {VectorTileRenderType} [renderMode='hybrid'] Render mode for vector tiles: * * `'hybrid'`: Polygon and line elements are rendered as images, so pixels are scaled during zoom * animations. Point symbols and texts are accurately rendered as vectors and can stay upright on * rotated views. @@ -126,16 +129,13 @@ class VectorTileLayer extends BaseVectorLayer { */ this.un; - const renderMode = options.renderMode || VectorTileRenderType.HYBRID; - assert( - renderMode == VectorTileRenderType.HYBRID || - renderMode == VectorTileRenderType.VECTOR, - 28 - ); // `renderMode` must be `'hybrid'` or `'vector'`. + const renderMode = options.renderMode || 'hybrid'; + // `renderMode` must be `'hybrid'` or `'vector'`. + assert(renderMode == 'hybrid' || renderMode == 'vector', 28); /** * @private - * @type {import("./VectorTileRenderType.js").default} + * @type {VectorTileRenderType} */ this.renderMode_ = renderMode; @@ -184,7 +184,7 @@ class VectorTileLayer extends BaseVectorLayer { } /** - * @return {import("./VectorTileRenderType.js").default} The render mode. + * @return {VectorTileRenderType} The render mode. */ getRenderMode() { return this.renderMode_; diff --git a/src/ol/layer/VectorTileRenderType.js b/src/ol/layer/VectorTileRenderType.js deleted file mode 100644 index 7a8ce37fa9..0000000000 --- a/src/ol/layer/VectorTileRenderType.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @module ol/layer/VectorTileRenderType - */ - -/** - * @enum {string} - * Render mode for vector tiles: - * @api - */ -export default { - /** - * Polygon and line elements are rendered as images, so pixels - * are scaled during zoom animations. Point symbols and texts are accurately - * rendered as vectors and can stay upright on rotated views. - * @api - */ - HYBRID: 'hybrid', - /** - * Everything is rendered as vectors. Use this mode for improved - * performance on vector tile layers with only a few rendered features (e.g. - * for highlighting a subset of features of another layer with the same - * source). - * @api - */ - VECTOR: 'vector', -}; diff --git a/src/ol/renderer/canvas/VectorTileLayer.js b/src/ol/renderer/canvas/VectorTileLayer.js index a421db526e..660454212d 100644 --- a/src/ol/renderer/canvas/VectorTileLayer.js +++ b/src/ol/renderer/canvas/VectorTileLayer.js @@ -5,7 +5,6 @@ import CanvasBuilderGroup from '../../render/canvas/BuilderGroup.js'; import CanvasExecutorGroup from '../../render/canvas/ExecutorGroup.js'; import CanvasTileLayerRenderer from './TileLayer.js'; import TileState from '../../TileState.js'; -import VectorTileRenderType from '../../layer/VectorTileRenderType.js'; import ViewHint from '../../ViewHint.js'; import { HIT_DETECT_RESOLUTION, @@ -139,7 +138,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer { if ( render && (hifi || Date.now() - frameState.time < 8) && - layer.getRenderMode() !== VectorTileRenderType.VECTOR + layer.getRenderMode() !== 'vector' ) { this.renderTileImage_(tile, frameState); } @@ -154,7 +153,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer { const layer = this.getLayer(); return ( super.isDrawableTile(tile) && - (layer.getRenderMode() === VectorTileRenderType.VECTOR + (layer.getRenderMode() === 'vector' ? getUid(layer) in tile.executorGroups : tile.hasContext(layer)) ); @@ -289,7 +288,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer { const executorGroupInstructions = builderGroup.finish(); // no need to clip when the render tile is covered by a single source tile const replayExtent = - layer.getRenderMode() !== VectorTileRenderType.VECTOR && + layer.getRenderMode() !== 'vector' && declutter && sourceTiles.length === 1 ? null @@ -784,7 +783,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer { const layer = /** @type {import("../../layer/VectorTile.js").default} */ ( this.getLayer() ); - if (layer.getRenderMode() === VectorTileRenderType.VECTOR) { + if (layer.getRenderMode() === 'vector') { return false; } const replayState = tile.getReplayState(layer); diff --git a/test/browser/spec/ol/renderer/canvas/vectortilelayer.test.js b/test/browser/spec/ol/renderer/canvas/vectortilelayer.test.js index 9b83fd8292..286e3e9098 100644 --- a/test/browser/spec/ol/renderer/canvas/vectortilelayer.test.js +++ b/test/browser/spec/ol/renderer/canvas/vectortilelayer.test.js @@ -11,7 +11,6 @@ import TileState from '../../../../../../src/ol/TileState.js'; import VectorRenderTile from '../../../../../../src/ol/VectorRenderTile.js'; import VectorTile from '../../../../../../src/ol/VectorTile.js'; import VectorTileLayer from '../../../../../../src/ol/layer/VectorTile.js'; -import VectorTileRenderType from '../../../../../../src/ol/layer/VectorTileRenderType.js'; import VectorTileSource from '../../../../../../src/ol/source/VectorTile.js'; import View from '../../../../../../src/ol/View.js'; import XYZ from '../../../../../../src/ol/source/XYZ.js'; @@ -124,7 +123,7 @@ describe('ol/renderer/canvas/VectorTileLayer', function () { it('does not render images for pure vector rendering', function () { const testLayer = new VectorTileLayer({ - renderMode: VectorTileRenderType.VECTOR, + renderMode: 'vector', source: source, style: layerStyle, }); diff --git a/test/rendering/cases/layer-vectortile-rendermode-vector-opacity/main.js b/test/rendering/cases/layer-vectortile-rendermode-vector-opacity/main.js index dfff3a9fb5..eac90bf2a6 100644 --- a/test/rendering/cases/layer-vectortile-rendermode-vector-opacity/main.js +++ b/test/rendering/cases/layer-vectortile-rendermode-vector-opacity/main.js @@ -1,7 +1,6 @@ import MVT from '../../../../src/ol/format/MVT.js'; import Map from '../../../../src/ol/Map.js'; import VectorTileLayer from '../../../../src/ol/layer/VectorTile.js'; -import VectorTileRenderType from '../../../../src/ol/layer/VectorTileRenderType.js'; import VectorTileSource from '../../../../src/ol/source/VectorTile.js'; import View from '../../../../src/ol/View.js'; import {createXYZ} from '../../../../src/ol/tilegrid.js'; @@ -9,7 +8,7 @@ import {createXYZ} from '../../../../src/ol/tilegrid.js'; new Map({ layers: [ new VectorTileLayer({ - renderMode: VectorTileRenderType.VECTOR, + renderMode: 'vector', opacity: 0.1, source: new VectorTileSource({ format: new MVT(), diff --git a/test/rendering/cases/layer-vectortile-rendermode-vector/main.js b/test/rendering/cases/layer-vectortile-rendermode-vector/main.js index 8e762e1217..c4205564a9 100644 --- a/test/rendering/cases/layer-vectortile-rendermode-vector/main.js +++ b/test/rendering/cases/layer-vectortile-rendermode-vector/main.js @@ -1,7 +1,6 @@ import MVT from '../../../../src/ol/format/MVT.js'; import Map from '../../../../src/ol/Map.js'; import VectorTileLayer from '../../../../src/ol/layer/VectorTile.js'; -import VectorTileRenderType from '../../../../src/ol/layer/VectorTileRenderType.js'; import VectorTileSource from '../../../../src/ol/source/VectorTile.js'; import View from '../../../../src/ol/View.js'; import {createXYZ} from '../../../../src/ol/tilegrid.js'; @@ -9,7 +8,7 @@ import {createXYZ} from '../../../../src/ol/tilegrid.js'; new Map({ layers: [ new VectorTileLayer({ - renderMode: VectorTileRenderType.VECTOR, + renderMode: 'vector', source: new VectorTileSource({ format: new MVT(), tileGrid: createXYZ(), From 7ac61fdc70b98e937cd4937e1be8616db374eb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 17 Jul 2022 00:36:18 +0200 Subject: [PATCH 3/5] Replace proj/Units enum with typedef --- src/ol/View.js | 3 +- src/ol/control/ScaleLine.js | 8 +-- src/ol/format/Feature.js | 3 +- src/ol/format/MVT.js | 3 +- src/ol/geom/Geometry.js | 3 +- src/ol/proj.js | 8 +-- src/ol/proj/Projection.js | 10 ++-- src/ol/proj/Units.js | 80 ++++++++------------------ src/ol/proj/epsg3857.js | 3 +- src/ol/proj/epsg4326.js | 3 +- src/ol/proj/proj4.js | 3 +- src/ol/tilegrid.js | 3 +- test/node/ol/proj.test.js | 13 ++--- test/node/ol/tilegrid/TileGrid.test.js | 2 +- 14 files changed, 52 insertions(+), 93 deletions(-) diff --git a/src/ol/View.js b/src/ol/View.js index f7409fa3c2..79ab2e3080 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -2,7 +2,6 @@ * @module ol/View */ import BaseObject from './Object.js'; -import Units from './proj/Units.js'; import ViewHint from './ViewHint.js'; import ViewProperty from './ViewProperty.js'; import {DEFAULT_TILE_SIZE} from './tilegrid/common.js'; @@ -2008,7 +2007,7 @@ export function createResolutionConstraint(options) { // calculate the default min and max resolution const size = !projExtent ? // use an extent that can fit the whole world if need be - (360 * METERS_PER_UNIT[Units.DEGREES]) / projection.getMetersPerUnit() + (360 * METERS_PER_UNIT.degrees) / projection.getMetersPerUnit() : Math.max(getWidth(projExtent), getHeight(projExtent)); const defaultMaxResolution = diff --git a/src/ol/control/ScaleLine.js b/src/ol/control/ScaleLine.js index 031e746ec7..f303c43ecf 100644 --- a/src/ol/control/ScaleLine.js +++ b/src/ol/control/ScaleLine.js @@ -2,7 +2,6 @@ * @module ol/control/ScaleLine */ import Control from './Control.js'; -import ProjUnits from '../proj/Units.js'; import {CLASS_UNSELECTABLE} from '../css.js'; import {METERS_PER_UNIT, getPointResolution} from '../proj.js'; import {assert} from '../asserts.js'; @@ -237,8 +236,7 @@ class ScaleLine extends Control { const center = viewState.center; const projection = viewState.projection; const units = this.getUnits(); - const pointResolutionUnits = - units == 'degrees' ? ProjUnits.DEGREES : ProjUnits.METERS; + const pointResolutionUnits = units == 'degrees' ? 'degrees' : 'm'; let pointResolution = getPointResolution( projection, viewState.resolution, @@ -257,7 +255,7 @@ class ScaleLine extends Control { let nominalCount = minWidth * pointResolution; let suffix = ''; if (units == 'degrees') { - const metersPerDegree = METERS_PER_UNIT[ProjUnits.DEGREES]; + const metersPerDegree = METERS_PER_UNIT.degrees; nominalCount *= metersPerDegree; if (nominalCount < metersPerDegree / 60) { suffix = '\u2033'; // seconds @@ -498,7 +496,7 @@ class ScaleLine extends Control { this.viewState_.projection, this.viewState_.resolution, this.viewState_.center, - ProjUnits.METERS + 'm' ); const dpi = this.dpi_ || DEFAULT_DPI; const inchesPerMeter = 1000 / 25.4; diff --git a/src/ol/format/Feature.js b/src/ol/format/Feature.js index d698e843c8..81f003794d 100644 --- a/src/ol/format/Feature.js +++ b/src/ol/format/Feature.js @@ -1,7 +1,6 @@ /** * @module ol/format/Feature */ -import Units from '../proj/Units.js'; import {abstract} from '../util.js'; import { equivalent as equivalentProjection, @@ -103,7 +102,7 @@ class FeatureFormat { if ( opt_options.extent && dataProjection && - dataProjection.getUnits() === Units.TILE_PIXELS + dataProjection.getUnits() === 'tile-pixels' ) { dataProjection = getProjection(dataProjection); dataProjection.setWorldExtent(opt_options.extent); diff --git a/src/ol/format/MVT.js b/src/ol/format/MVT.js index 0133d7ae5c..849c98dcd8 100644 --- a/src/ol/format/MVT.js +++ b/src/ol/format/MVT.js @@ -13,7 +13,6 @@ import Point from '../geom/Point.js'; import Polygon from '../geom/Polygon.js'; import Projection from '../proj/Projection.js'; import RenderFeature from '../render/Feature.js'; -import Units from '../proj/Units.js'; import {assert} from '../asserts.js'; import {get} from '../proj.js'; import {inflateEnds} from '../geom/flat/orient.js'; @@ -52,7 +51,7 @@ class MVT extends FeatureFormat { */ this.dataProjection = new Projection({ code: '', - units: Units.TILE_PIXELS, + units: 'tile-pixels', }); /** diff --git a/src/ol/geom/Geometry.js b/src/ol/geom/Geometry.js index cbaa005098..fef414eb40 100644 --- a/src/ol/geom/Geometry.js +++ b/src/ol/geom/Geometry.js @@ -2,7 +2,6 @@ * @module ol/geom/Geometry */ import BaseObject from '../Object.js'; -import Units from '../proj/Units.js'; import {abstract} from '../util.js'; import { compose as composeTransform, @@ -310,7 +309,7 @@ class Geometry extends BaseObject { /** @type {import("../proj/Projection.js").default} */ const sourceProj = getProjection(source); const transformFn = - sourceProj.getUnits() == Units.TILE_PIXELS + sourceProj.getUnits() == 'tile-pixels' ? function (inCoordinates, outCoordinates, stride) { const pixelExtent = sourceProj.getExtent(); const projectedExtent = sourceProj.getWorldExtent(); diff --git a/src/ol/proj.js b/src/ol/proj.js index 9cceb41fdc..50341ae95f 100644 --- a/src/ol/proj.js +++ b/src/ol/proj.js @@ -54,13 +54,13 @@ * this. */ import Projection from './proj/Projection.js'; -import Units, {METERS_PER_UNIT} from './proj/Units.js'; import { PROJECTIONS as EPSG3857_PROJECTIONS, fromEPSG4326, toEPSG4326, } from './proj/epsg3857.js'; import {PROJECTIONS as EPSG4326_PROJECTIONS} from './proj/epsg4326.js'; +import {METERS_PER_UNIT} from './proj/Units.js'; import { add as addProj, clear as clearProj, @@ -192,7 +192,7 @@ export function get(projectionLike) { * @param {ProjectionLike} projection The projection. * @param {number} resolution Nominal resolution in projection units. * @param {import("./coordinate.js").Coordinate} point Point to find adjusted resolution at. - * @param {import("./proj/Units.js").default} [opt_units] Units to get the point resolution in. + * @param {import("./proj/Units.js").Units} [opt_units] Units to get the point resolution in. * Default is the projection's units. * @return {number} Point resolution. * @api @@ -212,7 +212,7 @@ export function getPointResolution(projection, resolution, point, opt_units) { } } else { const units = projection.getUnits(); - if ((units == Units.DEGREES && !opt_units) || opt_units == Units.DEGREES) { + if ((units == 'degrees' && !opt_units) || opt_units == 'degrees') { pointResolution = resolution; } else { // Estimate point resolution by transforming the center pixel to EPSG:4326, @@ -222,7 +222,7 @@ export function getPointResolution(projection, resolution, point, opt_units) { projection, get('EPSG:4326') ); - if (toEPSG4326 === identityTransform && units !== Units.DEGREES) { + if (toEPSG4326 === identityTransform && units !== 'degrees') { // no transform is available pointResolution = resolution * projection.getMetersPerUnit(); } else { diff --git a/src/ol/proj/Projection.js b/src/ol/proj/Projection.js index 1724e2535b..1a4808c6dd 100644 --- a/src/ol/proj/Projection.js +++ b/src/ol/proj/Projection.js @@ -6,13 +6,13 @@ import {METERS_PER_UNIT} from './Units.js'; /** * @typedef {Object} Options * @property {string} code The SRS identifier code, e.g. `EPSG:4326`. - * @property {import("./Units.js").default|string} [units] Units. Required unless a + * @property {import("./Units.js").Units} [units] Units. Required unless a * proj4 projection is defined for `code`. * @property {import("../extent.js").Extent} [extent] The validity extent for the SRS. * @property {string} [axisOrientation='enu'] The axis orientation as specified in Proj4. * @property {boolean} [global=false] Whether the projection is valid for the whole globe. * @property {number} [metersPerUnit] The meters per unit for the SRS. - * If not provided, the `units` are used to get the meters per unit from the {@link module:ol/proj/Units~METERS_PER_UNIT} + * If not provided, the `units` are used to get the meters per unit from the {@link METERS_PER_UNIT} * lookup table. * @property {import("../extent.js").Extent} [worldExtent] The world extent for the SRS. * @property {function(number, import("../coordinate.js").Coordinate):number} [getPointResolution] @@ -65,9 +65,9 @@ class Projection { * `this.extent_` and `this.worldExtent_` must be configured properly for each * tile. * @private - * @type {import("./Units.js").default} + * @type {import("./Units.js").Units} */ - this.units_ = /** @type {import("./Units.js").default} */ (options.units); + this.units_ = /** @type {import("./Units.js").Units} */ (options.units); /** * Validity extent of the projection in projected coordinates. For projections @@ -153,7 +153,7 @@ class Projection { /** * Get the units of this projection. - * @return {import("./Units.js").default} Units. + * @return {import("./Units.js").Units} Units. * @api */ getUnits() { diff --git a/src/ol/proj/Units.js b/src/ol/proj/Units.js index c8f13c3bed..e83d9df3ac 100644 --- a/src/ol/proj/Units.js +++ b/src/ol/proj/Units.js @@ -3,58 +3,20 @@ */ /** - * Projection units: `'degrees'`, `'ft'`, `'m'`, `'pixels'`, `'tile-pixels'` or - * `'us-ft'`. - * @enum {string} + * @typedef {'radians' | 'degrees' | 'ft' | 'm' | 'pixels' | 'tile-pixels' | 'us-ft'} Units + * Projection units. */ -const Units = { - /** - * Radians - * @api - */ - RADIANS: 'radians', - /** - * Degrees - * @api - */ - DEGREES: 'degrees', - /** - * Feet - * @api - */ - FEET: 'ft', - /** - * Meters - * @api - */ - METERS: 'm', - /** - * Pixels - * @api - */ - PIXELS: 'pixels', - /** - * Tile Pixels - * @api - */ - TILE_PIXELS: 'tile-pixels', - /** - * US Feet - * @api - */ - USFEET: 'us-ft', -}; /** * See http://duff.ess.washington.edu/data/raster/drg/docs/geotiff.txt * @type {Object} */ const unitByCode = { - '9001': Units.METERS, - '9002': Units.FEET, - '9003': Units.USFEET, - '9101': Units.RADIANS, - '9102': Units.DEGREES, + '9001': 'm', + '9002': 'ft', + '9003': 'us-ft', + '9101': 'radians', + '9102': 'degrees', }; /** @@ -65,18 +27,26 @@ export function fromCode(code) { return unitByCode[code]; } +/** + * @typedef {Object} MetersPerUnitLookup + * @property {number} radians Radians + * @property {number} degrees Degrees + * @property {number} ft Feet + * @property {number} m Meters + * @property {number} us-ft US feet + */ + /** * Meters per unit lookup table. * @const - * @type {Object} + * @type {MetersPerUnitLookup} * @api */ -export const METERS_PER_UNIT = {}; -// use the radius of the Normal sphere -METERS_PER_UNIT[Units.RADIANS] = 6370997 / (2 * Math.PI); -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; +export const METERS_PER_UNIT = { + // use the radius of the Normal sphere + 'radians': 6370997 / (2 * Math.PI), + 'degrees': (2 * Math.PI * 6370997) / 360, + 'ft': 0.3048, + 'm': 1, + 'us-ft': 1200 / 3937, +}; diff --git a/src/ol/proj/epsg3857.js b/src/ol/proj/epsg3857.js index 1ffcf96d65..6018eff23c 100644 --- a/src/ol/proj/epsg3857.js +++ b/src/ol/proj/epsg3857.js @@ -2,7 +2,6 @@ * @module ol/proj/epsg3857 */ import Projection from './Projection.js'; -import Units from './Units.js'; /** * Radius of WGS84 sphere @@ -48,7 +47,7 @@ class EPSG3857Projection extends Projection { constructor(code) { super({ code: code, - units: Units.METERS, + units: 'm', extent: EXTENT, global: true, worldExtent: WORLD_EXTENT, diff --git a/src/ol/proj/epsg4326.js b/src/ol/proj/epsg4326.js index 7bf303cdb0..72436a0a09 100644 --- a/src/ol/proj/epsg4326.js +++ b/src/ol/proj/epsg4326.js @@ -2,7 +2,6 @@ * @module ol/proj/epsg4326 */ import Projection from './Projection.js'; -import Units from './Units.js'; /** * Semi-major radius of the WGS84 ellipsoid. @@ -42,7 +41,7 @@ class EPSG4326Projection extends Projection { constructor(code, opt_axisOrientation) { super({ code: code, - units: Units.DEGREES, + units: 'degrees', extent: EXTENT, axisOrientation: opt_axisOrientation, global: true, diff --git a/src/ol/proj/proj4.js b/src/ol/proj/proj4.js index 7ce0ac56de..923a3bdf59 100644 --- a/src/ol/proj/proj4.js +++ b/src/ol/proj/proj4.js @@ -2,7 +2,6 @@ * @module ol/proj/proj4 */ import Projection from './Projection.js'; -import Units from './Units.js'; import { addCoordinateTransforms, addEquivalentProjections, @@ -33,7 +32,7 @@ export function register(proj4) { const def = proj4.defs(code); let units = def.units; if (!units && def.projName === 'longlat') { - units = Units.DEGREES; + units = 'degrees'; } addProjection( new Projection({ diff --git a/src/ol/tilegrid.js b/src/ol/tilegrid.js index cdaab9c9fd..ef1856461c 100644 --- a/src/ol/tilegrid.js +++ b/src/ol/tilegrid.js @@ -2,7 +2,6 @@ * @module ol/tilegrid */ import TileGrid from './tilegrid/TileGrid.js'; -import Units from './proj/Units.js'; import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from './tilegrid/common.js'; import {METERS_PER_UNIT, get as getProjection} from './proj.js'; import { @@ -176,7 +175,7 @@ export function extentFromProjection(projection) { let extent = projection.getExtent(); if (!extent) { const half = - (180 * METERS_PER_UNIT[Units.DEGREES]) / projection.getMetersPerUnit(); + (180 * METERS_PER_UNIT.degrees) / projection.getMetersPerUnit(); extent = createOrUpdate(-half, -half, half, half); } return extent; diff --git a/test/node/ol/proj.test.js b/test/node/ol/proj.test.js index 6c85776de7..b3f1b1a7c9 100644 --- a/test/node/ol/proj.test.js +++ b/test/node/ol/proj.test.js @@ -1,5 +1,4 @@ import Projection from '../../../src/ol/proj/Projection.js'; -import Units from '../../../src/ol/proj/Units.js'; import View from '../../../src/ol/View.js'; import expect from '../expect.js'; import proj4 from 'proj4'; @@ -159,13 +158,13 @@ describe('ol/proj.js', function () { describe('fromUserResolution()', function () { it("adjusts a resolution for the user projection's units", function () { useGeographic(); - const user = 1 / METERS_PER_UNIT['degrees']; + const user = 1 / METERS_PER_UNIT.degrees; const resolution = fromUserResolution(user, 'EPSG:3857'); expect(resolution).to.roughlyEqual(1, 1e-9); }); it('returns the original if no user projection is set', function () { - const user = METERS_PER_UNIT['meters']; + const user = METERS_PER_UNIT.meters; const resolution = fromUserResolution(user, 'EPSG:3857'); expect(resolution).to.eql(user); }); @@ -176,11 +175,11 @@ describe('ol/proj.js', function () { useGeographic(); const dest = 1; const resolution = toUserResolution(dest, 'EPSG:3857'); - expect(resolution).to.eql(1 / METERS_PER_UNIT['degrees']); + expect(resolution).to.eql(1 / METERS_PER_UNIT.degrees); }); it('returns the original if no user projection is set', function () { - const dest = METERS_PER_UNIT['degrees']; + const dest = METERS_PER_UNIT.degrees; const resolution = toUserResolution(dest, 'EPSG:3857'); expect(resolution).to.eql(dest); }); @@ -435,7 +434,7 @@ describe('ol/proj.js', function () { it('returns the correct point resolution for EPSG:3857 with custom units', function () { let pointResolution = getPointResolution( 'EPSG:3857', - METERS_PER_UNIT['degrees'], + METERS_PER_UNIT.degrees, [0, 0], 'degrees' ); @@ -506,7 +505,7 @@ describe('ol/proj.js', function () { const proj = getProjection('EPSG:4258'); expect(proj.getCode()).to.eql('EPSG:4258'); expect(proj.getUnits()).to.eql('degrees'); - expect(proj.getMetersPerUnit()).to.eql(METERS_PER_UNIT[Units.DEGREES]); + expect(proj.getMetersPerUnit()).to.eql(METERS_PER_UNIT.degrees); delete proj4.defs['EPSG:4258']; }); diff --git a/test/node/ol/tilegrid/TileGrid.test.js b/test/node/ol/tilegrid/TileGrid.test.js index 438cd8df40..517736dbe0 100644 --- a/test/node/ol/tilegrid/TileGrid.test.js +++ b/test/node/ol/tilegrid/TileGrid.test.js @@ -444,7 +444,7 @@ describe('ol/tilegrid/TileGrid.js', function () { const grid = createForProjection(projection); const resolutions = grid.getResolutions(); expect(resolutions[5]).to.be( - (360 * METERS_PER_UNIT['degrees']) / DEFAULT_TILE_SIZE / Math.pow(2, 5) + (360 * METERS_PER_UNIT.degrees) / DEFAULT_TILE_SIZE / Math.pow(2, 5) ); }); From 2caa071a08ae1b5f048fb5747cdb64caf82c800e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 24 Jul 2022 17:42:23 +0200 Subject: [PATCH 4/5] Replace MouseWheelZoom Mode enum with typedef --- src/ol/interaction/MouseWheelZoom.js | 10 +++------- .../spec/ol/interaction/mousewheelzoom.test.js | 13 +++++++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index 6fcc526230..81c638dca9 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -8,12 +8,8 @@ import {all, always, focusWithTabindex} from '../events/condition.js'; import {clamp} from '../math.js'; /** - * @enum {string} + * @typedef {'trackpad' | 'wheel'} Mode */ -export const Mode = { - TRACKPAD: 'trackpad', - WHEEL: 'wheel', -}; /** * @typedef {Object} Options @@ -218,12 +214,12 @@ class MouseWheelZoom extends Interaction { } if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) { - this.mode_ = Math.abs(delta) < 4 ? Mode.TRACKPAD : Mode.WHEEL; + this.mode_ = Math.abs(delta) < 4 ? 'trackpad' : 'wheel'; } const view = map.getView(); if ( - this.mode_ === Mode.TRACKPAD && + this.mode_ === 'trackpad' && !(view.getConstrainResolution() || this.constrainResolution_) ) { if (this.trackpadTimeoutId_) { diff --git a/test/browser/spec/ol/interaction/mousewheelzoom.test.js b/test/browser/spec/ol/interaction/mousewheelzoom.test.js index 0640478fea..225d4ebd5c 100644 --- a/test/browser/spec/ol/interaction/mousewheelzoom.test.js +++ b/test/browser/spec/ol/interaction/mousewheelzoom.test.js @@ -1,14 +1,15 @@ import Event from '../../../../../src/ol/events/Event.js'; import Map from '../../../../../src/ol/Map.js'; import MapBrowserEvent from '../../../../../src/ol/MapBrowserEvent.js'; -import MouseWheelZoom, { - Mode, -} from '../../../../../src/ol/interaction/MouseWheelZoom.js'; +import MouseWheelZoom from '../../../../../src/ol/interaction/MouseWheelZoom.js'; import View from '../../../../../src/ol/View.js'; import {DEVICE_PIXEL_RATIO, FIREFOX} from '../../../../../src/ol/has.js'; describe('ol.interaction.MouseWheelZoom', function () { - let map, interaction; + /** @type {Map} */ + let map; + /** @type {MouseWheelZoom} */ + let interaction; beforeEach(function () { interaction = new MouseWheelZoom(); @@ -65,7 +66,7 @@ describe('ol.interaction.MouseWheelZoom', function () { if (FIREFOX) { it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function (done) { map.once('postrender', function () { - expect(interaction.mode_).to.be(Mode.TRACKPAD); + expect(interaction.mode_).to.be('trackpad'); done(); }); const event = new MapBrowserEvent('wheel', map, { @@ -83,7 +84,7 @@ describe('ol.interaction.MouseWheelZoom', function () { if (!FIREFOX) { it('works in DOM_DELTA_PIXEL mode (trackpad)', function (done) { map.once('postrender', function () { - expect(interaction.mode_).to.be(Mode.TRACKPAD); + expect(interaction.mode_).to.be('trackpad'); done(); }); const event = new MapBrowserEvent('wheel', map, { From 14c2c31d4cbdb9c31e1105ed0596dcfd4f765da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 24 Jul 2022 17:51:19 +0200 Subject: [PATCH 5/5] Replace RasterOperationType enum with typedef --- src/ol/source/Raster.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/ol/source/Raster.js b/src/ol/source/Raster.js index b3c3464934..2a9953b387 100644 --- a/src/ol/source/Raster.js +++ b/src/ol/source/Raster.js @@ -450,13 +450,9 @@ const RasterEventType = { }; /** + * @typedef {'pixel' | 'image'} RasterOperationType * Raster operation type. Supported values are `'pixel'` and `'image'`. - * @enum {string} */ -const RasterOperationType = { - PIXEL: 'pixel', - IMAGE: 'image', -}; /** * @typedef {import("./Image.js").ImageSourceEventTypes|'beforeoperations'|'afteroperations'} RasterSourceEventTypes @@ -575,9 +571,7 @@ class RasterSource extends ImageSource { * @type {RasterOperationType} */ this.operationType_ = - options.operationType !== undefined - ? options.operationType - : RasterOperationType.PIXEL; + options.operationType !== undefined ? options.operationType : 'pixel'; /** * @private @@ -692,7 +686,7 @@ class RasterSource extends ImageSource { this.processor_ = new Processor({ operation: operation, - imageOps: this.operationType_ === RasterOperationType.IMAGE, + imageOps: this.operationType_ === 'image', queue: 1, lib: opt_lib, threads: this.threads_,