diff --git a/src/ol/geom/flat/textpath.js b/src/ol/geom/flat/textpath.js index d4bb434f9a..5b0d9648c6 100644 --- a/src/ol/geom/flat/textpath.js +++ b/src/ol/geom/flat/textpath.js @@ -2,7 +2,6 @@ * @module ol/geom/flat/textpath */ import {lerp} from '../../math.js'; -const _ol_geom_flat_textpath_ = {}; /** @@ -18,7 +17,7 @@ const _ol_geom_flat_textpath_ = {}; * @return {Array.>} The result array of null if `maxAngle` was * exceeded. Entries of the array are x, y, anchorX, angle, chunk. */ -_ol_geom_flat_textpath_.lineString = function( +export function drawTextOnPath( flatCoordinates, offset, end, stride, text, measure, startM, maxAngle) { const result = []; @@ -90,5 +89,4 @@ _ol_geom_flat_textpath_.lineString = function( startM += charLength; } return result; -}; -export default _ol_geom_flat_textpath_; +} diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index b43195e582..6580f16312 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -10,7 +10,7 @@ import Relationship from '../../extent/Relationship.js'; import GeometryType from '../../geom/GeometryType.js'; import {inflateCoordinates, inflateCoordinatesArray, inflateMultiCoordinatesArray} from '../../geom/flat/inflate.js'; import {lineStringLength} from '../../geom/flat/length.js'; -import _ol_geom_flat_textpath_ from '../../geom/flat/textpath.js'; +import {drawTextOnPath} from '../../geom/flat/textpath.js'; import _ol_geom_flat_transform_ from '../../geom/flat/transform.js'; import {CANVAS_LINE_DASH} from '../../has.js'; import {isEmpty} from '../../obj.js'; @@ -715,7 +715,7 @@ CanvasReplay.prototype.replay_ = function( 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 parts = _ol_geom_flat_textpath_.lineString( + const parts = drawTextOnPath( pixelCoordinates, begin, end, 2, text, measure, startM, maxAngle); if (parts) { let c, cc, chars, label, part; diff --git a/test/spec/ol/geom/flat/textpath.test.js b/test/spec/ol/geom/flat/textpath.test.js index 4b63c0bd02..302f312b05 100644 --- a/test/spec/ol/geom/flat/textpath.test.js +++ b/test/spec/ol/geom/flat/textpath.test.js @@ -1,4 +1,4 @@ -import _ol_geom_flat_textpath_ from '../../../../../src/ol/geom/flat/textpath.js'; +import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js'; import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js'; describe('textpath', function() { @@ -16,27 +16,27 @@ describe('textpath', function() { it('center-aligns text on a horizontal line', function() { const startM = 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity); expect(instructions).to.eql([[40, 0, 5, 0, 'foo']]); }); it('left-aligns text on a horizontal line', function() { - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo', measure, 0, Infinity); expect(instructions).to.eql([[5, 0, 5, 0, 'foo']]); }); it('right-aligns text on a horizontal line', function() { const startM = 100 - 30; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity); expect(instructions).to.eql([[75, 0, 5, 0, 'foo']]); }); it('draws text on a vertical line', function() { const startM = 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( vertical, 0, vertical.length, 2, 'foo', measure, startM, Infinity); const a = 90 * Math.PI / 180; expect(instructions).to.eql([[0, 40, 5, a, 'foo']]); @@ -44,7 +44,7 @@ describe('textpath', function() { it('draws text on a diagonal line', function() { const startM = Math.sqrt(2) * 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( diagonal, 0, diagonal.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(45 * Math.PI / 180); expect(instructions.length).to.be(1); @@ -52,7 +52,7 @@ describe('textpath', function() { it('draws reverse text on a diagonal line', function() { const startM = Math.sqrt(2) * 50 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( reverse, 0, reverse.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(-45 * Math.PI / 180); expect(instructions.length).to.be(1); @@ -60,7 +60,7 @@ describe('textpath', function() { it('renders long text with extrapolation', function() { const startM = 50 - 75; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( horizontal, 0, horizontal.length, 2, 'foo-foo-foo-foo', measure, startM, Infinity); expect(instructions[0]).to.eql([-20, 0, 5, 0, 'foo-foo-foo-foo']); expect(instructions.length).to.be(1); @@ -69,7 +69,7 @@ describe('textpath', function() { it('renders angled text', function() { const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 0, angled.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.eql(45 * Math.PI / 180); expect(instructions[0][4]).to.be('fo'); @@ -80,7 +80,7 @@ describe('textpath', function() { it('respects maxAngle', function() { const length = lineStringLength(angled, 0, angled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 0, angled.length, 2, 'foo', measure, startM, Math.PI / 4); expect(instructions).to.be(null); }); @@ -88,7 +88,7 @@ describe('textpath', function() { it('uses the smallest angle for maxAngleDelta', function() { const length = lineStringLength(reverseangled, 0, reverseangled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( reverseangled, 0, reverseangled.length, 2, 'foo', measure, startM, Math.PI); expect(instructions).to.not.be(undefined); }); @@ -96,7 +96,7 @@ describe('textpath', function() { it('respects the offset option', function() { const length = lineStringLength(angled, 2, angled.length, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 2, angled.length, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(-45 * Math.PI / 180); expect(instructions.length).to.be(1); @@ -105,7 +105,7 @@ describe('textpath', function() { it('respects the end option', function() { const length = lineStringLength(angled, 0, 4, 2); const startM = length / 2 - 15; - const instructions = _ol_geom_flat_textpath_.lineString( + const instructions = drawTextOnPath( angled, 0, 4, 2, 'foo', measure, startM, Infinity); expect(instructions[0][3]).to.be(45 * Math.PI / 180); expect(instructions.length).to.be(1);