From e5186010afe73a855c32eb7c28d7c9c88dc06bb2 Mon Sep 17 00:00:00 2001 From: hu de yi Date: Fri, 25 Jul 2025 15:08:25 +0800 Subject: [PATCH] optimize Geometry updateSymbol --- packages/maptalks/src/geometry/Geometry.ts | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/maptalks/src/geometry/Geometry.ts b/packages/maptalks/src/geometry/Geometry.ts index bdd0369941..32b79a6f0a 100644 --- a/packages/maptalks/src/geometry/Geometry.ts +++ b/packages/maptalks/src/geometry/Geometry.ts @@ -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])) { @@ -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;