Skip to content

Commit c8510ae

Browse files
authored
fix Marker TextDesc cal error when textName Is multi line text (#2094)
* fix Marker TextDesc cal error when textName Is multi line text * fix typo
1 parent 053bdf8 commit c8510ae

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/core/util/marker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export function isPathSymbol(symbol) {
310310
export const DYNAMIC_SYMBOL_PROPS = [
311311
'markerWidth', 'markerHeight', 'markerHorizontalAlignment', 'markerVerticalAlignment', 'markerDx', 'markerDy', 'markerRotation',
312312
'textName',
313-
'textSize', 'textDx', 'textDy', 'textVerticalAlignment', 'textHorizontalAlignment', 'textRotation'
313+
'textSize', 'textDx', 'textDy', 'textVerticalAlignment', 'textHorizontalAlignment', 'textRotation', 'textWrapWidth'
314314
];
315315

316316
export const SIZE_SYMBOL_PROPS = [

src/core/util/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export function splitTextToRow(text, style) {
260260
size = stringLength(text, font, style['textSize']),
261261
textWidth = size['width'],
262262
textHeight = size['height'],
263-
wrapChar = style['textWrapCharacter'],
263+
wrapChar = style['textWrapCharacter'] || '\n',
264264
textRows = [];
265265
let wrapWidth = style['textWrapWidth'];
266266
if (!wrapWidth || wrapWidth > textWidth) {

test/geometry/symbol/SymbolTextSpec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,38 @@ describe('SymbolTextSpec', function () {
8787
// expect(geometry.getTextDesc().size.width).to.be.eql(0);
8888
expect(geometry.getTextDesc().size.height).to.be.eql(textSize);
8989
});
90+
91+
it('#2093 text symbol TextDesc rows when textName Is multi line text ', function () {
92+
function líneasNuevas(s) {
93+
return s.split('').join('\n').replace(/([\ud800-\udfff])\n([\ud800-\udfff])/g, '$1$2');
94+
}
95+
const textNames = ['甲子', '乙丑', '丙寅', '丁卯', '戊辰', '己巳'].map(name => {
96+
return líneasNuevas(name + '行都司');
97+
});
98+
textNames.push('大家好');
99+
textNames.push('Hello\nWorld');
100+
const randomName = Math.ceil(Math.random() * 100000) + '';
101+
textNames.push(líneasNuevas(randomName));
102+
103+
var v = new maptalks.VectorLayer('v', { 'drawImmediate': true }).addTo(map);
104+
textNames.forEach(textName => {
105+
v.clear();
106+
const lineRows = textName.split('\n');
107+
var geometry = new maptalks.Marker(center.copy(), {
108+
symbol: {
109+
'textName': textName,
110+
"textFaceName": "楷体",
111+
"textSize": { "stops": [[8, 14], [20, 32]] },
112+
"textFill": "#000",
113+
"textOpacity": 1,
114+
"textHaloFill": [1, 1, 1, 0.9],
115+
"textHaloRadius": 1,
116+
"textHorizontalAlignment": "middle",
117+
"textVerticalAlignment": "middle"
118+
}
119+
});
120+
v.addGeometry(geometry);
121+
expect(geometry.getTextDesc().rows.length).to.be.eql(lineRows.length);
122+
});
123+
});
90124
});

0 commit comments

Comments
 (0)