From b5b3e256f815b47eea46845f5692e89f75d12857 Mon Sep 17 00:00:00 2001 From: raiyni Date: Thu, 15 Feb 2018 22:54:02 -0600 Subject: [PATCH] ol/render/replay export --- src/ol/render/canvas/Replay.js | 4 ++-- src/ol/render/canvas/ReplayGroup.js | 8 +++---- src/ol/render/canvas/TextReplay.js | 10 ++++---- src/ol/render/replay.js | 29 +++++++++++------------ src/ol/render/webgl/ReplayGroup.js | 10 ++++---- src/ol/render/webgl/TextReplay.js | 6 ++--- src/ol/renderer/canvas/VectorTileLayer.js | 4 ++-- 7 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index 7a7a5a205a..f3253383d3 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -17,7 +17,7 @@ import {isEmpty} from '../../obj.js'; import VectorContext from '../VectorContext.js'; import {drawImage, resetTransform, defaultPadding, defaultFillStyle, defaultStrokeStyle, defaultMiterLimit, defaultLineWidth, defaultLineJoin, defaultLineDashOffset, defaultLineDash, defaultLineCap} from '../canvas.js'; import CanvasInstruction from '../canvas/Instruction.js'; -import _ol_render_replay_ from '../replay.js'; +import {TEXT_ALIGN} from '../replay.js'; import { create as createTransform, compose as composeTransform, @@ -718,7 +718,7 @@ CanvasReplay.prototype.replay_ = function( const textLength = measure(text); if (overflow || textLength <= pathLength) { const textAlign = /** @type {ol.render.canvas.TextReplay} */ (this).textStates[textKey].textAlign; - const startM = (pathLength - textLength) * _ol_render_replay_.TEXT_ALIGN[textAlign]; + const startM = (pathLength - textLength) * TEXT_ALIGN[textAlign]; const parts = drawTextOnPath( pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle); if (parts) { diff --git a/src/ol/render/canvas/ReplayGroup.js b/src/ol/render/canvas/ReplayGroup.js index 436349b897..21d31ce01c 100644 --- a/src/ol/render/canvas/ReplayGroup.js +++ b/src/ol/render/canvas/ReplayGroup.js @@ -14,7 +14,7 @@ import CanvasImageReplay from '../canvas/ImageReplay.js'; import CanvasLineStringReplay from '../canvas/LineStringReplay.js'; import CanvasPolygonReplay from '../canvas/PolygonReplay.js'; import CanvasTextReplay from '../canvas/TextReplay.js'; -import _ol_render_replay_ from '../replay.js'; +import {ORDER} from '../replay.js'; import {create as createTransform, compose as composeTransform} from '../../transform.js'; @@ -370,8 +370,8 @@ CanvasReplayGroup.prototype.forEachFeatureAtCoordinate = function( for (i = zs.length - 1; i >= 0; --i) { const zIndexKey = zs[i].toString(); replays = this.replaysByZIndex_[zIndexKey]; - for (j = _ol_render_replay_.ORDER.length - 1; j >= 0; --j) { - replayType = _ol_render_replay_.ORDER[j]; + for (j = ORDER.length - 1; j >= 0; --j) { + replayType = ORDER[j]; replay = replays[replayType]; if (replay !== undefined) { if (declutterReplays && @@ -473,7 +473,7 @@ CanvasReplayGroup.prototype.replay = function(context, context.save(); this.clip(context, transform); - const replayTypes = opt_replayTypes ? opt_replayTypes : _ol_render_replay_.ORDER; + const replayTypes = opt_replayTypes ? opt_replayTypes : ORDER; let i, ii, j, jj, replays, replay; for (i = 0, ii = zs.length; i < ii; ++i) { const zIndexKey = zs[i].toString(); diff --git a/src/ol/render/canvas/TextReplay.js b/src/ol/render/canvas/TextReplay.js index c06a4003ee..f707289950 100644 --- a/src/ol/render/canvas/TextReplay.js +++ b/src/ol/render/canvas/TextReplay.js @@ -11,7 +11,7 @@ import {CANVAS_LINE_DASH, SAFARI} from '../../has.js'; import {labelCache, measureTextWidth, defaultTextAlign, measureTextHeight, defaultPadding, defaultLineCap, defaultLineDashOffset, defaultLineDash, defaultLineJoin, defaultFillStyle, checkFont, defaultFont, defaultLineWidth, defaultMiterLimit, defaultStrokeStyle, defaultTextBaseline} from '../canvas.js'; import CanvasInstruction from '../canvas/Instruction.js'; import CanvasReplay from '../canvas/Replay.js'; -import _ol_render_replay_ from '../replay.js'; +import {TEXT_ALIGN} from '../replay.js'; import TextPlacement from '../../style/TextPlacement.js'; /** @@ -291,7 +291,7 @@ CanvasTextReplay.prototype.getImage = function(text, textKey, fillKey, strokeKey const textState = this.textStates[textKey] || this.textState_; const pixelRatio = this.pixelRatio; const scale = textState.scale * pixelRatio; - const align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || defaultTextAlign]; + const align = TEXT_ALIGN[textState.textAlign || defaultTextAlign]; const strokeWidth = strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0; const lines = text.split('\n'); @@ -354,8 +354,8 @@ CanvasTextReplay.prototype.drawTextImage_ = function(label, begin, end) { const textState = this.textState_; const strokeState = this.textStrokeState_; const pixelRatio = this.pixelRatio; - const align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || defaultTextAlign]; - const baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline]; + const align = TEXT_ALIGN[textState.textAlign || defaultTextAlign]; + const baseline = TEXT_ALIGN[textState.textBaseline]; const strokeWidth = strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0; const anchorX = align * label.width / pixelRatio + 2 * (0.5 - align) * strokeWidth; @@ -422,7 +422,7 @@ CanvasTextReplay.prototype.drawChars_ = function(begin, end, declutterGroup) { } const pixelRatio = this.pixelRatio; - const baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline]; + const baseline = TEXT_ALIGN[textState.textBaseline]; const offsetY = this.textOffsetY_ * pixelRatio; const text = this.text_; diff --git a/src/ol/render/replay.js b/src/ol/render/replay.js index c477763e7a..6e667ee408 100644 --- a/src/ol/render/replay.js +++ b/src/ol/render/replay.js @@ -2,14 +2,13 @@ * @module ol/render/replay */ import ReplayType from '../render/ReplayType.js'; -const _ol_render_replay_ = {}; /** * @const * @type {Array.} */ -_ol_render_replay_.ORDER = [ +export const ORDER = [ ReplayType.POLYGON, ReplayType.CIRCLE, ReplayType.LINE_STRING, @@ -22,16 +21,16 @@ _ol_render_replay_.ORDER = [ * @const * @enum {number} */ -_ol_render_replay_.TEXT_ALIGN = {}; -_ol_render_replay_.TEXT_ALIGN['left'] = 0; -_ol_render_replay_.TEXT_ALIGN['end'] = 0; -_ol_render_replay_.TEXT_ALIGN['center'] = 0.5; -_ol_render_replay_.TEXT_ALIGN['right'] = 1; -_ol_render_replay_.TEXT_ALIGN['start'] = 1; -_ol_render_replay_.TEXT_ALIGN['top'] = 0; -_ol_render_replay_.TEXT_ALIGN['middle'] = 0.5; -_ol_render_replay_.TEXT_ALIGN['hanging'] = 0.2; -_ol_render_replay_.TEXT_ALIGN['alphabetic'] = 0.8; -_ol_render_replay_.TEXT_ALIGN['ideographic'] = 0.8; -_ol_render_replay_.TEXT_ALIGN['bottom'] = 1; -export default _ol_render_replay_; +export const TEXT_ALIGN = { + left: 0, + end: 0, + center: 0.5, + right: 1, + start: 1, + top: 0, + middle: 0.5, + hanging: 0.2, + alphabetic: 0.8, + ideographic: 0.8, + bottom: 1 +}; diff --git a/src/ol/render/webgl/ReplayGroup.js b/src/ol/render/webgl/ReplayGroup.js index c2f787ad10..4fb2cceb78 100644 --- a/src/ol/render/webgl/ReplayGroup.js +++ b/src/ol/render/webgl/ReplayGroup.js @@ -5,7 +5,7 @@ import {inherits} from '../../index.js'; import {numberSafeCompareFunction} from '../../array.js'; import {buffer, createOrUpdateFromCoordinate} from '../../extent.js'; import {isEmpty} from '../../obj.js'; -import _ol_render_replay_ from '../replay.js'; +import {ORDER} from '../replay.js'; import ReplayGroup from '../ReplayGroup.js'; import WebGLCircleReplay from '../webgl/CircleReplay.js'; import WebGLImageReplay from '../webgl/ImageReplay.js'; @@ -171,8 +171,8 @@ WebGLReplayGroup.prototype.replay = function(context, let i, ii, j, jj, replays, replay; for (i = 0, ii = zs.length; i < ii; ++i) { replays = this.replaysByZIndex_[zs[i].toString()]; - for (j = 0, jj = _ol_render_replay_.ORDER.length; j < jj; ++j) { - replay = replays[_ol_render_replay_.ORDER[j]]; + for (j = 0, jj = ORDER.length; j < jj; ++j) { + replay = replays[ORDER[j]]; if (replay !== undefined) { replay.replay(context, center, resolution, rotation, size, pixelRatio, @@ -214,8 +214,8 @@ WebGLReplayGroup.prototype.replayHitDetection_ = function(context, let i, ii, j, replays, replay, result; for (i = 0, ii = zs.length; i < ii; ++i) { replays = this.replaysByZIndex_[zs[i].toString()]; - for (j = _ol_render_replay_.ORDER.length - 1; j >= 0; --j) { - replay = replays[_ol_render_replay_.ORDER[j]]; + for (j = ORDER.length - 1; j >= 0; --j) { + replay = replays[ORDER[j]]; if (replay !== undefined) { result = replay.replay(context, center, resolution, rotation, size, pixelRatio, opacity, diff --git a/src/ol/render/webgl/TextReplay.js b/src/ol/render/webgl/TextReplay.js index 298e54891e..739e587a74 100644 --- a/src/ol/render/webgl/TextReplay.js +++ b/src/ol/render/webgl/TextReplay.js @@ -6,7 +6,7 @@ import {asColorLike} from '../../colorlike.js'; import {createCanvasContext2D} from '../../dom.js'; import GeometryType from '../../geom/GeometryType.js'; import {CANVAS_LINE_DASH} from '../../has.js'; -import _ol_render_replay_ from '../replay.js'; +import {TEXT_ALIGN} from '../replay.js'; import {DEFAULT_FILLSTYLE, DEFAULT_FONT, DEFAULT_LINECAP, DEFAULT_LINEDASH, DEFAULT_LINEDASHOFFSET, DEFAULT_LINEJOIN, DEFAULT_LINEWIDTH, DEFAULT_MITERLIMIT, DEFAULT_STROKESTYLE, DEFAULT_TEXTALIGN, DEFAULT_TEXTBASELINE} from '../webgl.js'; @@ -378,8 +378,8 @@ WebGLTextReplay.prototype.setTextStyle = function(textStyle) { state.font = textStyle.getFont() || DEFAULT_FONT; state.scale = textStyle.getScale() || 1; this.text_ = /** @type {string} */ (textStyle.getText()); - const textAlign = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextAlign()]; - const textBaseline = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextBaseline()]; + const textAlign = TEXT_ALIGN[textStyle.getTextAlign()]; + const textBaseline = TEXT_ALIGN[textStyle.getTextBaseline()]; this.textAlign_ = textAlign === undefined ? DEFAULT_TEXTALIGN : textAlign; this.textBaseline_ = textBaseline === undefined ? diff --git a/src/ol/renderer/canvas/VectorTileLayer.js b/src/ol/renderer/canvas/VectorTileLayer.js index eb7139a7cf..e89c2ed341 100644 --- a/src/ol/renderer/canvas/VectorTileLayer.js +++ b/src/ol/renderer/canvas/VectorTileLayer.js @@ -15,7 +15,7 @@ import Units from '../../proj/Units.js'; import ReplayType from '../../render/ReplayType.js'; import {labelCache, rotateAtOffset} from '../../render/canvas.js'; import CanvasReplayGroup from '../../render/canvas/ReplayGroup.js'; -import _ol_render_replay_ from '../../render/replay.js'; +import {ORDER} from '../../render/replay.js'; import RendererType from '../Type.js'; import CanvasTileLayerRenderer from '../canvas/TileLayer.js'; import {getSquaredTolerance as getSquaredRenderTolerance, renderFeature} from '../vector.js'; @@ -44,7 +44,7 @@ const IMAGE_REPLAYS = { const VECTOR_REPLAYS = { 'image': [ReplayType.DEFAULT], 'hybrid': [ReplayType.IMAGE, ReplayType.TEXT, ReplayType.DEFAULT], - 'vector': _ol_render_replay_.ORDER + 'vector': ORDER };