Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Marker TextDesc cal error when textName Is multi line text #2094

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/util/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export function isPathSymbol(symbol) {
export const DYNAMIC_SYMBOL_PROPS = [
'markerWidth', 'markerHeight', 'markerHorizontalAlignment', 'markerVerticalAlignment', 'markerDx', 'markerDy', 'markerRotation',
'textName',
'textSize', 'textDx', 'textDy', 'textVerticalAlignment', 'textHorizontalAlignment', 'textRotation'
'textSize', 'textDx', 'textDy', 'textVerticalAlignment', 'textHorizontalAlignment', 'textRotation', 'textWrapWidth'
];

export const SIZE_SYMBOL_PROPS = [
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export function splitTextToRow(text, style) {
size = stringLength(text, font, style['textSize']),
textWidth = size['width'],
textHeight = size['height'],
wrapChar = style['textWrapCharacter'],
wrapChar = style['textWrapCharacter'] || '\n',
textRows = [];
let wrapWidth = style['textWrapWidth'];
if (!wrapWidth || wrapWidth > textWidth) {
Expand Down
34 changes: 34 additions & 0 deletions test/geometry/symbol/SymbolTextSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,38 @@ describe('SymbolTextSpec', function () {
// expect(geometry.getTextDesc().size.width).to.be.eql(0);
expect(geometry.getTextDesc().size.height).to.be.eql(textSize);
});

it('#2093 text symbol TextDesc rows when textName Is multi line text ', function () {
function líneasNuevas(s) {
return s.split('').join('\n').replace(/([\ud800-\udfff])\n([\ud800-\udfff])/g, '$1$2');
}
const textNames = ['甲子', '乙丑', '丙寅', '丁卯', '戊辰', '己巳'].map(name => {
return líneasNuevas(name + '行都司');
});
textNames.push('大家好');
textNames.push('Hello\nWorld');
const randomName = Math.ceil(Math.random() * 100000) + '';
textNames.push(líneasNuevas(randomName));

var v = new maptalks.VectorLayer('v', { 'drawImmediate': true }).addTo(map);
textNames.forEach(textName => {
v.clear();
const lineRows = textName.split('\n');
var geometry = new maptalks.Marker(center.copy(), {
symbol: {
'textName': textName,
"textFaceName": "楷体",
"textSize": { "stops": [[8, 14], [20, 32]] },
"textFill": "#000",
"textOpacity": 1,
"textHaloFill": [1, 1, 1, 0.9],
"textHaloRadius": 1,
"textHorizontalAlignment": "middle",
"textVerticalAlignment": "middle"
}
});
v.addGeometry(geometry);
expect(geometry.getTextDesc().rows.length).to.be.eql(lineRows.length);
});
});
});