diff --git a/src/ol/control/ScaleLine.js b/src/ol/control/ScaleLine.js index f496316ff6..031e746ec7 100644 --- a/src/ol/control/ScaleLine.js +++ b/src/ol/control/ScaleLine.js @@ -13,17 +13,9 @@ import {assert} from '../asserts.js'; const UNITS_PROP = 'units'; /** - * Units for the scale line. Supported values are `'degrees'`, `'imperial'`, - * `'nautical'`, `'metric'`, `'us'`. - * @enum {string} + * @typedef {'degrees' | 'imperial' | 'nautical' | 'metric' | 'us'} Units + * Units for the scale line. */ -export const Units = { - DEGREES: 'degrees', - IMPERIAL: 'imperial', - NAUTICAL: 'nautical', - METRIC: 'metric', - US: 'us', -}; /** * @const @@ -57,7 +49,7 @@ const DEFAULT_DPI = 25.4 / 0.28; * should be re-rendered. This is called in a `requestAnimationFrame` callback. * @property {HTMLElement|string} [target] Specify a target if you want the control * to be rendered outside of the map's viewport. - * @property {import("./ScaleLine.js").Units|string} [units='metric'] Units. + * @property {Units} [units='metric'] Units. * @property {boolean} [bar=false] Render scalebars instead of a line. * @property {number} [steps=4] Number of steps the scalebar should use. Use even numbers * for best results. Only applies when `bar` is `true`. @@ -164,7 +156,7 @@ class ScaleLine extends Control { this.addChangeListener(UNITS_PROP, this.handleUnitsChanged_); - this.setUnits(options.units || Units.METRIC); + this.setUnits(options.units || 'metric'); /** * @private @@ -193,7 +185,7 @@ class ScaleLine extends Control { /** * Return the units to use in the scale line. - * @return {import("./ScaleLine.js").Units} The units + * @return {Units} The units * to use in the scale line. * @observable * @api @@ -211,7 +203,7 @@ class ScaleLine extends Control { /** * Set the units to use in the scale line. - * @param {import("./ScaleLine.js").Units} units The units to use in the scale line. + * @param {Units} units The units to use in the scale line. * @observable * @api */ @@ -246,7 +238,7 @@ class ScaleLine extends Control { const projection = viewState.projection; const units = this.getUnits(); const pointResolutionUnits = - units == Units.DEGREES ? ProjUnits.DEGREES : ProjUnits.METERS; + units == 'degrees' ? ProjUnits.DEGREES : ProjUnits.METERS; let pointResolution = getPointResolution( projection, viewState.resolution, @@ -264,7 +256,7 @@ class ScaleLine extends Control { let nominalCount = minWidth * pointResolution; let suffix = ''; - if (units == Units.DEGREES) { + if (units == 'degrees') { const metersPerDegree = METERS_PER_UNIT[ProjUnits.DEGREES]; nominalCount *= metersPerDegree; if (nominalCount < metersPerDegree / 60) { @@ -276,7 +268,7 @@ class ScaleLine extends Control { } else { suffix = '\u00b0'; // degrees } - } else if (units == Units.IMPERIAL) { + } else if (units == 'imperial') { if (nominalCount < 0.9144) { suffix = 'in'; pointResolution /= 0.0254; @@ -287,10 +279,10 @@ class ScaleLine extends Control { suffix = 'mi'; pointResolution /= 1609.344; } - } else if (units == Units.NAUTICAL) { + } else if (units == 'nautical') { pointResolution /= 1852; suffix = 'NM'; - } else if (units == Units.METRIC) { + } else if (units == 'metric') { if (nominalCount < 0.001) { suffix = 'μm'; pointResolution *= 1000000; @@ -303,7 +295,7 @@ class ScaleLine extends Control { suffix = 'km'; pointResolution /= 1000; } - } else if (units == Units.US) { + } else if (units == 'us') { if (nominalCount < 0.9144) { suffix = 'in'; pointResolution *= 39.37; diff --git a/src/ol/format/EsriJSON.js b/src/ol/format/EsriJSON.js index 21605642f3..164f7d5acf 100644 --- a/src/ol/format/EsriJSON.js +++ b/src/ol/format/EsriJSON.js @@ -2,7 +2,6 @@ * @module ol/format/EsriJSON */ import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import JSONFeature from './JSONFeature.js'; import LineString from '../geom/LineString.js'; import LinearRing from '../geom/LinearRing.js'; @@ -295,7 +294,7 @@ function readGeometry(object, opt_options) { * array. It is used for checking for holes. * Logic inspired by: https://github.com/Esri/terraformer-arcgis-parser * @param {Array>>} rings Rings. - * @param {import("../geom/GeometryLayout.js").default} layout Geometry layout. + * @param {import("../geom/Geometry.js").GeometryLayout} layout Geometry layout. * @return {Array>>>} Transformed rings. */ function convertRings(rings, layout) { @@ -352,14 +351,11 @@ function convertRings(rings, layout) { function readPointGeometry(object) { let point; if (object.m !== undefined && object.z !== undefined) { - point = new Point( - [object.x, object.y, object.z, object.m], - GeometryLayout.XYZM - ); + point = new Point([object.x, object.y, object.z, object.m], 'XYZM'); } else if (object.z !== undefined) { - point = new Point([object.x, object.y, object.z], GeometryLayout.XYZ); + point = new Point([object.x, object.y, object.z], 'XYZ'); } else if (object.m !== undefined) { - point = new Point([object.x, object.y, object.m], GeometryLayout.XYM); + point = new Point([object.x, object.y, object.m], 'XYM'); } else { point = new Point([object.x, object.y]); } @@ -386,16 +382,17 @@ function readMultiLineStringGeometry(object) { /** * @param {EsriJSONHasZM} object Object. - * @return {import("../geom/GeometryLayout.js").default} The geometry layout to use. + * @return {import("../geom/Geometry.js").GeometryLayout} The geometry layout to use. */ function getGeometryLayout(object) { - let layout = GeometryLayout.XY; + /** @type {import("../geom/Geometry.js").GeometryLayout} */ + let layout = 'XY'; if (object.hasZ === true && object.hasM === true) { - layout = GeometryLayout.XYZM; + layout = 'XYZM'; } else if (object.hasZ === true) { - layout = GeometryLayout.XYZ; + layout = 'XYZ'; } else if (object.hasM === true) { - layout = GeometryLayout.XYM; + layout = 'XYM'; } return layout; } @@ -437,26 +434,26 @@ function writePointGeometry(geometry, opt_options) { /** @type {EsriJSONPoint} */ let esriJSON; const layout = geometry.getLayout(); - if (layout === GeometryLayout.XYZ) { + if (layout === 'XYZ') { esriJSON = { x: coordinates[0], y: coordinates[1], z: coordinates[2], }; - } else if (layout === GeometryLayout.XYM) { + } else if (layout === 'XYM') { esriJSON = { x: coordinates[0], y: coordinates[1], m: coordinates[2], }; - } else if (layout === GeometryLayout.XYZM) { + } else if (layout === 'XYZM') { esriJSON = { x: coordinates[0], y: coordinates[1], z: coordinates[2], m: coordinates[3], }; - } else if (layout === GeometryLayout.XY) { + } else if (layout === 'XY') { esriJSON = { x: coordinates[0], y: coordinates[1], @@ -474,8 +471,8 @@ function writePointGeometry(geometry, opt_options) { function getHasZM(geometry) { const layout = geometry.getLayout(); return { - hasZ: layout === GeometryLayout.XYZ || layout === GeometryLayout.XYZM, - hasM: layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM, + hasZ: layout === 'XYZ' || layout === 'XYZM', + hasM: layout === 'XYM' || layout === 'XYZM', }; } diff --git a/src/ol/format/GML3.js b/src/ol/format/GML3.js index 28ab6ee76f..d4143d62d8 100644 --- a/src/ol/format/GML3.js +++ b/src/ol/format/GML3.js @@ -3,7 +3,6 @@ */ import GML2 from './GML2.js'; import GMLBase, {GMLNS} from './GMLBase.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import MultiLineString from '../geom/MultiLineString.js'; import MultiPolygon from '../geom/MultiPolygon.js'; @@ -308,7 +307,7 @@ class GML3 extends GMLBase { extend(flatCoordinates, flatLinearRings[i]); ends.push(flatCoordinates.length); } - return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends); + return new Polygon(flatCoordinates, 'XYZ', ends); } else { return undefined; } @@ -329,7 +328,7 @@ class GML3 extends GMLBase { this ); if (flatCoordinates) { - const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ); + const lineString = new LineString(flatCoordinates, 'XYZ'); return lineString; } else { return undefined; diff --git a/src/ol/format/GMLBase.js b/src/ol/format/GMLBase.js index 718652acff..c348c2d09e 100644 --- a/src/ol/format/GMLBase.js +++ b/src/ol/format/GMLBase.js @@ -5,7 +5,6 @@ // of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect // envelopes/extents, only geometries! import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import LinearRing from '../geom/LinearRing.js'; import MultiLineString from '../geom/MultiLineString.js'; @@ -370,7 +369,7 @@ class GMLBase extends XMLFeature { readPoint(node, objectStack) { const flatCoordinates = this.readFlatCoordinatesFromNode(node, objectStack); if (flatCoordinates) { - return new Point(flatCoordinates, GeometryLayout.XYZ); + return new Point(flatCoordinates, 'XYZ'); } } @@ -465,7 +464,7 @@ class GMLBase extends XMLFeature { readLineString(node, objectStack) { const flatCoordinates = this.readFlatCoordinatesFromNode(node, objectStack); if (flatCoordinates) { - const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ); + const lineString = new LineString(flatCoordinates, 'XYZ'); return lineString; } else { return undefined; @@ -500,7 +499,7 @@ class GMLBase extends XMLFeature { readLinearRing(node, objectStack) { const flatCoordinates = this.readFlatCoordinatesFromNode(node, objectStack); if (flatCoordinates) { - return new LinearRing(flatCoordinates, GeometryLayout.XYZ); + return new LinearRing(flatCoordinates, 'XYZ'); } } @@ -526,7 +525,7 @@ class GMLBase extends XMLFeature { extend(flatCoordinates, flatLinearRings[i]); ends.push(flatCoordinates.length); } - return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends); + return new Polygon(flatCoordinates, 'XYZ', ends); } else { return undefined; } diff --git a/src/ol/format/GPX.js b/src/ol/format/GPX.js index 5a889e2e32..2601b14489 100644 --- a/src/ol/format/GPX.js +++ b/src/ol/format/GPX.js @@ -2,7 +2,6 @@ * @module ol/format/GPX */ import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import MultiLineString from '../geom/MultiLineString.js'; import Point from '../geom/Point.js'; @@ -557,19 +556,20 @@ function appendCoordinate(flatCoordinates, layoutOptions, node, values) { * @param {LayoutOptions} layoutOptions Layout options. * @param {Array} flatCoordinates Flat coordinates. * @param {Array} [ends] Ends. - * @return {import("../geom/GeometryLayout.js").default} Layout. + * @return {import("../geom/Geometry.js").GeometryLayout} Layout. */ function applyLayoutOptions(layoutOptions, flatCoordinates, ends) { - let layout = GeometryLayout.XY; + /** @type {import("../geom/Geometry.js").GeometryLayout} */ + let layout = 'XY'; let stride = 2; if (layoutOptions.hasZ && layoutOptions.hasM) { - layout = GeometryLayout.XYZM; + layout = 'XYZM'; stride = 4; } else if (layoutOptions.hasZ) { - layout = GeometryLayout.XYZ; + layout = 'XYZ'; stride = 3; } else if (layoutOptions.hasM) { - layout = GeometryLayout.XYM; + layout = 'XYM'; stride = 3; } if (stride !== 4) { @@ -800,17 +800,17 @@ function writeWptType(node, coordinate, objectStack) { node.setAttributeNS(null, 'lon', String(coordinate[0])); const geometryLayout = context['geometryLayout']; switch (geometryLayout) { - case GeometryLayout.XYZM: + case 'XYZM': if (coordinate[3] !== 0) { properties['time'] = coordinate[3]; } // fall through - case GeometryLayout.XYZ: + case 'XYZ': if (coordinate[2] !== 0) { properties['ele'] = coordinate[2]; } break; - case GeometryLayout.XYM: + case 'XYM': if (coordinate[2] !== 0) { properties['time'] = coordinate[2]; } diff --git a/src/ol/format/IGC.js b/src/ol/format/IGC.js index 2c00be8359..0583fb8b30 100644 --- a/src/ol/format/IGC.js +++ b/src/ol/format/IGC.js @@ -2,21 +2,15 @@ * @module ol/format/IGC */ import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import TextFeature from './TextFeature.js'; import {get as getProjection} from '../proj.js'; import {transformGeometryWithOptions} from './Feature.js'; /** + * @typedef {'barometric' | 'gps' | 'none'} IGCZ * IGC altitude/z. One of 'barometric', 'gps', 'none'. - * @enum {string} */ -const IGCZ = { - BAROMETRIC: 'barometric', - GPS: 'gps', - NONE: 'none', -}; /** * @const @@ -47,7 +41,7 @@ const NEWLINE_RE = /\r\n|\r|\n/; /** * @typedef {Object} Options - * @property {IGCZ|string} [altitudeMode='none'] Altitude mode. Possible + * @property {IGCZ} [altitudeMode='none'] Altitude mode. Possible * values are `'barometric'`, `'gps'`, and `'none'`. */ @@ -79,9 +73,7 @@ class IGC extends TextFeature { * @private * @type {IGCZ} */ - this.altitudeMode_ = options.altitudeMode - ? options.altitudeMode - : IGCZ.NONE; + this.altitudeMode_ = options.altitudeMode ? options.altitudeMode : 'none'; } /** @@ -119,11 +111,11 @@ class IGC extends TextFeature { x = -x; } flatCoordinates.push(x, y); - if (altitudeMode != IGCZ.NONE) { + if (altitudeMode != 'none') { let z; - if (altitudeMode == IGCZ.GPS) { + if (altitudeMode == 'gps') { z = parseInt(m[11], 10); - } else if (altitudeMode == IGCZ.BAROMETRIC) { + } else if (altitudeMode == 'barometric') { z = parseInt(m[12], 10); } else { z = 0; @@ -155,8 +147,7 @@ class IGC extends TextFeature { if (flatCoordinates.length === 0) { return null; } - const layout = - altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM; + const layout = altitudeMode == 'none' ? 'XYM' : 'XYZM'; const lineString = new LineString(flatCoordinates, layout); const feature = new Feature( transformGeometryWithOptions(lineString, false, opt_options) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index e2b3587bb8..8f0de59ae7 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -4,10 +4,7 @@ import Feature from '../Feature.js'; import Fill from '../style/Fill.js'; import GeometryCollection from '../geom/GeometryCollection.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import Icon from '../style/Icon.js'; -import IconAnchorUnits from '../style/IconAnchorUnits.js'; -import IconOrigin from '../style/IconOrigin.js'; import ImageState from '../ImageState.js'; import LineString from '../geom/LineString.js'; import MultiLineString from '../geom/MultiLineString.js'; @@ -57,10 +54,10 @@ import {transformGeometryWithOptions} from './Feature.js'; /** * @typedef {Object} Vec2 * @property {number} x X coordinate. - * @property {import("../style/IconAnchorUnits").default} xunits Units of x. + * @property {import("../style/Icon.js").IconAnchorUnits} xunits Units of x. * @property {number} y Y coordinate. - * @property {import("../style/IconAnchorUnits").default} yunits Units of Y. - * @property {import("../style/IconOrigin.js").default} [origin] Origin. + * @property {import("../style/Icon.js").IconAnchorUnits} yunits Units of Y. + * @property {import("../style/Icon.js").IconOrigin} [origin] Origin. */ /** @@ -96,12 +93,12 @@ const SCHEMA_LOCATION = 'https://developers.google.com/kml/schema/kml22gx.xsd'; /** - * @type {Object} + * @type {Object} */ const ICON_ANCHOR_UNITS_MAP = { - 'fraction': IconAnchorUnits.FRACTION, - 'pixels': IconAnchorUnits.PIXELS, - 'insetPixels': IconAnchorUnits.PIXELS, + 'fraction': 'fraction', + 'pixels': 'pixels', + 'insetPixels': 'pixels', }; /** @@ -212,12 +209,12 @@ export function getDefaultFillStyle() { let DEFAULT_IMAGE_STYLE_ANCHOR; /** - * @type {import("../style/IconAnchorUnits").default} + * @type {import("../style/Icon.js").IconAnchorUnits} */ let DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS; /** - * @type {import("../style/IconAnchorUnits").default} + * @type {import("../style/Icon.js").IconAnchorUnits} */ let DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS; @@ -324,9 +321,9 @@ function createStyleDefaults() { DEFAULT_IMAGE_STYLE_ANCHOR = [20, 2]; - DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS = IconAnchorUnits.PIXELS; + DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS = 'pixels'; - DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS = IconAnchorUnits.PIXELS; + DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS = 'pixels'; DEFAULT_IMAGE_STYLE_SIZE = [64, 64]; @@ -335,7 +332,7 @@ function createStyleDefaults() { DEFAULT_IMAGE_STYLE = new Icon({ anchor: DEFAULT_IMAGE_STYLE_ANCHOR, - anchorOrigin: IconOrigin.BOTTOM_LEFT, + anchorOrigin: 'bottom-left', anchorXUnits: DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS, anchorYUnits: DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS, crossOrigin: 'anonymous', @@ -1175,18 +1172,19 @@ function readStyleURL(node) { function readVec2(node) { const xunits = node.getAttribute('xunits'); const yunits = node.getAttribute('yunits'); + /** @type {import('../style/Icon.js').IconOrigin} */ let origin; if (xunits !== 'insetPixels') { if (yunits !== 'insetPixels') { - origin = IconOrigin.BOTTOM_LEFT; + origin = 'bottom-left'; } else { - origin = IconOrigin.TOP_LEFT; + origin = 'top-left'; } } else { if (yunits !== 'insetPixels') { - origin = IconOrigin.BOTTOM_RIGHT; + origin = 'bottom-right'; } else { - origin = IconOrigin.TOP_RIGHT; + origin = 'top-right'; } } return { @@ -1267,7 +1265,8 @@ function iconStyleParser(node, objectStack) { src = DEFAULT_IMAGE_STYLE_SRC; } let anchor, anchorXUnits, anchorYUnits; - let anchorOrigin = IconOrigin.BOTTOM_LEFT; + /** @type {import('../style/Icon.js').IconOrigin|undefined} */ + let anchorOrigin = 'bottom-left'; const hotSpot = /** @type {Vec2|undefined} */ (object['hotSpot']); if (hotSpot) { anchor = [hotSpot.x, hotSpot.y]; @@ -1327,7 +1326,7 @@ function iconStyleParser(node, objectStack) { anchorYUnits: anchorYUnits, crossOrigin: this.crossOrigin_, offset: offset, - offsetOrigin: IconOrigin.BOTTOM_LEFT, + offsetOrigin: 'bottom-left', rotation: rotation, scale: scale, size: size, @@ -1594,7 +1593,7 @@ function readGxTrack(node, objectStack) { ); } } - return new LineString(flatCoordinates, GeometryLayout.XYZM); + return new LineString(flatCoordinates, 'XYZM'); } /** @@ -1677,7 +1676,7 @@ function readLineString(node, objectStack) { ); const flatCoordinates = readFlatCoordinatesFromNode(node, objectStack); if (flatCoordinates) { - const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ); + const lineString = new LineString(flatCoordinates, 'XYZ'); lineString.setProperties(properties, true); return lineString; } else { @@ -1699,7 +1698,7 @@ function readLinearRing(node, objectStack) { ); const flatCoordinates = readFlatCoordinatesFromNode(node, objectStack); if (flatCoordinates) { - const polygon = new Polygon(flatCoordinates, GeometryLayout.XYZ, [ + const polygon = new Polygon(flatCoordinates, 'XYZ', [ flatCoordinates.length, ]); polygon.setProperties(properties, true); @@ -1795,7 +1794,7 @@ function readPoint(node, objectStack) { ); const flatCoordinates = readFlatCoordinatesFromNode(node, objectStack); if (flatCoordinates) { - const point = new Point(flatCoordinates, GeometryLayout.XYZ); + const point = new Point(flatCoordinates, 'XYZ'); point.setProperties(properties, true); return point; } else { @@ -1838,7 +1837,7 @@ function readPolygon(node, objectStack) { extend(flatCoordinates, flatLinearRings[i]); ends.push(flatCoordinates.length); } - const polygon = new Polygon(flatCoordinates, GeometryLayout.XYZ, ends); + const polygon = new Polygon(flatCoordinates, 'XYZ', ends); polygon.setProperties(properties, true); return polygon; } else { @@ -2338,9 +2337,9 @@ function writeCoordinatesTextNode(node, coordinates, objectStack) { const stride = context['stride']; let dimension; - if (layout == GeometryLayout.XY || layout == GeometryLayout.XYM) { + if (layout == 'XY' || layout == 'XYM') { dimension = 2; - } else if (layout == GeometryLayout.XYZ || layout == GeometryLayout.XYZM) { + } else if (layout == 'XYZ' || layout == 'XYZM') { dimension = 3; } else { assert(false, 34); // Invalid geometry layout @@ -2628,9 +2627,9 @@ function writeIconStyle(node, style, objectStack) { if (anchor && (anchor[0] !== size[0] / 2 || anchor[1] !== size[1] / 2)) { const /** @type {Vec2} */ hotSpot = { x: anchor[0], - xunits: IconAnchorUnits.PIXELS, + xunits: 'pixels', y: size[1] - anchor[1], - yunits: IconAnchorUnits.PIXELS, + yunits: 'pixels', }; properties['hotSpot'] = hotSpot; } diff --git a/src/ol/format/MVT.js b/src/ol/format/MVT.js index e5040ae45d..0133d7ae5c 100644 --- a/src/ol/format/MVT.js +++ b/src/ol/format/MVT.js @@ -4,7 +4,6 @@ //FIXME Implement projection handling import FeatureFormat, {transformGeometryWithOptions} from './Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import MultiLineString from '../geom/MultiLineString.js'; import MultiPoint from '../geom/MultiPoint.js'; @@ -204,18 +203,18 @@ class MVT extends FeatureFormat { const endss = inflateEnds(flatCoordinates, ends); geom = endss.length > 1 - ? new MultiPolygon(flatCoordinates, GeometryLayout.XY, endss) - : new Polygon(flatCoordinates, GeometryLayout.XY, ends); + ? new MultiPolygon(flatCoordinates, 'XY', endss) + : new Polygon(flatCoordinates, 'XY', ends); } else { geom = geometryType === 'Point' - ? new Point(flatCoordinates, GeometryLayout.XY) + ? new Point(flatCoordinates, 'XY') : geometryType === 'LineString' - ? new LineString(flatCoordinates, GeometryLayout.XY) + ? new LineString(flatCoordinates, 'XY') : geometryType === 'MultiPoint' - ? new MultiPoint(flatCoordinates, GeometryLayout.XY) + ? new MultiPoint(flatCoordinates, 'XY') : geometryType === 'MultiLineString' - ? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends) + ? new MultiLineString(flatCoordinates, 'XY', ends) : null; } const ctor = /** @type {typeof import("../Feature.js").default} */ ( diff --git a/src/ol/format/OSMXML.js b/src/ol/format/OSMXML.js index c75a217426..b2570c0dfa 100644 --- a/src/ol/format/OSMXML.js +++ b/src/ol/format/OSMXML.js @@ -3,7 +3,6 @@ */ // FIXME add typedef for stack state objects import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import Point from '../geom/Point.js'; import Polygon from '../geom/Polygon.js'; @@ -88,11 +87,11 @@ class OSMXML extends XMLFeature { let geometry; if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) { // closed way - geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [ + geometry = new Polygon(flatCoordinates, 'XY', [ flatCoordinates.length, ]); } else { - geometry = new LineString(flatCoordinates, GeometryLayout.XY); + geometry = new LineString(flatCoordinates, 'XY'); } transformGeometryWithOptions(geometry, false, options); const feature = new Feature(geometry); diff --git a/src/ol/format/Polyline.js b/src/ol/format/Polyline.js index b87c162be1..d1393956fa 100644 --- a/src/ol/format/Polyline.js +++ b/src/ol/format/Polyline.js @@ -2,7 +2,6 @@ * @module ol/format/Polyline */ import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import TextFeature from './TextFeature.js'; import {assert} from '../asserts.js'; @@ -15,7 +14,7 @@ import {transformGeometryWithOptions} from './Feature.js'; /** * @typedef {Object} Options * @property {number} [factor=1e5] The factor by which the coordinates values will be scaled. - * @property {GeometryLayout} [geometryLayout='XY'] Layout of the + * @property {import("../geom/Geometry.js").GeometryLayout} [geometryLayout='XY'] Layout of the * feature geometries created by the format reader. */ @@ -55,11 +54,11 @@ class Polyline extends TextFeature { /** * @private - * @type {import("../geom/GeometryLayout").default} + * @type {import("../geom/Geometry.js").GeometryLayout} */ this.geometryLayout_ = options.geometryLayout ? options.geometryLayout - : GeometryLayout.XY; + : 'XY'; } /** diff --git a/src/ol/format/WKB.js b/src/ol/format/WKB.js index 669f265593..1b75d51333 100644 --- a/src/ol/format/WKB.js +++ b/src/ol/format/WKB.js @@ -4,7 +4,6 @@ import Feature from '../Feature.js'; import FeatureFormat, {transformGeometryWithOptions} from './Feature.js'; import GeometryCollection from '../geom/GeometryCollection.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import MultiLineString from '../geom/MultiLineString.js'; import MultiPoint from '../geom/MultiPoint.js'; @@ -53,17 +52,50 @@ class WkbReader { * @param {DataView} view source to read */ constructor(view) { + /** @private */ this.view_ = view; + + /** + * @type {number} + * @private + */ this.pos_ = 0; + /** + * @type {boolean} + * @private + */ this.initialized_ = false; + + /** + * @type {boolean} + * @private + */ this.isLittleEndian_ = false; + + /** + * @type {boolean} + * @private + */ this.hasZ_ = false; + + /** + * @type {boolean} + * @private + */ this.hasM_ = false; - /** @type {number|null} */ + + /** + * @type {number|null} + * @private + */ this.srid_ = null; - this.layout_ = GeometryLayout.XY; + /** + * @type {import("../geom/Geometry.js").GeometryLayout} + * @private + */ + this.layout_ = 'XY'; } /** @@ -164,7 +196,9 @@ class WkbReader { wkbTypeThousandth === 3; const hasSRID = Boolean(wkbType & 0x20000000); const typeId = (wkbType & 0x0fffffff) % 1000; // Assume 1000 is an upper limit for type ID - const layout = ['XY', hasZ ? 'Z' : '', hasM ? 'M' : ''].join(''); + const layout = /** @type {import("../geom/Geometry.js").GeometryLayout} */ ( + ['XY', hasZ ? 'Z' : '', hasM ? 'M' : ''].join('') + ); const srid = hasSRID ? this.readUint32(isLittleEndian) : null; @@ -415,7 +449,7 @@ class WkbWriter { /** * @param {import('../coordinate.js').Coordinate} coords coords - * @param {import("../geom/GeometryLayout").default} layout layout + * @param {import("../geom/Geometry.js").GeometryLayout} layout layout */ writePoint(coords, layout) { /** @@ -439,7 +473,7 @@ class WkbWriter { /** * @param {Array} coords coords - * @param {import("../geom/GeometryLayout").default} layout layout + * @param {import("../geom/Geometry.js").GeometryLayout} layout layout */ writeLineString(coords, layout) { this.writeUint32(coords.length); // numPoints @@ -450,7 +484,7 @@ class WkbWriter { /** * @param {Array>} rings rings - * @param {import("../geom/GeometryLayout").default} layout layout + * @param {import("../geom/Geometry.js").GeometryLayout} layout layout */ writePolygon(rings, layout) { this.writeUint32(rings.length); // numRings @@ -484,7 +518,7 @@ class WkbWriter { /** * @param {Array} coords coords - * @param {string} layout layout + * @param {import("../geom/Geometry.js").GeometryLayout} layout layout */ writeMultiPoint(coords, layout) { this.writeUint32(coords.length); // numItems @@ -496,7 +530,7 @@ class WkbWriter { /** * @param {Array>} coords coords - * @param {string} layout layout + * @param {import("../geom/Geometry.js").GeometryLayout} layout layout */ writeMultiLineString(coords, layout) { this.writeUint32(coords.length); // numItems @@ -508,7 +542,7 @@ class WkbWriter { /** * @param {Array>>} coords coords - * @param {string} layout layout + * @param {import("../geom/Geometry.js").GeometryLayout} layout layout */ writeMultiPolygon(coords, layout) { this.writeUint32(coords.length); // numItems @@ -531,31 +565,31 @@ class WkbWriter { /** * @param {import("../geom/Geometry.js").default} geom geometry - * @param {import("../geom/GeometryLayout.js").default} [layout] layout - * @return {import("../geom/GeometryLayout.js").default} minumum layout made by common axes + * @param {import("../geom/Geometry.js").GeometryLayout} [layout] layout + * @return {import("../geom/Geometry.js").GeometryLayout} minumum layout made by common axes */ - findMinimumLayout(geom, layout = GeometryLayout.XYZM) { + findMinimumLayout(geom, layout = 'XYZM') { /** - * @param {import("../geom/GeometryLayout.js").default} a A - * @param {import("../geom/GeometryLayout.js").default} b B - * @return {import("../geom/GeometryLayout.js").default} minumum layout made by common axes + * @param {import("../geom/Geometry.js").GeometryLayout} a A + * @param {import("../geom/Geometry.js").GeometryLayout} b B + * @return {import("../geom/Geometry.js").GeometryLayout} minumum layout made by common axes */ const GeometryLayout_min = (a, b) => { if (a === b) { return a; } - if (a === GeometryLayout.XYZM) { + if (a === 'XYZM') { // anything `b` is minimum return b; } - if (b === GeometryLayout.XYZM) { + if (b === 'XYZM') { // anything `a` is minimum return a; } // otherwise, incompatible - return GeometryLayout.XY; + return 'XY'; }; if (geom instanceof SimpleGeometry) { @@ -564,7 +598,7 @@ class WkbWriter { if (geom instanceof GeometryCollection) { const geoms = geom.getGeometriesArray(); - for (let i = 0; i < geoms.length && layout !== GeometryLayout.XY; i++) { + for (let i = 0; i < geoms.length && layout !== 'XY'; i++) { layout = this.findMinimumLayout(geoms[i], layout); } } @@ -652,7 +686,7 @@ class WkbWriter { * @property {boolean} [hex=true] Returns hex string instead of ArrayBuffer for output. This also is used as a hint internally whether it should load contents as text or ArrayBuffer on reading. * @property {boolean} [littleEndian=true] Use littleEndian for output. * @property {boolean} [ewkb=true] Use EWKB format for output. - * @property {import("../geom/GeometryLayout").default} [geometryLayout=null] Use specific coordinate layout for output features (null: auto detect) + * @property {import("../geom/Geometry.js").GeometryLayout} [geometryLayout=null] Use specific coordinate layout for output features (null: auto detect) * @property {number} [nodataZ=0] If the `geometryLayout` doesn't match with geometry to be output, this value is used to fill missing coordinate value of Z. * @property {number} [nodataM=0] If the `geometryLayout` doesn't match with geometry to be output, this value is used to fill missing coordinate value of M. * @property {number|boolean} [srid=true] SRID for output. Specify integer value to enforce the value as a SRID. Specify `true` to extract from `dataProjection`. `false` to suppress the output. This option only takes effect when `ewkb` is `true`. diff --git a/src/ol/format/WKT.js b/src/ol/format/WKT.js index 6d75c8ee37..27587db38a 100644 --- a/src/ol/format/WKT.js +++ b/src/ol/format/WKT.js @@ -3,7 +3,6 @@ */ import Feature from '../Feature.js'; import GeometryCollection from '../geom/GeometryCollection.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import MultiLineString from '../geom/MultiLineString.js'; import MultiPoint from '../geom/MultiPoint.js'; @@ -15,7 +14,7 @@ import {transformGeometryWithOptions} from './Feature.js'; /** * Geometry constructors - * @enum {function (new:import("../geom/Geometry.js").default, Array, import("../geom/GeometryLayout.js").default)} + * @enum {function (new:import("../geom/Geometry.js").default, Array, import("../geom/Geometry.js").GeometryLayout)} */ const GeometryConstructor = { 'POINT': Point, @@ -249,10 +248,10 @@ class Parser { }; /** - * @type {import("../geom/GeometryLayout.js").default} + * @type {import("../geom/Geometry.js").GeometryLayout} * @private */ - this.layout_ = GeometryLayout.XY; + this.layout_ = 'XY'; } /** @@ -296,22 +295,23 @@ class Parser { /** * Try to parse the dimensional info. - * @return {import("../geom/GeometryLayout.js").default} The layout. + * @return {import("../geom/Geometry.js").GeometryLayout} The layout. * @private */ parseGeometryLayout_() { - let layout = GeometryLayout.XY; + /** @type {import("../geom/Geometry.js").GeometryLayout} */ + let layout = 'XY'; const dimToken = this.token_; if (this.isTokenType(TokenType.TEXT)) { const dimInfo = dimToken.value; if (dimInfo === Z) { - layout = GeometryLayout.XYZ; + layout = 'XYZ'; } else if (dimInfo === M) { - layout = GeometryLayout.XYM; + layout = 'XYM'; } else if (dimInfo === ZM) { - layout = GeometryLayout.XYZM; + layout = 'XYZM'; } - if (layout !== GeometryLayout.XY) { + if (layout !== 'XY') { this.consume_(); } } @@ -819,10 +819,10 @@ function encodeMultiPolygonGeometry(geom) { function encodeGeometryLayout(geom) { const layout = geom.getLayout(); let dimInfo = ''; - if (layout === GeometryLayout.XYZ || layout === GeometryLayout.XYZM) { + if (layout === 'XYZ' || layout === 'XYZM') { dimInfo += Z; } - if (layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM) { + if (layout === 'XYM' || layout === 'XYZM') { dimInfo += M; } return dimInfo; diff --git a/src/ol/geom/Circle.js b/src/ol/geom/Circle.js index f0289d4061..4726219e98 100644 --- a/src/ol/geom/Circle.js +++ b/src/ol/geom/Circle.js @@ -18,7 +18,7 @@ class Circle extends SimpleGeometry { * For internal use, flat coordinates in combination with `opt_layout` and no * `opt_radius` are also accepted. * @param {number} [opt_radius] Radius. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. */ constructor(center, opt_radius, opt_layout) { super(); @@ -188,7 +188,7 @@ class Circle extends SimpleGeometry { * number) of the circle. * @param {!import("../coordinate.js").Coordinate} center Center. * @param {number} radius Radius. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCenterAndRadius(center, radius, opt_layout) { diff --git a/src/ol/geom/Geometry.js b/src/ol/geom/Geometry.js index bf13d7976f..cbaa005098 100644 --- a/src/ol/geom/Geometry.js +++ b/src/ol/geom/Geometry.js @@ -18,6 +18,12 @@ import {get as getProjection, getTransform} from '../proj.js'; import {memoizeOne} from '../functions.js'; import {transform2D} from './flat/transform.js'; +/** + * @typedef {'XY' | 'XYZ' | 'XYM' | 'XYZM'} GeometryLayout + * The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z') + * or measure ('M') coordinate is available. + */ + /** * @typedef {'Point' | 'LineString' | 'LinearRing' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'Circle'} Type * The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`, diff --git a/src/ol/geom/GeometryLayout.js b/src/ol/geom/GeometryLayout.js deleted file mode 100644 index b7b563f353..0000000000 --- a/src/ol/geom/GeometryLayout.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @module ol/geom/GeometryLayout - */ - -/** - * The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z') - * or measure ('M') coordinate is available. Supported values are `'XY'`, - * `'XYZ'`, `'XYM'`, `'XYZM'`. - * @enum {string} - */ -export default { - XY: 'XY', - XYZ: 'XYZ', - XYM: 'XYM', - XYZM: 'XYZM', -}; diff --git a/src/ol/geom/LineString.js b/src/ol/geom/LineString.js index 2c1dfc4d8d..b0490e565b 100644 --- a/src/ol/geom/LineString.js +++ b/src/ol/geom/LineString.js @@ -1,7 +1,6 @@ /** * @module ol/geom/LineString */ -import GeometryLayout from './GeometryLayout.js'; import SimpleGeometry from './SimpleGeometry.js'; import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js'; import {closestSquaredDistanceXY} from '../extent.js'; @@ -24,7 +23,7 @@ class LineString extends SimpleGeometry { /** * @param {Array|Array} coordinates Coordinates. * For internal use, flat coordinates in combination with `opt_layout` are also accepted. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. */ constructor(coordinates, opt_layout) { super(); @@ -169,10 +168,7 @@ class LineString extends SimpleGeometry { * @api */ getCoordinateAtM(m, opt_extrapolate) { - if ( - this.layout != GeometryLayout.XYM && - this.layout != GeometryLayout.XYZM - ) { + if (this.layout != 'XYM' && this.layout != 'XYZM') { return null; } const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false; @@ -263,7 +259,7 @@ class LineString extends SimpleGeometry { simplifiedFlatCoordinates, 0 ); - return new LineString(simplifiedFlatCoordinates, GeometryLayout.XY); + return new LineString(simplifiedFlatCoordinates, 'XY'); } /** @@ -294,7 +290,7 @@ class LineString extends SimpleGeometry { /** * Set the coordinates of the linestring. * @param {!Array} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCoordinates(coordinates, opt_layout) { diff --git a/src/ol/geom/LinearRing.js b/src/ol/geom/LinearRing.js index 73c11a105d..2d98ad77c2 100644 --- a/src/ol/geom/LinearRing.js +++ b/src/ol/geom/LinearRing.js @@ -1,7 +1,6 @@ /** * @module ol/geom/LinearRing */ -import GeometryLayout from './GeometryLayout.js'; import SimpleGeometry from './SimpleGeometry.js'; import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js'; import {closestSquaredDistanceXY} from '../extent.js'; @@ -21,7 +20,7 @@ class LinearRing extends SimpleGeometry { /** * @param {Array|Array} coordinates Coordinates. * For internal use, flat coordinates in combination with `opt_layout` are also accepted. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. */ constructor(coordinates, opt_layout) { super(); @@ -143,7 +142,7 @@ class LinearRing extends SimpleGeometry { simplifiedFlatCoordinates, 0 ); - return new LinearRing(simplifiedFlatCoordinates, GeometryLayout.XY); + return new LinearRing(simplifiedFlatCoordinates, 'XY'); } /** @@ -168,7 +167,7 @@ class LinearRing extends SimpleGeometry { /** * Set the coordinates of the linear ring. * @param {!Array} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCoordinates(coordinates, opt_layout) { diff --git a/src/ol/geom/MultiLineString.js b/src/ol/geom/MultiLineString.js index 9f9820a998..7e35b983a7 100644 --- a/src/ol/geom/MultiLineString.js +++ b/src/ol/geom/MultiLineString.js @@ -1,7 +1,6 @@ /** * @module ol/geom/MultiLineString */ -import GeometryLayout from './GeometryLayout.js'; import LineString from './LineString.js'; import SimpleGeometry from './SimpleGeometry.js'; import {arrayMaxSquaredDelta, assignClosestArrayPoint} from './flat/closest.js'; @@ -27,7 +26,7 @@ class MultiLineString extends SimpleGeometry { * @param {Array|LineString>|Array} coordinates * Coordinates or LineString geometries. (For internal use, flat coordinates in * combination with `opt_layout` and `opt_ends` are also accepted.) - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {Array} [opt_ends] Flat coordinate ends for internal use. */ constructor(coordinates, opt_layout, opt_ends) { @@ -173,8 +172,7 @@ class MultiLineString extends SimpleGeometry { */ getCoordinateAtM(m, opt_extrapolate, opt_interpolate) { if ( - (this.layout != GeometryLayout.XYM && - this.layout != GeometryLayout.XYZM) || + (this.layout != 'XYM' && this.layout != 'XYZM') || this.flatCoordinates.length === 0 ) { return null; @@ -298,11 +296,7 @@ class MultiLineString extends SimpleGeometry { 0, simplifiedEnds ); - return new MultiLineString( - simplifiedFlatCoordinates, - GeometryLayout.XY, - simplifiedEnds - ); + return new MultiLineString(simplifiedFlatCoordinates, 'XY', simplifiedEnds); } /** @@ -333,7 +327,7 @@ class MultiLineString extends SimpleGeometry { /** * Set the coordinates of the multilinestring. * @param {!Array>} coordinates Coordinates. - * @param {GeometryLayout} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCoordinates(coordinates, opt_layout) { diff --git a/src/ol/geom/MultiPoint.js b/src/ol/geom/MultiPoint.js index c1a1c0e74c..049058fa4c 100644 --- a/src/ol/geom/MultiPoint.js +++ b/src/ol/geom/MultiPoint.js @@ -19,7 +19,7 @@ class MultiPoint extends SimpleGeometry { /** * @param {Array|Array} coordinates Coordinates. * For internal use, flat coordinates in combination with `opt_layout` are also accepted. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. */ constructor(coordinates, opt_layout) { super(); @@ -182,7 +182,7 @@ class MultiPoint extends SimpleGeometry { /** * Set the coordinates of the multipoint. * @param {!Array} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCoordinates(coordinates, opt_layout) { diff --git a/src/ol/geom/MultiPolygon.js b/src/ol/geom/MultiPolygon.js index 0bf35c1e3e..3f7dcc233d 100644 --- a/src/ol/geom/MultiPolygon.js +++ b/src/ol/geom/MultiPolygon.js @@ -1,7 +1,6 @@ /** * @module ol/geom/MultiPolygon */ -import GeometryLayout from './GeometryLayout.js'; import MultiPoint from './MultiPoint.js'; import Polygon from './Polygon.js'; import SimpleGeometry from './SimpleGeometry.js'; @@ -34,7 +33,7 @@ class MultiPolygon extends SimpleGeometry { /** * @param {Array>|Polygon>|Array} coordinates Coordinates. * For internal use, flat coordinates in combination with `opt_layout` and `opt_endss` are also accepted. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {Array>} [opt_endss] Array of ends for internal use with flat coordinates. */ constructor(coordinates, opt_layout, opt_endss) { @@ -306,10 +305,7 @@ class MultiPolygon extends SimpleGeometry { * @api */ getInteriorPoints() { - return new MultiPoint( - this.getFlatInteriorPoints().slice(), - GeometryLayout.XYM - ); + return new MultiPoint(this.getFlatInteriorPoints().slice(), 'XYM'); } /** @@ -354,11 +350,7 @@ class MultiPolygon extends SimpleGeometry { 0, simplifiedEndss ); - return new MultiPolygon( - simplifiedFlatCoordinates, - GeometryLayout.XY, - simplifiedEndss - ); + return new MultiPolygon(simplifiedFlatCoordinates, 'XY', simplifiedEndss); } /** @@ -450,7 +442,7 @@ class MultiPolygon extends SimpleGeometry { /** * Set the coordinates of the multipolygon. * @param {!Array>>} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCoordinates(coordinates, opt_layout) { diff --git a/src/ol/geom/Point.js b/src/ol/geom/Point.js index 7c8ac4dd3a..9466eb9c62 100644 --- a/src/ol/geom/Point.js +++ b/src/ol/geom/Point.js @@ -15,7 +15,7 @@ import {squaredDistance as squaredDx} from '../math.js'; class Point extends SimpleGeometry { /** * @param {import("../coordinate.js").Coordinate} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. */ constructor(coordinates, opt_layout) { super(); @@ -99,7 +99,7 @@ class Point extends SimpleGeometry { /** * @param {!Array<*>} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCoordinates(coordinates, opt_layout) { diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 5dc984e9ed..b67f5ebed0 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -1,7 +1,6 @@ /** * @module ol/geom/Polygon */ -import GeometryLayout from './GeometryLayout.js'; import LinearRing from './LinearRing.js'; import Point from './Point.js'; import SimpleGeometry from './SimpleGeometry.js'; @@ -34,7 +33,7 @@ class Polygon extends SimpleGeometry { * an array of vertices' coordinates where the first coordinate and the last are * equivalent. (For internal use, flat coordinates in combination with * `opt_layout` and `opt_ends` are also accepted.) - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {Array} [opt_ends] Ends (for internal use with flat coordinates). */ constructor(coordinates, opt_layout, opt_ends) { @@ -253,7 +252,7 @@ class Polygon extends SimpleGeometry { * @api */ getInteriorPoint() { - return new Point(this.getFlatInteriorPoint(), GeometryLayout.XYM); + return new Point(this.getFlatInteriorPoint(), 'XYM'); } /** @@ -353,11 +352,7 @@ class Polygon extends SimpleGeometry { 0, simplifiedEnds ); - return new Polygon( - simplifiedFlatCoordinates, - GeometryLayout.XY, - simplifiedEnds - ); + return new Polygon(simplifiedFlatCoordinates, 'XY', simplifiedEnds); } /** @@ -388,7 +383,7 @@ class Polygon extends SimpleGeometry { /** * Set the coordinates of the polygon. * @param {!Array>} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @api */ setCoordinates(coordinates, opt_layout) { @@ -433,9 +428,7 @@ export function circular(center, radius, opt_n, opt_sphereRadius) { ); } flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]); - return new Polygon(flatCoordinates, GeometryLayout.XY, [ - flatCoordinates.length, - ]); + return new Polygon(flatCoordinates, 'XY', [flatCoordinates.length]); } /** @@ -461,9 +454,7 @@ export function fromExtent(extent) { minX, minY, ]; - return new Polygon(flatCoordinates, GeometryLayout.XY, [ - flatCoordinates.length, - ]); + return new Polygon(flatCoordinates, 'XY', [flatCoordinates.length]); } /** diff --git a/src/ol/geom/SimpleGeometry.js b/src/ol/geom/SimpleGeometry.js index b64d10facd..4cec890bf8 100644 --- a/src/ol/geom/SimpleGeometry.js +++ b/src/ol/geom/SimpleGeometry.js @@ -2,7 +2,6 @@ * @module ol/geom/SimpleGeometry */ import Geometry from './Geometry.js'; -import GeometryLayout from './GeometryLayout.js'; import {abstract} from '../util.js'; import {createOrUpdateFromFlatCoordinates, getCenter} from '../extent.js'; import {rotate, scale, transform2D, translate} from './flat/transform.js'; @@ -21,9 +20,9 @@ class SimpleGeometry extends Geometry { /** * @protected - * @type {import("./GeometryLayout.js").default} + * @type {import("./Geometry.js").GeometryLayout} */ - this.layout = GeometryLayout.XY; + this.layout = 'XY'; /** * @protected @@ -89,8 +88,8 @@ class SimpleGeometry extends Geometry { } /** - * Return the {@link module:ol/geom/GeometryLayout layout} of the geometry. - * @return {import("./GeometryLayout.js").default} Layout. + * Return the {@link import("./Geometry.js").GeometryLayout layout} of the geometry. + * @return {import("./Geometry.js").GeometryLayout} Layout. * @api */ getLayout() { @@ -151,7 +150,7 @@ class SimpleGeometry extends Geometry { } /** - * @param {import("./GeometryLayout.js").default} layout Layout. + * @param {import("./Geometry.js").GeometryLayout} layout Layout. * @param {Array} flatCoordinates Flat coordinates. */ setFlatCoordinates(layout, flatCoordinates) { @@ -163,14 +162,14 @@ class SimpleGeometry extends Geometry { /** * @abstract * @param {!Array<*>} coordinates Coordinates. - * @param {import("./GeometryLayout.js").default} [opt_layout] Layout. + * @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. */ setCoordinates(coordinates, opt_layout) { abstract(); } /** - * @param {import("./GeometryLayout.js").default|undefined} layout Layout. + * @param {import("./Geometry.js").GeometryLayout|undefined} layout Layout. * @param {Array<*>} coordinates Coordinates. * @param {number} nesting Nesting. * @protected @@ -183,7 +182,7 @@ class SimpleGeometry extends Geometry { } else { for (let i = 0; i < nesting; ++i) { if (coordinates.length === 0) { - this.layout = GeometryLayout.XY; + this.layout = 'XY'; this.stride = 2; return; } else { @@ -299,31 +298,31 @@ class SimpleGeometry extends Geometry { /** * @param {number} stride Stride. - * @return {import("./GeometryLayout.js").default} layout Layout. + * @return {import("./Geometry.js").GeometryLayout} layout Layout. */ function getLayoutForStride(stride) { let layout; if (stride == 2) { - layout = GeometryLayout.XY; + layout = 'XY'; } else if (stride == 3) { - layout = GeometryLayout.XYZ; + layout = 'XYZ'; } else if (stride == 4) { - layout = GeometryLayout.XYZM; + layout = 'XYZM'; } - return /** @type {import("./GeometryLayout.js").default} */ (layout); + return /** @type {import("./Geometry.js").GeometryLayout} */ (layout); } /** - * @param {import("./GeometryLayout.js").default} layout Layout. + * @param {import("./Geometry.js").GeometryLayout} layout Layout. * @return {number} Stride. */ export function getStrideForLayout(layout) { let stride; - if (layout == GeometryLayout.XY) { + if (layout == 'XY') { stride = 2; - } else if (layout == GeometryLayout.XYZ || layout == GeometryLayout.XYM) { + } else if (layout == 'XYZ' || layout == 'XYM') { stride = 3; - } else if (layout == GeometryLayout.XYZM) { + } else if (layout == 'XYZM') { stride = 4; } return /** @type {number} */ (stride); diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 2560de2d85..5edd39a0a5 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -5,7 +5,6 @@ import Circle from '../geom/Circle.js'; import Event from '../events/Event.js'; import EventType from '../events/EventType.js'; import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import InteractionProperty from './Property.js'; import LineString from '../geom/LineString.js'; import MapBrowserEvent from '../MapBrowserEvent.js'; @@ -83,7 +82,7 @@ import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js'; * Shift key activates freehand drawing. * @property {boolean} [wrapX=false] Wrap the world horizontally on the sketch * overlay. - * @property {GeometryLayout} [geometryLayout='XY'] Layout of the + * @property {import("../geom/Geometry.js").GeometryLayout} [geometryLayout='XY'] Layout of the * feature geometries created by the draw interaction. */ @@ -118,16 +117,10 @@ import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js'; */ /** + * @typedef {'Point' | 'LineString' | 'Polygon' | 'Circle'} Mode * Draw mode. This collapses multi-part geometry types with their single-part * cousins. - * @enum {string} */ -const Mode = { - POINT: 'Point', - LINE_STRING: 'LineString', - POLYGON: 'Polygon', - CIRCLE: 'Circle', -}; /** * @enum {string} @@ -312,7 +305,7 @@ class Draw extends PointerInteraction { */ this.minPoints_ = options.minPoints ? options.minPoints - : this.mode_ === Mode.POLYGON + : this.mode_ === 'Polygon' ? 3 : 2; @@ -323,7 +316,7 @@ class Draw extends PointerInteraction { * @private */ this.maxPoints_ = - this.mode_ === Mode.CIRCLE + this.mode_ === 'Circle' ? 2 : options.maxPoints ? options.maxPoints @@ -340,16 +333,16 @@ class Draw extends PointerInteraction { /** * @private - * @type {import("../geom/GeometryLayout").default} + * @type {import("../geom/Geometry.js").GeometryLayout} */ this.geometryLayout_ = options.geometryLayout ? options.geometryLayout - : GeometryLayout.XY; + : 'XY'; let geometryFunction = options.geometryFunction; if (!geometryFunction) { const mode = this.mode_; - if (mode === Mode.CIRCLE) { + if (mode === 'Circle') { /** * @param {!LineCoordType} coordinates The coordinates. * @param {import("../geom/SimpleGeometry.js").default|undefined} geometry Optional geometry. @@ -378,11 +371,11 @@ class Draw extends PointerInteraction { }; } else { let Constructor; - if (mode === Mode.POINT) { + if (mode === 'Point') { Constructor = Point; - } else if (mode === Mode.LINE_STRING) { + } else if (mode === 'LineString') { Constructor = LineString; - } else if (mode === Mode.POLYGON) { + } else if (mode === 'Polygon') { Constructor = Polygon; } /** @@ -393,7 +386,7 @@ class Draw extends PointerInteraction { */ geometryFunction = function (coordinates, geometry, projection) { if (geometry) { - if (mode === Mode.POLYGON) { + if (mode === 'Polygon') { if (coordinates[0].length) { // Add a closing coordinate to match the first geometry.setCoordinates( @@ -555,8 +548,7 @@ class Draw extends PointerInteraction { // Avoid context menu for long taps when drawing on mobile event.originalEvent.preventDefault(); } - this.freehand_ = - this.mode_ !== Mode.POINT && this.freehandCondition_(event); + this.freehand_ = this.mode_ !== 'Point' && this.freehandCondition_(event); let move = event.type === MapBrowserEventType.POINTERMOVE; let pass = true; if ( @@ -674,7 +666,7 @@ class Draw extends PointerInteraction { this.finishDrawing(); } else if ( !this.freehand_ && - (!startingToDraw || this.mode_ === Mode.POINT) + (!startingToDraw || this.mode_ === 'Point') ) { if (this.atFinish_(event.pixel)) { if (this.finishCondition_(event)) { @@ -740,13 +732,13 @@ class Draw extends PointerInteraction { let potentiallyDone = false; let potentiallyFinishCoordinates = [this.finishCoordinate_]; const mode = this.mode_; - if (mode === Mode.POINT) { + if (mode === 'Point') { at = true; - } else if (mode === Mode.CIRCLE) { + } else if (mode === 'Circle') { at = this.sketchCoords_.length === 2; - } else if (mode === Mode.LINE_STRING) { + } else if (mode === 'LineString') { potentiallyDone = this.sketchCoords_.length > this.minPoints_; - } else if (mode === Mode.POLYGON) { + } else if (mode === 'Polygon') { const sketchCoords = /** @type {PolyCoordType} */ (this.sketchCoords_); potentiallyDone = sketchCoords[0].length > this.minPoints_; potentiallyFinishCoordinates = [ @@ -824,9 +816,9 @@ class Draw extends PointerInteraction { start.push(0); } this.finishCoordinate_ = start; - if (this.mode_ === Mode.POINT) { + if (this.mode_ === 'Point') { this.sketchCoords_ = start.slice(); - } else if (this.mode_ === Mode.POLYGON) { + } else if (this.mode_ === 'Polygon') { this.sketchCoords_ = [[start.slice(), start.slice()]]; this.sketchLineCoords_ = this.sketchCoords_[0]; } else { @@ -865,9 +857,9 @@ class Draw extends PointerInteraction { while (coordinate.length < stride) { coordinate.push(0); } - if (this.mode_ === Mode.POINT) { + if (this.mode_ === 'Point') { last = this.sketchCoords_; - } else if (this.mode_ === Mode.POLYGON) { + } else if (this.mode_ === 'Polygon') { coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0]; last = coordinates[coordinates.length - 1]; if (this.atFinish_(map.getPixelFromCoordinate(coordinate))) { @@ -889,7 +881,7 @@ class Draw extends PointerInteraction { const sketchPointGeom = this.sketchPoint_.getGeometry(); sketchPointGeom.setCoordinates(coordinate); } - if (geometry.getType() === 'Polygon' && this.mode_ !== Mode.POLYGON) { + if (geometry.getType() === 'Polygon' && this.mode_ !== 'Polygon') { this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry)); } else if (this.sketchLineCoords_) { const sketchLineGeom = this.sketchLine_.getGeometry(); @@ -909,7 +901,7 @@ class Draw extends PointerInteraction { let done; let coordinates; const mode = this.mode_; - if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) { + if (mode === 'LineString' || mode === 'Circle') { this.finishCoordinate_ = coordinate.slice(); coordinates = /** @type {LineCoordType} */ (this.sketchCoords_); if (coordinates.length >= this.maxPoints_) { @@ -921,7 +913,7 @@ class Draw extends PointerInteraction { } coordinates.push(coordinate.slice()); this.geometryFunction_(coordinates, geometry, projection); - } else if (mode === Mode.POLYGON) { + } else if (mode === 'Polygon') { coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0]; if (coordinates.length >= this.maxPoints_) { if (this.freehand_) { @@ -956,7 +948,7 @@ class Draw extends PointerInteraction { const projection = this.getMap().getView().getProjection(); let coordinates; const mode = this.mode_; - if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) { + if (mode === 'LineString' || mode === 'Circle') { coordinates = /** @type {LineCoordType} */ (this.sketchCoords_); coordinates.splice(-2, 1); if (coordinates.length >= 2) { @@ -969,7 +961,7 @@ class Draw extends PointerInteraction { if (geometry.getType() === 'Polygon' && this.sketchLine_) { this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry)); } - } else if (mode === Mode.POLYGON) { + } else if (mode === 'Polygon') { coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0]; coordinates.splice(-2, 1); const sketchLineGeom = this.sketchLine_.getGeometry(); @@ -1003,11 +995,11 @@ class Draw extends PointerInteraction { let coordinates = this.sketchCoords_; const geometry = sketchFeature.getGeometry(); const projection = this.getMap().getView().getProjection(); - if (this.mode_ === Mode.LINE_STRING) { + if (this.mode_ === 'LineString') { // remove the redundant last point coordinates.pop(); this.geometryFunction_(coordinates, geometry, projection); - } else if (this.mode_ === Mode.POLYGON) { + } else if (this.mode_ === 'Polygon') { // remove the redundant last point in ring /** @type {PolyCoordType} */ (coordinates)[0].pop(); this.geometryFunction_(coordinates, geometry, projection); @@ -1084,9 +1076,9 @@ class Draw extends PointerInteraction { } /** @type {LineCoordType} */ let sketchCoords; - if (mode === Mode.LINE_STRING || mode === Mode.CIRCLE) { + if (mode === 'LineString' || mode === 'Circle') { sketchCoords = /** @type {LineCoordType} */ (this.sketchCoords_); - } else if (mode === Mode.POLYGON) { + } else if (mode === 'Polygon') { sketchCoords = this.sketchCoords_ && this.sketchCoords_.length ? /** @type {PolyCoordType} */ (this.sketchCoords_)[0] @@ -1277,15 +1269,15 @@ function getMode(type) { switch (type) { case 'Point': case 'MultiPoint': - return Mode.POINT; + return 'Point'; case 'LineString': case 'MultiLineString': - return Mode.LINE_STRING; + return 'LineString'; case 'Polygon': case 'MultiPolygon': - return Mode.POLYGON; + return 'Polygon'; case 'Circle': - return Mode.CIRCLE; + return 'Circle'; default: throw new Error('Invalid type: ' + type); } diff --git a/src/ol/layer/Graticule.js b/src/ol/layer/Graticule.js index d22c518511..03a99d3847 100644 --- a/src/ol/layer/Graticule.js +++ b/src/ol/layer/Graticule.js @@ -5,7 +5,6 @@ import Collection from '../Collection.js'; import EventType from '../render/EventType.js'; import Feature from '../Feature.js'; import Fill from '../style/Fill.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import LineString from '../geom/LineString.js'; import Point from '../geom/Point.js'; import Stroke from '../style/Stroke.js'; @@ -1037,10 +1036,10 @@ class Graticule extends VectorLayer { ); let lineString = this.meridians_[index]; if (!lineString) { - lineString = new LineString(flatCoordinates, GeometryLayout.XY); + lineString = new LineString(flatCoordinates, 'XY'); this.meridians_[index] = lineString; } else { - lineString.setFlatCoordinates(GeometryLayout.XY, flatCoordinates); + lineString.setFlatCoordinates('XY', flatCoordinates); lineString.changed(); } return lineString; @@ -1107,9 +1106,9 @@ class Graticule extends VectorLayer { ); let lineString = this.parallels_[index]; if (!lineString) { - lineString = new LineString(flatCoordinates, GeometryLayout.XY); + lineString = new LineString(flatCoordinates, 'XY'); } else { - lineString.setFlatCoordinates(GeometryLayout.XY, flatCoordinates); + lineString.setFlatCoordinates('XY', flatCoordinates); lineString.changed(); } return lineString; diff --git a/src/ol/render/Feature.js b/src/ol/render/Feature.js index 9a6f9d2e7c..d9458e71df 100644 --- a/src/ol/render/Feature.js +++ b/src/ol/render/Feature.js @@ -2,7 +2,6 @@ * @module ol/render/Feature */ import Feature from '../Feature.js'; -import GeometryLayout from '../geom/GeometryLayout.js'; import { LineString, MultiLineString, @@ -350,19 +349,13 @@ export function toGeometry(renderFeature) { case 'Point': return new Point(renderFeature.getFlatCoordinates()); case 'MultiPoint': - return new MultiPoint( - renderFeature.getFlatCoordinates(), - GeometryLayout.XY - ); + return new MultiPoint(renderFeature.getFlatCoordinates(), 'XY'); case 'LineString': - return new LineString( - renderFeature.getFlatCoordinates(), - GeometryLayout.XY - ); + return new LineString(renderFeature.getFlatCoordinates(), 'XY'); case 'MultiLineString': return new MultiLineString( renderFeature.getFlatCoordinates(), - GeometryLayout.XY, + 'XY', /** @type {Array} */ (renderFeature.getEnds()) ); case 'Polygon': @@ -370,8 +363,8 @@ export function toGeometry(renderFeature) { const ends = /** @type {Array} */ (renderFeature.getEnds()); const endss = inflateEnds(flatCoordinates, ends); return endss.length > 1 - ? new MultiPolygon(flatCoordinates, GeometryLayout.XY, endss) - : new Polygon(flatCoordinates, GeometryLayout.XY, ends); + ? new MultiPolygon(flatCoordinates, 'XY', endss) + : new Polygon(flatCoordinates, 'XY', ends); default: throw new Error('Invalid geometry type:' + geometryType); } diff --git a/src/ol/render/canvas.js b/src/ol/render/canvas.js index fd393d5cd6..644158097d 100644 --- a/src/ol/render/canvas.js +++ b/src/ol/render/canvas.js @@ -61,7 +61,7 @@ import {getFontParameters} from '../css.js'; * @property {string} [textAlign] TextAlign. * @property {string} [justify] Justify. * @property {string} textBaseline TextBaseline. - * @property {string} [placement] Placement. + * @property {import('../style/Text.js').TextPlacement} [placement] Placement. * @property {number} [maxAngle] MaxAngle. * @property {boolean} [overflow] Overflow. * @property {import("../style/Fill.js").default} [backgroundFill] BackgroundFill. diff --git a/src/ol/render/canvas/TextBuilder.js b/src/ol/render/canvas/TextBuilder.js index df9ec4218d..a8eab29930 100644 --- a/src/ol/render/canvas/TextBuilder.js +++ b/src/ol/render/canvas/TextBuilder.js @@ -3,7 +3,6 @@ */ import CanvasBuilder from './Builder.js'; import CanvasInstruction from './Instruction.js'; -import TextPlacement from '../../style/TextPlacement.js'; import {asColorLike} from '../../colorlike.js'; import { defaultFillStyle, @@ -177,7 +176,7 @@ class CanvasTextBuilder extends CanvasBuilder { let stride = geometry.getStride(); if ( - textState.placement === TextPlacement.LINE && + textState.placement === 'line' && (geometryType == 'LineString' || geometryType == 'MultiLineString' || geometryType == 'Polygon' || diff --git a/src/ol/render/canvas/hitdetect.js b/src/ol/render/canvas/hitdetect.js index 8758d58142..37e16c23fb 100644 --- a/src/ol/render/canvas/hitdetect.js +++ b/src/ol/render/canvas/hitdetect.js @@ -3,7 +3,6 @@ */ import CanvasImmediateRenderer from './Immediate.js'; -import IconAnchorUnits from '../../style/IconAnchorUnits.js'; import {Icon} from '../../style.js'; import {clamp} from '../../math.js'; import {createCanvasContext2D} from '../../dom.js'; @@ -104,8 +103,8 @@ export function createHitDetectionImageData( img: img, imgSize: imgSize, anchor: image.getAnchor(), - anchorXUnits: IconAnchorUnits.PIXELS, - anchorYUnits: IconAnchorUnits.PIXELS, + anchorXUnits: 'pixels', + anchorYUnits: 'pixels', offset: image.getOrigin(), opacity: 1, size: image.getSize(), diff --git a/src/ol/source/Zoomify.js b/src/ol/source/Zoomify.js index 9e8e571b1c..d3212abbe2 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -14,12 +14,8 @@ import {getCenter} from '../extent.js'; import {toSize} from '../size.js'; /** - * @enum {string} + * @typedef {'default' | 'truncated'} TierSizeCalculation */ -const TierSizeCalculation = { - DEFAULT: 'default', - TRUNCATED: 'truncated', -}; export class CustomTile extends ImageTile { /** @@ -105,7 +101,7 @@ export class CustomTile extends ImageTile { * `http://my.zoomify.info?FIF=IMAGE.TIF&JTL={z},{tileIndex}`. * A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be * used instead of defining each one separately in the `urls` option. - * @property {string} [tierSizeCalculation] Tier size calculation method: `default` or `truncated`. + * @property {TierSizeCalculation} [tierSizeCalculation] Tier size calculation method: `default` or `truncated`. * @property {import("../size.js").Size} size Size. * @property {import("../extent.js").Extent} [extent] Extent for the TileGrid that is created. * Default sets the TileGrid in the @@ -143,7 +139,7 @@ class Zoomify extends TileImage { const tierSizeCalculation = options.tierSizeCalculation !== undefined ? options.tierSizeCalculation - : TierSizeCalculation.DEFAULT; + : 'default'; const tilePixelRatio = options.tilePixelRatio || 1; const imageWidth = size[0]; @@ -153,7 +149,7 @@ class Zoomify extends TileImage { let tileSizeForTierSizeCalculation = tileSize * tilePixelRatio; switch (tierSizeCalculation) { - case TierSizeCalculation.DEFAULT: + case 'default': while ( imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation @@ -165,7 +161,7 @@ class Zoomify extends TileImage { tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation; } break; - case TierSizeCalculation.TRUNCATED: + case 'truncated': let width = imageWidth; let height = imageHeight; while ( diff --git a/src/ol/style/Icon.js b/src/ol/style/Icon.js index ab63f15867..414c8cd4a5 100644 --- a/src/ol/style/Icon.js +++ b/src/ol/style/Icon.js @@ -2,8 +2,6 @@ * @module ol/style/Icon */ import EventType from '../events/EventType.js'; -import IconAnchorUnits from './IconAnchorUnits.js'; -import IconOrigin from './IconOrigin.js'; import ImageState from '../ImageState.js'; import ImageStyle from './Image.js'; import {asArray} from '../color.js'; @@ -11,15 +9,25 @@ import {assert} from '../asserts.js'; import {get as getIconImage} from './IconImage.js'; import {getUid} from '../util.js'; +/** + * @typedef {'fraction' | 'pixels'} IconAnchorUnits + * Anchor unit can be either a fraction of the icon size or in pixels. + */ + +/** + * @typedef {'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'} IconOrigin + * Icon origin. One of 'bottom-left', 'bottom-right', 'top-left', 'top-right'. + */ + /** * @typedef {Object} Options * @property {Array} [anchor=[0.5, 0.5]] Anchor. Default value is the icon center. - * @property {import("./IconOrigin.js").default} [anchorOrigin='top-left'] Origin of the anchor: `bottom-left`, `bottom-right`, + * @property {IconOrigin} [anchorOrigin='top-left'] Origin of the anchor: `bottom-left`, `bottom-right`, * `top-left` or `top-right`. - * @property {import("./IconAnchorUnits.js").default} [anchorXUnits='fraction'] Units in which the anchor x value is + * @property {IconAnchorUnits} [anchorXUnits='fraction'] Units in which the anchor x value is * specified. A value of `'fraction'` indicates the x value is a fraction of the icon. A value of `'pixels'` indicates * the x value in pixels. - * @property {import("./IconAnchorUnits.js").default} [anchorYUnits='fraction'] Units in which the anchor y value is + * @property {IconAnchorUnits} [anchorYUnits='fraction'] Units in which the anchor y value is * specified. A value of `'fraction'` indicates the y value is a fraction of the icon. A value of `'pixels'` indicates * the y value in pixels. * @property {import("../color.js").Color|string} [color] Color to tint the icon. If not specified, @@ -33,7 +41,7 @@ import {getUid} from '../util.js'; * @property {Array} [offset=[0, 0]] Offset, which, together with the size and the offset origin, define the * sub-rectangle to use from the original icon image. * @property {Array} [displacement=[0,0]] Displacement of the icon. - * @property {import("./IconOrigin.js").default} [offsetOrigin='top-left'] Origin of the offset: `bottom-left`, `bottom-right`, + * @property {IconOrigin} [offsetOrigin='top-left'] Origin of the offset: `bottom-left`, `bottom-right`, * `top-left` or `top-right`. * @property {number} [opacity=1] Opacity of the icon. * @property {number|import("../size.js").Size} [scale=1] Scale. @@ -104,30 +112,24 @@ class Icon extends ImageStyle { /** * @private - * @type {import("./IconOrigin.js").default} + * @type {IconOrigin} */ this.anchorOrigin_ = - options.anchorOrigin !== undefined - ? options.anchorOrigin - : IconOrigin.TOP_LEFT; + options.anchorOrigin !== undefined ? options.anchorOrigin : 'top-left'; /** * @private - * @type {import("./IconAnchorUnits.js").default} + * @type {IconAnchorUnits} */ this.anchorXUnits_ = - options.anchorXUnits !== undefined - ? options.anchorXUnits - : IconAnchorUnits.FRACTION; + options.anchorXUnits !== undefined ? options.anchorXUnits : 'fraction'; /** * @private - * @type {import("./IconAnchorUnits.js").default} + * @type {IconAnchorUnits} */ this.anchorYUnits_ = - options.anchorYUnits !== undefined - ? options.anchorYUnits - : IconAnchorUnits.FRACTION; + options.anchorYUnits !== undefined ? options.anchorYUnits : 'fraction'; /** * @private @@ -192,12 +194,10 @@ class Icon extends ImageStyle { this.offset_ = options.offset !== undefined ? options.offset : [0, 0]; /** * @private - * @type {import("./IconOrigin.js").default} + * @type {IconOrigin} */ this.offsetOrigin_ = - options.offsetOrigin !== undefined - ? options.offsetOrigin - : IconOrigin.TOP_LEFT; + options.offsetOrigin !== undefined ? options.offsetOrigin : 'top-left'; /** * @private @@ -255,22 +255,22 @@ class Icon extends ImageStyle { anchor = this.anchor_; const size = this.getSize(); if ( - this.anchorXUnits_ == IconAnchorUnits.FRACTION || - this.anchorYUnits_ == IconAnchorUnits.FRACTION + this.anchorXUnits_ == 'fraction' || + this.anchorYUnits_ == 'fraction' ) { if (!size) { return null; } anchor = this.anchor_.slice(); - if (this.anchorXUnits_ == IconAnchorUnits.FRACTION) { + if (this.anchorXUnits_ == 'fraction') { anchor[0] *= size[0]; } - if (this.anchorYUnits_ == IconAnchorUnits.FRACTION) { + if (this.anchorYUnits_ == 'fraction') { anchor[1] *= size[1]; } } - if (this.anchorOrigin_ != IconOrigin.TOP_LEFT) { + if (this.anchorOrigin_ != 'top-left') { if (!size) { return null; } @@ -278,14 +278,14 @@ class Icon extends ImageStyle { anchor = this.anchor_.slice(); } if ( - this.anchorOrigin_ == IconOrigin.TOP_RIGHT || - this.anchorOrigin_ == IconOrigin.BOTTOM_RIGHT + this.anchorOrigin_ == 'top-right' || + this.anchorOrigin_ == 'bottom-right' ) { anchor[0] = -anchor[0] + size[0]; } if ( - this.anchorOrigin_ == IconOrigin.BOTTOM_LEFT || - this.anchorOrigin_ == IconOrigin.BOTTOM_RIGHT + this.anchorOrigin_ == 'bottom-left' || + this.anchorOrigin_ == 'bottom-right' ) { anchor[1] = -anchor[1] + size[1]; } @@ -369,7 +369,7 @@ class Icon extends ImageStyle { } let offset = this.offset_; - if (this.offsetOrigin_ != IconOrigin.TOP_LEFT) { + if (this.offsetOrigin_ != 'top-left') { const size = this.getSize(); const iconImageSize = this.iconImage_.getSize(); if (!size || !iconImageSize) { @@ -377,14 +377,14 @@ class Icon extends ImageStyle { } offset = offset.slice(); if ( - this.offsetOrigin_ == IconOrigin.TOP_RIGHT || - this.offsetOrigin_ == IconOrigin.BOTTOM_RIGHT + this.offsetOrigin_ == 'top-right' || + this.offsetOrigin_ == 'bottom-right' ) { offset[0] = iconImageSize[0] - size[0] - offset[0]; } if ( - this.offsetOrigin_ == IconOrigin.BOTTOM_LEFT || - this.offsetOrigin_ == IconOrigin.BOTTOM_RIGHT + this.offsetOrigin_ == 'bottom-left' || + this.offsetOrigin_ == 'bottom-right' ) { offset[1] = iconImageSize[1] - size[1] - offset[1]; } diff --git a/src/ol/style/IconAnchorUnits.js b/src/ol/style/IconAnchorUnits.js deleted file mode 100644 index 22e77eb27f..0000000000 --- a/src/ol/style/IconAnchorUnits.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @module ol/style/IconAnchorUnits - */ - -/** - * Icon anchor units. One of 'fraction', 'pixels'. - * @enum {string} - */ -export default { - /** - * Anchor is a fraction - * @api - */ - FRACTION: 'fraction', - /** - * Anchor is in pixels - * @api - */ - PIXELS: 'pixels', -}; diff --git a/src/ol/style/IconOrigin.js b/src/ol/style/IconOrigin.js deleted file mode 100644 index a1bd31b1c1..0000000000 --- a/src/ol/style/IconOrigin.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @module ol/style/IconOrigin - */ - -/** - * Icon origin. One of 'bottom-left', 'bottom-right', 'top-left', 'top-right'. - * @enum {string} - */ -export default { - /** - * Origin is at bottom left - * @api - */ - BOTTOM_LEFT: 'bottom-left', - /** - * Origin is at bottom right - * @api - */ - BOTTOM_RIGHT: 'bottom-right', - /** - * Origin is at top left - * @api - */ - TOP_LEFT: 'top-left', - /** - * Origin is at top right - * @api - */ - TOP_RIGHT: 'top-right', -}; diff --git a/src/ol/style/Text.js b/src/ol/style/Text.js index 1337f88187..3bc20c6545 100644 --- a/src/ol/style/Text.js +++ b/src/ol/style/Text.js @@ -2,9 +2,16 @@ * @module ol/style/Text */ import Fill from './Fill.js'; -import TextPlacement from './TextPlacement.js'; import {toSize} from '../size.js'; +/** + * @typedef {'point' | 'line'} TextPlacement + * Default text placement is `'point'`. Note that + * `'line'` requires the underlying geometry to be a {@link module:ol/geom/LineString~LineString}, + * {@link module:ol/geom/Polygon~Polygon}, {@link module:ol/geom/MultiLineString~MultiLineString} or + * {@link module:ol/geom/MultiPolygon~MultiPolygon}. + */ + /** * The default fill color to use if no fill was set at construction time; a * blackish `#333`. @@ -23,7 +30,7 @@ const DEFAULT_FILL_COLOR = '#333'; * @property {number} [offsetY=0] Vertical text offset in pixels. A positive will shift the text down. * @property {boolean} [overflow=false] For polygon labels or when `placement` is set to `'line'`, allow text to exceed * the width of the polygon at the label position or the length of the path that it follows. - * @property {import("./TextPlacement.js").default|string} [placement='point'] Text placement. + * @property {TextPlacement} [placement='point'] Text placement. * @property {number|import("../size.js").Size} [scale] Scale. * @property {boolean} [rotateWithView=false] Whether to rotate the text with the view. * @property {number} [rotation=0] Rotation in radians (positive rotation clockwise). @@ -135,10 +142,10 @@ class Text { /** * @private - * @type {import("./TextPlacement.js").default|string} + * @type {TextPlacement} */ this.placement_ = - options.placement !== undefined ? options.placement : TextPlacement.POINT; + options.placement !== undefined ? options.placement : 'point'; /** * @private @@ -249,7 +256,7 @@ class Text { /** * Get the label placement. - * @return {import("./TextPlacement.js").default|string} Text placement. + * @return {TextPlacement} Text placement. * @api */ getPlacement() { @@ -443,7 +450,7 @@ class Text { /** * Set the text placement. * - * @param {import("./TextPlacement.js").default|string} placement Placement. + * @param {TextPlacement} placement Placement. * @api */ setPlacement(placement) { diff --git a/src/ol/style/TextPlacement.js b/src/ol/style/TextPlacement.js deleted file mode 100644 index fb05299494..0000000000 --- a/src/ol/style/TextPlacement.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @module ol/style/TextPlacement - */ - -/** - * Text placement. One of `'point'`, `'line'`. Default is `'point'`. Note that - * `'line'` requires the underlying geometry to be a {@link module:ol/geom/LineString~LineString}, - * {@link module:ol/geom/Polygon~Polygon}, {@link module:ol/geom/MultiLineString~MultiLineString} or - * {@link module:ol/geom/MultiPolygon~MultiPolygon}. - * @enum {string} - */ -export default { - POINT: 'point', - LINE: 'line', -}; diff --git a/test/browser/spec/ol/format/kml.test.js b/test/browser/spec/ol/format/kml.test.js index 53035a9ad8..79b0eddb19 100644 --- a/test/browser/spec/ol/format/kml.test.js +++ b/test/browser/spec/ol/format/kml.test.js @@ -4,8 +4,6 @@ import Fill from '../../../../../src/ol/style/Fill.js'; import GeoJSON from '../../../../../src/ol/format/GeoJSON.js'; import GeometryCollection from '../../../../../src/ol/geom/GeometryCollection.js'; import Icon from '../../../../../src/ol/style/Icon.js'; -import IconAnchorUnits from '../../../../../src/ol/style/IconAnchorUnits.js'; -import IconOrigin from '../../../../../src/ol/style/IconOrigin.js'; import ImageState from '../../../../../src/ol/ImageState.js'; import KML, { getDefaultFillStyle, @@ -2430,25 +2428,25 @@ describe('ol.format.KML', function () { if (f.getId() == 1) { expect(imageStyle.anchor_[0]).to.be(0.5); expect(imageStyle.anchor_[1]).to.be(0.5); - expect(imageStyle.anchorOrigin_).to.be(IconOrigin.BOTTOM_LEFT); - expect(imageStyle.anchorXUnits_).to.be(IconAnchorUnits.FRACTION); - expect(imageStyle.anchorYUnits_).to.be(IconAnchorUnits.FRACTION); + expect(imageStyle.anchorOrigin_).to.be('bottom-left'); + expect(imageStyle.anchorXUnits_).to.be('fraction'); + expect(imageStyle.anchorYUnits_).to.be('fraction'); } else { expect(imageStyle.anchor_[0]).to.be(5); expect(imageStyle.anchor_[1]).to.be(5); - expect(imageStyle.anchorXUnits_).to.be(IconAnchorUnits.PIXELS); - expect(imageStyle.anchorYUnits_).to.be(IconAnchorUnits.PIXELS); + expect(imageStyle.anchorXUnits_).to.be('pixels'); + expect(imageStyle.anchorYUnits_).to.be('pixels'); if (f.getId() == 2) { - expect(imageStyle.anchorOrigin_).to.be(IconOrigin.BOTTOM_LEFT); + expect(imageStyle.anchorOrigin_).to.be('bottom-left'); } if (f.getId() == 3) { - expect(imageStyle.anchorOrigin_).to.be(IconOrigin.BOTTOM_RIGHT); + expect(imageStyle.anchorOrigin_).to.be('bottom-right'); } if (f.getId() == 4) { - expect(imageStyle.anchorOrigin_).to.be(IconOrigin.TOP_LEFT); + expect(imageStyle.anchorOrigin_).to.be('top-left'); } if (f.getId() == 5) { - expect(imageStyle.anchorOrigin_).to.be(IconOrigin.TOP_RIGHT); + expect(imageStyle.anchorOrigin_).to.be('top-right'); } } expect(imageStyle.getRotation()).to.eql(0); diff --git a/test/browser/spec/ol/interaction/draw.test.js b/test/browser/spec/ol/interaction/draw.test.js index 5b80d01246..88ce841b97 100644 --- a/test/browser/spec/ol/interaction/draw.test.js +++ b/test/browser/spec/ol/interaction/draw.test.js @@ -4,7 +4,6 @@ import Draw, { createRegularPolygon, } from '../../../../../src/ol/interaction/Draw.js'; import Feature from '../../../../../src/ol/Feature.js'; -import GeometryLayout from '../../../../../src/ol/geom/GeometryLayout.js'; import Interaction from '../../../../../src/ol/interaction/Interaction.js'; import LineString from '../../../../../src/ol/geom/LineString.js'; import Map from '../../../../../src/ol/Map.js'; @@ -2027,83 +2026,83 @@ describe('ol.interaction.Draw', function () { } it('respects XY layout for POINT type', function () { - drawPoint(GeometryLayout.XY); + drawPoint('XY'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([10, -20]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XY); + expect(geometry.getLayout()).to.eql('XY'); }); it('respects XYZ layout for POINT type', function () { - drawPoint(GeometryLayout.XYZ); + drawPoint('XYZ'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([10, -20, 0]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZ); + expect(geometry.getLayout()).to.eql('XYZ'); }); it('respects XYM layout for POINT type', function () { - drawPoint(GeometryLayout.XYM); + drawPoint('XYM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([10, -20, 0]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYM); + expect(geometry.getLayout()).to.eql('XYM'); }); it('respects XYZM layout for POINT type', function () { - drawPoint(GeometryLayout.XYZM); + drawPoint('XYZM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([10, -20, 0, 0]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZM); + expect(geometry.getLayout()).to.eql('XYZM'); }); it('respects XY layout for LINESTRING type', function () { - drawLineString(GeometryLayout.XY); + drawLineString('XY'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ [10, -20], [30, -20], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XY); + expect(geometry.getLayout()).to.eql('XY'); }); it('respects XYZ layout for LINESTRING type', function () { - drawLineString(GeometryLayout.XYZ); + drawLineString('XYZ'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ [10, -20, 0], [30, -20, 0], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZ); + expect(geometry.getLayout()).to.eql('XYZ'); }); it('respects XYM layout for LINESTRING type', function () { - drawLineString(GeometryLayout.XYM); + drawLineString('XYM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ [10, -20, 0], [30, -20, 0], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYM); + expect(geometry.getLayout()).to.eql('XYM'); }); it('respects XYZM layout for LINESTRING type', function () { - drawLineString(GeometryLayout.XYZM); + drawLineString('XYZM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ [10, -20, 0, 0], [30, -20, 0, 0], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZM); + expect(geometry.getLayout()).to.eql('XYZM'); }); it('respects XY layout for POLYGON type', function () { - drawPolygon(GeometryLayout.XY); + drawPolygon('XY'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ @@ -2114,11 +2113,11 @@ describe('ol.interaction.Draw', function () { [10, -20], ], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XY); + expect(geometry.getLayout()).to.eql('XY'); }); it('respects XYZ layout for POLYGON type', function () { - drawPolygon(GeometryLayout.XYZ); + drawPolygon('XYZ'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ @@ -2129,11 +2128,11 @@ describe('ol.interaction.Draw', function () { [10, -20, 0], ], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZ); + expect(geometry.getLayout()).to.eql('XYZ'); }); it('respects XYM layout for POLYGON type', function () { - drawPolygon(GeometryLayout.XYM); + drawPolygon('XYM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ @@ -2144,11 +2143,11 @@ describe('ol.interaction.Draw', function () { [10, -20, 0], ], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYM); + expect(geometry.getLayout()).to.eql('XYM'); }); it('respects XYZM layout for POLYGON type', function () { - drawPolygon(GeometryLayout.XYZM); + drawPolygon('XYZM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCoordinates()).to.eql([ @@ -2159,43 +2158,43 @@ describe('ol.interaction.Draw', function () { [10, -20, 0, 0], ], ]); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZM); + expect(geometry.getLayout()).to.eql('XYZM'); }); it('respects XY layout for CIRCLE type', function () { - drawCircle(GeometryLayout.XY); + drawCircle('XY'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCenter()).to.eql([10, -20]); expect(geometry.getRadius()).to.eql(20); - expect(geometry.getLayout()).to.eql(GeometryLayout.XY); + expect(geometry.getLayout()).to.eql('XY'); }); it('respects XYZ layout for CIRCLE type', function () { - drawCircle(GeometryLayout.XYZ); + drawCircle('XYZ'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCenter()).to.eql([10, -20, 0]); expect(geometry.getRadius()).to.eql(20); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZ); + expect(geometry.getLayout()).to.eql('XYZ'); }); it('respects XYM layout for CIRCLE type', function () { - drawCircle(GeometryLayout.XYM); + drawCircle('XYM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCenter()).to.eql([10, -20, 0]); expect(geometry.getRadius()).to.eql(20); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYM); + expect(geometry.getLayout()).to.eql('XYM'); }); it('respects XYZM layout for CIRCLE type', function () { - drawCircle(GeometryLayout.XYZM); + drawCircle('XYZM'); const features = source.getFeatures(); const geometry = features[0].getGeometry(); expect(geometry.getCenter()).to.eql([10, -20, 0, 0]); expect(geometry.getRadius()).to.eql(20); - expect(geometry.getLayout()).to.eql(GeometryLayout.XYZM); + expect(geometry.getLayout()).to.eql('XYZM'); }); }); });