MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / removeFeatures

Method removeFeatures

src/openlayers/overlay/theme/Theme.js:211–256  ·  view source on GitHub ↗

* @function Theme.prototype.removeFeatures * @param {(Array. |FeatureVector|Function)} features - 要删除要素的数组或用来过滤的回调函数。 * @description 从专题图中删除要素。这个函数删除所有传递进来的矢量要素。 * 参数中的要素数组中的每一项,必须是已经添加到当前图层中的要素, * 如果无法确定要素数组,则可以调用 removeAllFeatures 来删除所有要素

(features)

Source from the content-addressed store, hash-verified

209 * 删除所有要素后再重新添加。这样效率会更高。
210 */
211 removeFeatures(features) {
212 var me = this;
213 if (!features) {
214 return;
215 }
216 if (features === me.features) {
217 return me.removeAllFeatures();
218 }
219 if (!CommonUtil.isArray(features) && !(typeof features === 'function')) {
220 features = [features];
221 }
222
223 var featuresFailRemoved = [];
224
225 for (var i = 0; i < me.features.length; i++) {
226 var feature = me.features[i];
227
228 //如果我们传入的feature在features数组中没有的话,则不进行删除,
229 //并将其放入未删除的数组中。
230 if (features && typeof features === 'function') {
231 if (features(feature)) {
232 me.features.splice(i--, 1);
233 }
234 } else {
235 var findex = CommonUtil.indexOf(features, feature);
236 if (findex === -1) {
237 featuresFailRemoved.push(feature);
238 } else {
239 me.features.splice(i--, 1);
240 }
241 }
242 }
243 var drawFeatures = [];
244 for (var hex = 0, len = this.features.length; hex < len; hex++) {
245 feature = this.features[hex];
246 drawFeatures.push(feature);
247 }
248 this.features = [];
249 this.addFeatures(drawFeatures);
250 //绘制专题要素
251 if (this.renderer) {
252 this.redrawThematicFeatures(this.map.getView().calculateExtent());
253 }
254 var succeed = featuresFailRemoved.length == 0 ? true : false;
255 this.dispatchEvent({type: "featuresremoved", value: {features: featuresFailRemoved, succeed: succeed}});
256 }
257
258 /**
259 * @function Theme.prototype.removeAllFeatures

Callers 1

destroyFeaturesMethod · 0.95

Calls 6

addFeaturesMethod · 0.95
indexOfMethod · 0.80
pushMethod · 0.80
getViewMethod · 0.80
removeAllFeaturesMethod · 0.45

Tested by

no test coverage detected