Skip to content

Commit

Permalink
let filter return array, fix #881
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhenn committed Apr 5, 2019
1 parent 8b2bffd commit e01a13b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/layer/OverlayLayer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { GEOJSON_TYPES } from '../core/Constants';
import { isNil, UID, isObject } from '../core/util';
import Extent from '../geo/Extent';
import { Geometry, GeometryCollection, LineString, Curve } from '../geometry';
import { Geometry, LineString, Curve } from '../geometry';
import { isFunction } from '../core/util';
import { createFilter, getFilterFeature } from '@maptalks/feature-filter';
import Layer from './Layer';
import GeoJSON from '../geometry/GeoJSON';

Expand Down Expand Up @@ -152,8 +154,18 @@ class OverlayLayer extends Layer {
* @param {*} [context=undefined] - Function's context, value to use as this when executing function.
* @return {GeometryCollection} A GeometryCollection with all the geometries that pass the test
*/
filter() {
return GeometryCollection.prototype.filter.apply(this, arguments);
filter(fn, context) {
const selected = [];
const isFn = isFunction(fn);
const filter = isFn ? fn : createFilter(fn);

this.forEach(geometry => {
const g = isFn ? geometry : getFilterFeature(geometry);
if (context ? filter.call(context, g) : filter(g)) {
selected.push(geometry);
}
}, this);
return selected;
}

/**
Expand Down

0 comments on commit e01a13b

Please sign in to comment.