* @function Graphic.prototype.removeGraphics * @description 删除要素数组,默认将删除所有要素。 * @param {Array. } [graphics] - 删除的 graphics 数组。
(graphics = null)
| 344 | * @param {Array.<OverlayGraphic>} [graphics] - 删除的 graphics 数组。 |
| 345 | */ |
| 346 | removeGraphics(graphics = null) { |
| 347 | //当 graphics 为 null 、为空数组,或 === this.graphics,则清除所有要素 |
| 348 | if (!graphics || graphics.length === 0 || graphics === this.graphics) { |
| 349 | this.graphics.length = 0; |
| 350 | this.update(); |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | if (!CommonUtil.isArray(graphics)) { |
| 355 | graphics = [graphics]; |
| 356 | } |
| 357 | |
| 358 | for (let i = graphics.length - 1; i >= 0; i--) { |
| 359 | let graphic = graphics[i]; |
| 360 | |
| 361 | //如果我们传入的grapchic在graphics数组中没有的话,则不进行删除, |
| 362 | //并将其放入未删除的数组中。 |
| 363 | let findex = CommonUtil.indexOf(this.graphics, graphic); |
| 364 | |
| 365 | if (findex === -1) { |
| 366 | continue; |
| 367 | } |
| 368 | this.graphics.splice(findex, 1); |
| 369 | } |
| 370 | |
| 371 | //删除完成后重新设置 setGraphics,以更新 |
| 372 | this.update(); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * @function Graphic.prototype.clear |
no test coverage detected