Skip to content

optimize Geometry updateSymbol #2585

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

Merged
merged 1 commit into from
Jul 28, 2025
Merged
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
26 changes: 23 additions & 3 deletions packages/maptalks/src/geometry/Geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,26 @@ export class Geometry extends JSONAble(Eventable(Handlerable(Class))) {
return this;
}
let s = this._getSymbol();
const propsIsArray = Array.isArray(props);
if (!s) {
//generate defalut empty symbol
s = {};
if (propsIsArray) {
s = props.map(() => { return {} });
}
}
if (!Array.isArray(s) && propsIsArray) {
//only read first element of props
props = props[0] || {};
}
if (Array.isArray(s)) {
if (!Array.isArray(props)) {
throw new Error('Parameter of updateSymbol is not an array.');
if (!propsIsArray) {
//auto generate array symbol
props = [props];
while (props.length < s.length) {
props.push({});
}
// throw new Error('Parameter of updateSymbol is not an array.');
}
for (let i = 0; i < props.length; i++) {
if (isTextSymbol(props[i])) {
Expand All @@ -509,7 +526,10 @@ export class Geometry extends JSONAble(Eventable(Handlerable(Class))) {
}
}
} else if (Array.isArray(props)) {
throw new Error('Geometry\'s symbol is not an array to update.');
// throw new Error('Geometry\'s symbol is object but the update symbol is array.');
console.error('Geometry\'s symbol is object but the update symbol is array.');
console.error('Geometry\'s symbol and update symbol:', s, props);
return this;
} else {
if (isTextSymbol(s)) {
delete this._textDesc;
Expand Down