Use union type instead of enum for canvas builder type
This commit is contained in:
committed by
Andreas Hocevar
parent
05f9b35eeb
commit
3a061ed576
@@ -8,6 +8,10 @@ import {clear} from '../obj.js';
|
||||
import {createCanvasContext2D} from '../dom.js';
|
||||
import {getFontParameters} from '../css.js';
|
||||
|
||||
/**
|
||||
* @typedef {'Circle' | 'Image' | 'LineString' | 'Polygon' | 'Text' | 'Default'} BuilderType
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} FillState
|
||||
* @property {import("../colorlike.js").ColorLike} fillStyle FillStyle.
|
||||
|
||||
@@ -9,7 +9,7 @@ import PolygonBuilder from './PolygonBuilder.js';
|
||||
import TextBuilder from './TextBuilder.js';
|
||||
|
||||
/**
|
||||
* @type {Object<import("./BuilderType").default, typeof Builder>}
|
||||
* @type {Object<import("../canvas.js").BuilderType, typeof Builder>}
|
||||
*/
|
||||
const BATCH_CONSTRUCTORS = {
|
||||
'Circle': PolygonBuilder,
|
||||
@@ -54,13 +54,13 @@ class BuilderGroup {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object<string, !Object<import("./BuilderType").default, Builder>>}
|
||||
* @type {!Object<string, !Object<import("../canvas.js").BuilderType, Builder>>}
|
||||
*/
|
||||
this.buildersByZIndex_ = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Object<string, !Object<import("./BuilderType").default, import("./Builder.js").SerializableInstructions>>} The serializable instructions
|
||||
* @return {!Object<string, !Object<import("../canvas.js").BuilderType, import("./Builder.js").SerializableInstructions>>} The serializable instructions
|
||||
*/
|
||||
finish() {
|
||||
const builderInstructions = {};
|
||||
@@ -77,7 +77,7 @@ class BuilderGroup {
|
||||
|
||||
/**
|
||||
* @param {number|undefined} zIndex Z index.
|
||||
* @param {import("./BuilderType.js").default} builderType Replay type.
|
||||
* @param {import("../canvas.js").BuilderType} builderType Replay type.
|
||||
* @return {import("../VectorContext.js").default} Replay.
|
||||
*/
|
||||
getBuilder(zIndex, builderType) {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* @module ol/render/canvas/BuilderType
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
CIRCLE: 'Circle',
|
||||
DEFAULT: 'Default',
|
||||
IMAGE: 'Image',
|
||||
LINE_STRING: 'LineString',
|
||||
POLYGON: 'Polygon',
|
||||
TEXT: 'Text',
|
||||
};
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/render/canvas/ExecutorGroup
|
||||
*/
|
||||
|
||||
import BuilderType from './BuilderType.js';
|
||||
import Executor from './Executor.js';
|
||||
import {buffer, createEmpty, extendCoordinate} from '../../extent.js';
|
||||
import {
|
||||
@@ -16,16 +15,9 @@ import {transform2D} from '../../geom/flat/transform.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Array<import("./BuilderType.js").default>}
|
||||
* @type {Array<import("../canvas.js").BuilderType>}
|
||||
*/
|
||||
const ORDER = [
|
||||
BuilderType.POLYGON,
|
||||
BuilderType.CIRCLE,
|
||||
BuilderType.LINE_STRING,
|
||||
BuilderType.IMAGE,
|
||||
BuilderType.TEXT,
|
||||
BuilderType.DEFAULT,
|
||||
];
|
||||
const ORDER = ['Polygon', 'Circle', 'LineString', 'Image', 'Text', 'Default'];
|
||||
|
||||
class ExecutorGroup {
|
||||
/**
|
||||
@@ -36,7 +28,7 @@ class ExecutorGroup {
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {boolean} overlaps The executor group can have overlapping geometries.
|
||||
* @param {!Object<string, !Object<import("./BuilderType.js").default, import("../canvas.js").SerializableInstructions>>} allInstructions
|
||||
* @param {!Object<string, !Object<import("../canvas.js").BuilderType, import("../canvas.js").SerializableInstructions>>} allInstructions
|
||||
* The serializable instructions.
|
||||
* @param {number} [opt_renderBuffer] Optional rendering buffer.
|
||||
*/
|
||||
@@ -80,7 +72,7 @@ class ExecutorGroup {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object<string, !Object<import("./BuilderType.js").default, import("./Executor").default>>}
|
||||
* @type {!Object<string, !Object<import("../canvas.js").BuilderType, import("./Executor").default>>}
|
||||
*/
|
||||
this.executorsByZIndex_ = {};
|
||||
|
||||
@@ -116,7 +108,7 @@ class ExecutorGroup {
|
||||
/**
|
||||
* Create executors and populate them using the provided instructions.
|
||||
* @private
|
||||
* @param {!Object<string, !Object<import("./BuilderType.js").default, import("../canvas.js").SerializableInstructions>>} allInstructions The serializable instructions
|
||||
* @param {!Object<string, !Object<import("../canvas.js").BuilderType, import("../canvas.js").SerializableInstructions>>} allInstructions The serializable instructions
|
||||
*/
|
||||
createExecutors_(allInstructions) {
|
||||
for (const zIndex in allInstructions) {
|
||||
@@ -139,7 +131,7 @@ class ExecutorGroup {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<import("./BuilderType.js").default>} executors Executors.
|
||||
* @param {Array<import("../canvas.js").BuilderType>} executors Executors.
|
||||
* @return {boolean} Has executors of the provided types.
|
||||
*/
|
||||
hasExecutors(executors) {
|
||||
@@ -238,8 +230,7 @@ class ExecutorGroup {
|
||||
if (imageData[indexes[i]] > 0) {
|
||||
if (
|
||||
!declutteredFeatures ||
|
||||
(builderType !== BuilderType.IMAGE &&
|
||||
builderType !== BuilderType.TEXT) ||
|
||||
(builderType !== 'Image' && builderType !== 'Text') ||
|
||||
declutteredFeatures.indexOf(feature) !== -1
|
||||
) {
|
||||
const idx = (indexes[i] - 3) / 4;
|
||||
@@ -316,7 +307,7 @@ class ExecutorGroup {
|
||||
* @param {import("../../transform.js").Transform} transform Transform.
|
||||
* @param {number} viewRotation View rotation.
|
||||
* @param {boolean} snapToPixel Snap point symbols and test to integer pixel.
|
||||
* @param {Array<import("./BuilderType.js").default>} [opt_builderTypes] Ordered replay types to replay.
|
||||
* @param {Array<import("../canvas.js").BuilderType>} [opt_builderTypes] Ordered replay types to replay.
|
||||
* Default is {@link module:ol/render/replay~ORDER}
|
||||
* @param {import("rbush").default} [opt_declutterTree] Declutter tree.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user