Skip to content

Instantly share code, notes, and snippets.

@js1568
Last active December 31, 2015 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save js1568/7989256 to your computer and use it in GitHub Desktop.
Save js1568/7989256 to your computer and use it in GitHub Desktop.
Extend L.GeoJson to allow changes to the Feature Group after creation. Useful for dynamic filtering and map layer event processing.
L.GeoJSON.include({
setOptions: function(opts) {
//save original json data
this._data = this._data || this.toGeoJSON();
//destory layer group
this.clearLayers();
L.setOptions(this, opts);
//recreate layer group
this.addData(this._data);
}
});
@js1568
Copy link
Author

js1568 commented Dec 16, 2013

Usage example:

geojson.setOptions({
  filter: function (feature, layer) {
    return feature.properties.category == selectedCat;
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment