Skip to content

Commit 83cce4d

Browse files
authored
optimize Geometry updateSymbol (#2585)
1 parent 2a4b411 commit 83cce4d

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

packages/maptalks/src/geometry/Geometry.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,26 @@ export class Geometry extends JSONAble(Eventable(Handlerable(Class))) {
496496
return this;
497497
}
498498
let s = this._getSymbol();
499+
const propsIsArray = Array.isArray(props);
500+
if (!s) {
501+
//generate defalut empty symbol
502+
s = {};
503+
if (propsIsArray) {
504+
s = props.map(() => { return {} });
505+
}
506+
}
507+
if (!Array.isArray(s) && propsIsArray) {
508+
//only read first element of props
509+
props = props[0] || {};
510+
}
499511
if (Array.isArray(s)) {
500-
if (!Array.isArray(props)) {
501-
throw new Error('Parameter of updateSymbol is not an array.');
512+
if (!propsIsArray) {
513+
//auto generate array symbol
514+
props = [props];
515+
while (props.length < s.length) {
516+
props.push({});
517+
}
518+
// throw new Error('Parameter of updateSymbol is not an array.');
502519
}
503520
for (let i = 0; i < props.length; i++) {
504521
if (isTextSymbol(props[i])) {
@@ -509,7 +526,10 @@ export class Geometry extends JSONAble(Eventable(Handlerable(Class))) {
509526
}
510527
}
511528
} else if (Array.isArray(props)) {
512-
throw new Error('Geometry\'s symbol is not an array to update.');
529+
// throw new Error('Geometry\'s symbol is object but the update symbol is array.');
530+
console.error('Geometry\'s symbol is object but the update symbol is array.');
531+
console.error('Geometry\'s symbol and update symbol:', s, props);
532+
return this;
513533
} else {
514534
if (isTextSymbol(s)) {
515535
delete this._textDesc;

0 commit comments

Comments
 (0)