Replace TextPlacement enum with typedef

This commit is contained in:
Maximilian Krög
2022-07-16 23:30:07 +02:00
parent 4d2156ff3a
commit 69caa06783
4 changed files with 15 additions and 24 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ import {getFontParameters} from '../css.js';
* @property {string} [textAlign] TextAlign. * @property {string} [textAlign] TextAlign.
* @property {string} [justify] Justify. * @property {string} [justify] Justify.
* @property {string} textBaseline TextBaseline. * @property {string} textBaseline TextBaseline.
* @property {string} [placement] Placement. * @property {import('../style/Text.js').TextPlacement} [placement] Placement.
* @property {number} [maxAngle] MaxAngle. * @property {number} [maxAngle] MaxAngle.
* @property {boolean} [overflow] Overflow. * @property {boolean} [overflow] Overflow.
* @property {import("../style/Fill.js").default} [backgroundFill] BackgroundFill. * @property {import("../style/Fill.js").default} [backgroundFill] BackgroundFill.
+1 -2
View File
@@ -3,7 +3,6 @@
*/ */
import CanvasBuilder from './Builder.js'; import CanvasBuilder from './Builder.js';
import CanvasInstruction from './Instruction.js'; import CanvasInstruction from './Instruction.js';
import TextPlacement from '../../style/TextPlacement.js';
import {asColorLike} from '../../colorlike.js'; import {asColorLike} from '../../colorlike.js';
import { import {
defaultFillStyle, defaultFillStyle,
@@ -177,7 +176,7 @@ class CanvasTextBuilder extends CanvasBuilder {
let stride = geometry.getStride(); let stride = geometry.getStride();
if ( if (
textState.placement === TextPlacement.LINE && textState.placement === 'line' &&
(geometryType == 'LineString' || (geometryType == 'LineString' ||
geometryType == 'MultiLineString' || geometryType == 'MultiLineString' ||
geometryType == 'Polygon' || geometryType == 'Polygon' ||
+13 -6
View File
@@ -2,9 +2,16 @@
* @module ol/style/Text * @module ol/style/Text
*/ */
import Fill from './Fill.js'; import Fill from './Fill.js';
import TextPlacement from './TextPlacement.js';
import {toSize} from '../size.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 * The default fill color to use if no fill was set at construction time; a
* blackish `#333`. * 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 {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 * @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. * 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 {number|import("../size.js").Size} [scale] Scale.
* @property {boolean} [rotateWithView=false] Whether to rotate the text with the view. * @property {boolean} [rotateWithView=false] Whether to rotate the text with the view.
* @property {number} [rotation=0] Rotation in radians (positive rotation clockwise). * @property {number} [rotation=0] Rotation in radians (positive rotation clockwise).
@@ -135,10 +142,10 @@ class Text {
/** /**
* @private * @private
* @type {import("./TextPlacement.js").default|string} * @type {TextPlacement}
*/ */
this.placement_ = this.placement_ =
options.placement !== undefined ? options.placement : TextPlacement.POINT; options.placement !== undefined ? options.placement : 'point';
/** /**
* @private * @private
@@ -249,7 +256,7 @@ class Text {
/** /**
* Get the label placement. * Get the label placement.
* @return {import("./TextPlacement.js").default|string} Text placement. * @return {TextPlacement} Text placement.
* @api * @api
*/ */
getPlacement() { getPlacement() {
@@ -443,7 +450,7 @@ class Text {
/** /**
* Set the text placement. * Set the text placement.
* *
* @param {import("./TextPlacement.js").default|string} placement Placement. * @param {TextPlacement} placement Placement.
* @api * @api
*/ */
setPlacement(placement) { setPlacement(placement) {
-15
View File
@@ -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',
};