ol/render/replay export

This commit is contained in:
raiyni
2018-02-15 22:54:02 -06:00
parent c715570f87
commit b5b3e256f8
7 changed files with 35 additions and 36 deletions

View File

@@ -17,7 +17,7 @@ import {isEmpty} from '../../obj.js';
import VectorContext from '../VectorContext.js'; import VectorContext from '../VectorContext.js';
import {drawImage, resetTransform, defaultPadding, defaultFillStyle, defaultStrokeStyle, defaultMiterLimit, defaultLineWidth, defaultLineJoin, defaultLineDashOffset, defaultLineDash, defaultLineCap} from '../canvas.js'; import {drawImage, resetTransform, defaultPadding, defaultFillStyle, defaultStrokeStyle, defaultMiterLimit, defaultLineWidth, defaultLineJoin, defaultLineDashOffset, defaultLineDash, defaultLineCap} from '../canvas.js';
import CanvasInstruction from '../canvas/Instruction.js'; import CanvasInstruction from '../canvas/Instruction.js';
import _ol_render_replay_ from '../replay.js'; import {TEXT_ALIGN} from '../replay.js';
import { import {
create as createTransform, create as createTransform,
compose as composeTransform, compose as composeTransform,
@@ -718,7 +718,7 @@ CanvasReplay.prototype.replay_ = function(
const textLength = measure(text); const textLength = measure(text);
if (overflow || textLength <= pathLength) { if (overflow || textLength <= pathLength) {
const textAlign = /** @type {ol.render.canvas.TextReplay} */ (this).textStates[textKey].textAlign; 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( const parts = drawTextOnPath(
pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle); pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle);
if (parts) { if (parts) {

View File

@@ -14,7 +14,7 @@ import CanvasImageReplay from '../canvas/ImageReplay.js';
import CanvasLineStringReplay from '../canvas/LineStringReplay.js'; import CanvasLineStringReplay from '../canvas/LineStringReplay.js';
import CanvasPolygonReplay from '../canvas/PolygonReplay.js'; import CanvasPolygonReplay from '../canvas/PolygonReplay.js';
import CanvasTextReplay from '../canvas/TextReplay.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'; 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) { for (i = zs.length - 1; i >= 0; --i) {
const zIndexKey = zs[i].toString(); const zIndexKey = zs[i].toString();
replays = this.replaysByZIndex_[zIndexKey]; replays = this.replaysByZIndex_[zIndexKey];
for (j = _ol_render_replay_.ORDER.length - 1; j >= 0; --j) { for (j = ORDER.length - 1; j >= 0; --j) {
replayType = _ol_render_replay_.ORDER[j]; replayType = ORDER[j];
replay = replays[replayType]; replay = replays[replayType];
if (replay !== undefined) { if (replay !== undefined) {
if (declutterReplays && if (declutterReplays &&
@@ -473,7 +473,7 @@ CanvasReplayGroup.prototype.replay = function(context,
context.save(); context.save();
this.clip(context, transform); 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; let i, ii, j, jj, replays, replay;
for (i = 0, ii = zs.length; i < ii; ++i) { for (i = 0, ii = zs.length; i < ii; ++i) {
const zIndexKey = zs[i].toString(); const zIndexKey = zs[i].toString();

View File

@@ -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 {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 CanvasInstruction from '../canvas/Instruction.js';
import CanvasReplay from '../canvas/Replay.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'; 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 textState = this.textStates[textKey] || this.textState_;
const pixelRatio = this.pixelRatio; const pixelRatio = this.pixelRatio;
const scale = textState.scale * 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 strokeWidth = strokeKey && strokeState.lineWidth ? strokeState.lineWidth : 0;
const lines = text.split('\n'); const lines = text.split('\n');
@@ -354,8 +354,8 @@ CanvasTextReplay.prototype.drawTextImage_ = function(label, begin, end) {
const textState = this.textState_; const textState = this.textState_;
const strokeState = this.textStrokeState_; const strokeState = this.textStrokeState_;
const pixelRatio = this.pixelRatio; const pixelRatio = this.pixelRatio;
const align = _ol_render_replay_.TEXT_ALIGN[textState.textAlign || defaultTextAlign]; const align = TEXT_ALIGN[textState.textAlign || defaultTextAlign];
const baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline]; const baseline = TEXT_ALIGN[textState.textBaseline];
const strokeWidth = strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0; const strokeWidth = strokeState && strokeState.lineWidth ? strokeState.lineWidth : 0;
const anchorX = align * label.width / pixelRatio + 2 * (0.5 - align) * strokeWidth; 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 pixelRatio = this.pixelRatio;
const baseline = _ol_render_replay_.TEXT_ALIGN[textState.textBaseline]; const baseline = TEXT_ALIGN[textState.textBaseline];
const offsetY = this.textOffsetY_ * pixelRatio; const offsetY = this.textOffsetY_ * pixelRatio;
const text = this.text_; const text = this.text_;

View File

@@ -2,14 +2,13 @@
* @module ol/render/replay * @module ol/render/replay
*/ */
import ReplayType from '../render/ReplayType.js'; import ReplayType from '../render/ReplayType.js';
const _ol_render_replay_ = {};
/** /**
* @const * @const
* @type {Array.<ol.render.ReplayType>} * @type {Array.<ol.render.ReplayType>}
*/ */
_ol_render_replay_.ORDER = [ export const ORDER = [
ReplayType.POLYGON, ReplayType.POLYGON,
ReplayType.CIRCLE, ReplayType.CIRCLE,
ReplayType.LINE_STRING, ReplayType.LINE_STRING,
@@ -22,16 +21,16 @@ _ol_render_replay_.ORDER = [
* @const * @const
* @enum {number} * @enum {number}
*/ */
_ol_render_replay_.TEXT_ALIGN = {}; export const TEXT_ALIGN = {
_ol_render_replay_.TEXT_ALIGN['left'] = 0; left: 0,
_ol_render_replay_.TEXT_ALIGN['end'] = 0; end: 0,
_ol_render_replay_.TEXT_ALIGN['center'] = 0.5; center: 0.5,
_ol_render_replay_.TEXT_ALIGN['right'] = 1; right: 1,
_ol_render_replay_.TEXT_ALIGN['start'] = 1; start: 1,
_ol_render_replay_.TEXT_ALIGN['top'] = 0; top: 0,
_ol_render_replay_.TEXT_ALIGN['middle'] = 0.5; middle: 0.5,
_ol_render_replay_.TEXT_ALIGN['hanging'] = 0.2; hanging: 0.2,
_ol_render_replay_.TEXT_ALIGN['alphabetic'] = 0.8; alphabetic: 0.8,
_ol_render_replay_.TEXT_ALIGN['ideographic'] = 0.8; ideographic: 0.8,
_ol_render_replay_.TEXT_ALIGN['bottom'] = 1; bottom: 1
export default _ol_render_replay_; };

View File

@@ -5,7 +5,7 @@ import {inherits} from '../../index.js';
import {numberSafeCompareFunction} from '../../array.js'; import {numberSafeCompareFunction} from '../../array.js';
import {buffer, createOrUpdateFromCoordinate} from '../../extent.js'; import {buffer, createOrUpdateFromCoordinate} from '../../extent.js';
import {isEmpty} from '../../obj.js'; import {isEmpty} from '../../obj.js';
import _ol_render_replay_ from '../replay.js'; import {ORDER} from '../replay.js';
import ReplayGroup from '../ReplayGroup.js'; import ReplayGroup from '../ReplayGroup.js';
import WebGLCircleReplay from '../webgl/CircleReplay.js'; import WebGLCircleReplay from '../webgl/CircleReplay.js';
import WebGLImageReplay from '../webgl/ImageReplay.js'; import WebGLImageReplay from '../webgl/ImageReplay.js';
@@ -171,8 +171,8 @@ WebGLReplayGroup.prototype.replay = function(context,
let i, ii, j, jj, replays, replay; let i, ii, j, jj, replays, replay;
for (i = 0, ii = zs.length; i < ii; ++i) { for (i = 0, ii = zs.length; i < ii; ++i) {
replays = this.replaysByZIndex_[zs[i].toString()]; replays = this.replaysByZIndex_[zs[i].toString()];
for (j = 0, jj = _ol_render_replay_.ORDER.length; j < jj; ++j) { for (j = 0, jj = ORDER.length; j < jj; ++j) {
replay = replays[_ol_render_replay_.ORDER[j]]; replay = replays[ORDER[j]];
if (replay !== undefined) { if (replay !== undefined) {
replay.replay(context, replay.replay(context,
center, resolution, rotation, size, pixelRatio, center, resolution, rotation, size, pixelRatio,
@@ -214,8 +214,8 @@ WebGLReplayGroup.prototype.replayHitDetection_ = function(context,
let i, ii, j, replays, replay, result; let i, ii, j, replays, replay, result;
for (i = 0, ii = zs.length; i < ii; ++i) { for (i = 0, ii = zs.length; i < ii; ++i) {
replays = this.replaysByZIndex_[zs[i].toString()]; replays = this.replaysByZIndex_[zs[i].toString()];
for (j = _ol_render_replay_.ORDER.length - 1; j >= 0; --j) { for (j = ORDER.length - 1; j >= 0; --j) {
replay = replays[_ol_render_replay_.ORDER[j]]; replay = replays[ORDER[j]];
if (replay !== undefined) { if (replay !== undefined) {
result = replay.replay(context, result = replay.replay(context,
center, resolution, rotation, size, pixelRatio, opacity, center, resolution, rotation, size, pixelRatio, opacity,

View File

@@ -6,7 +6,7 @@ import {asColorLike} from '../../colorlike.js';
import {createCanvasContext2D} from '../../dom.js'; import {createCanvasContext2D} from '../../dom.js';
import GeometryType from '../../geom/GeometryType.js'; import GeometryType from '../../geom/GeometryType.js';
import {CANVAS_LINE_DASH} from '../../has.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, import {DEFAULT_FILLSTYLE, DEFAULT_FONT, DEFAULT_LINECAP, DEFAULT_LINEDASH,
DEFAULT_LINEDASHOFFSET, DEFAULT_LINEJOIN, DEFAULT_LINEWIDTH, DEFAULT_MITERLIMIT, DEFAULT_LINEDASHOFFSET, DEFAULT_LINEJOIN, DEFAULT_LINEWIDTH, DEFAULT_MITERLIMIT,
DEFAULT_STROKESTYLE, DEFAULT_TEXTALIGN, DEFAULT_TEXTBASELINE} from '../webgl.js'; 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.font = textStyle.getFont() || DEFAULT_FONT;
state.scale = textStyle.getScale() || 1; state.scale = textStyle.getScale() || 1;
this.text_ = /** @type {string} */ (textStyle.getText()); this.text_ = /** @type {string} */ (textStyle.getText());
const textAlign = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextAlign()]; const textAlign = TEXT_ALIGN[textStyle.getTextAlign()];
const textBaseline = _ol_render_replay_.TEXT_ALIGN[textStyle.getTextBaseline()]; const textBaseline = TEXT_ALIGN[textStyle.getTextBaseline()];
this.textAlign_ = textAlign === undefined ? this.textAlign_ = textAlign === undefined ?
DEFAULT_TEXTALIGN : textAlign; DEFAULT_TEXTALIGN : textAlign;
this.textBaseline_ = textBaseline === undefined ? this.textBaseline_ = textBaseline === undefined ?

View File

@@ -15,7 +15,7 @@ import Units from '../../proj/Units.js';
import ReplayType from '../../render/ReplayType.js'; import ReplayType from '../../render/ReplayType.js';
import {labelCache, rotateAtOffset} from '../../render/canvas.js'; import {labelCache, rotateAtOffset} from '../../render/canvas.js';
import CanvasReplayGroup from '../../render/canvas/ReplayGroup.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 RendererType from '../Type.js';
import CanvasTileLayerRenderer from '../canvas/TileLayer.js'; import CanvasTileLayerRenderer from '../canvas/TileLayer.js';
import {getSquaredTolerance as getSquaredRenderTolerance, renderFeature} from '../vector.js'; import {getSquaredTolerance as getSquaredRenderTolerance, renderFeature} from '../vector.js';
@@ -44,7 +44,7 @@ const IMAGE_REPLAYS = {
const VECTOR_REPLAYS = { const VECTOR_REPLAYS = {
'image': [ReplayType.DEFAULT], 'image': [ReplayType.DEFAULT],
'hybrid': [ReplayType.IMAGE, ReplayType.TEXT, ReplayType.DEFAULT], 'hybrid': [ReplayType.IMAGE, ReplayType.TEXT, ReplayType.DEFAULT],
'vector': _ol_render_replay_.ORDER 'vector': ORDER
}; };