Skip to content

Instantly share code, notes, and snippets.

@yohanboniface
Created July 26, 2012 13:56
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 yohanboniface/3182172 to your computer and use it in GitHub Desktop.
Save yohanboniface/3182172 to your computer and use it in GitHub Desktop.
L.LazyGeoJSON = L.GeoJSON.extend({
initialize: function (geojson_getter, options) {
L.Util.setOptions(this, options);
this._layers = {};
this.geojson_getter = geojson_getter;
this._geojson = null;
},
onAdd: function (map, insertAtTheBottom) {
// Fetch geojson only at first call
if(this._geojson === null) {
var geojson = this.geojson_getter();
this.addData(geojson);
this._geojson = geojson;
}
// Call parent
L.FeatureGroup.prototype.onAdd.call(this, map, insertAtTheBottom);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment