MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / removeGraphics

Method removeGraphics

src/openlayers/overlay/Graphic.js:346–373  ·  view source on GitHub ↗

* @function Graphic.prototype.removeGraphics * @description 删除要素数组,默认将删除所有要素。 * @param {Array. } [graphics] - 删除的 graphics 数组。

(graphics = null)

Source from the content-addressed store, hash-verified

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

Callers 6

clearMethod · 0.95
GraphicSpec.jsFile · 0.45
GraphicLayer.jsFile · 0.45

Calls 2

updateMethod · 0.95
indexOfMethod · 0.80

Tested by

no test coverage detected