* @function GraphicLayer.prototype.removeGraphics * @description 删除要素数组,默认删除所有要素。 * @param {Array. } [graphics=null] - 删除的 graphics 数组。
(graphics = null)
| 190 | * @param {Array.<Graphic>} [graphics=null] - 删除的 graphics 数组。 |
| 191 | */ |
| 192 | removeGraphics(graphics = null) { |
| 193 | //当 graphics 为 null 、为空数组,或 === this.graphics,则清除所有要素 |
| 194 | if (!graphics || graphics.length === 0 || graphics === this.graphics) { |
| 195 | this.graphics.length = 0; |
| 196 | this.update(); |
| 197 | return; |
| 198 | } |
| 199 | if (!CommonUtil.isArray(graphics)) { |
| 200 | graphics = [graphics]; |
| 201 | } |
| 202 | |
| 203 | for (let i = graphics.length - 1; i >= 0; i--) { |
| 204 | let graphic = graphics[i]; |
| 205 | |
| 206 | //如果我们传入的grapchic在graphics数组中没有的话,则不进行删除, |
| 207 | //并将其放入未删除的数组中。 |
| 208 | let findex = CommonUtil.indexOf(this.graphics, graphic); |
| 209 | |
| 210 | if (findex === -1) { |
| 211 | continue; |
| 212 | } |
| 213 | this.graphics.splice(findex, 1); |
| 214 | } |
| 215 | |
| 216 | //删除完成后重新设置 setGraphics,以更新 |
| 217 | this.update(); |
| 218 | }, |
| 219 | |
| 220 | /** |
| 221 | * @function GraphicLayer.prototype.setStyle |