diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index 7ead085a7f..63edc8988d 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -5,7 +5,6 @@ import Feature from '../Feature.js'; import Fill from '../style/Fill.js'; import GeometryCollection from '../geom/GeometryCollection.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'; @@ -56,9 +55,9 @@ 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/Icon.js").IconAnchorUnits} yunits Units of Y. * @property {import("../style/IconOrigin.js").default} [origin] Origin. */ @@ -95,12 +94,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', }; /** @@ -211,12 +210,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; @@ -323,9 +322,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]; @@ -2627,9 +2626,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/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/style/Icon.js b/src/ol/style/Icon.js index ab63f15867..5a0e95cde0 100644 --- a/src/ol/style/Icon.js +++ b/src/ol/style/Icon.js @@ -2,7 +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'; @@ -11,15 +10,20 @@ 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 {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`, * `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, @@ -113,21 +117,17 @@ class Icon extends ImageStyle { /** * @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 @@ -255,17 +255,17 @@ 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]; } } 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/test/browser/spec/ol/format/kml.test.js b/test/browser/spec/ol/format/kml.test.js index 53035a9ad8..672f95e7f5 100644 --- a/test/browser/spec/ol/format/kml.test.js +++ b/test/browser/spec/ol/format/kml.test.js @@ -4,7 +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, { @@ -2431,13 +2430,13 @@ describe('ol.format.KML', function () { 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.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); }