diff --git a/examples/GeoJSON.js b/examples/GeoJSON.js index 4d4904ad..c22dd10d 100644 --- a/examples/GeoJSON.js +++ b/examples/GeoJSON.js @@ -79,6 +79,10 @@ requirejs(['../src/WorldWind', return configuration; }; + var callbackFunction = function(layer) { + wwd.addLayer(layer); + }; + var resourcesUrl = "http://worldwindserver.net/webworldwind/data/geojson-data/"; // Polygon test @@ -118,11 +122,11 @@ requirejs(['../src/WorldWind', multiLineStringGeoJSON.load(shapeConfigurationCallback, multiLineStringLayer); wwd.addLayer(multiLineStringLayer); - // GeometryCollection test + // GeometryCollection test with a callback function var geometryCollectionLayer = new WorldWind.RenderableLayer("GeometryCollection"); var geometryCollectionGeoJSON = new WorldWind.GeoJSONParser(resourcesUrl + "GeometryCollectionFeatureTest.geojson"); - geometryCollectionGeoJSON.load(shapeConfigurationCallback, geometryCollectionLayer); - wwd.addLayer(geometryCollectionLayer); + geometryCollectionGeoJSON.load(shapeConfigurationCallback, geometryCollectionLayer, callbackFunction); + // Feature test var featureLayer = new WorldWind.RenderableLayer("Feature - USA"); diff --git a/src/formats/geojson/GeoJSONParser.js b/src/formats/geojson/GeoJSONParser.js index 280b1270..781005ae 100644 --- a/src/formats/geojson/GeoJSONParser.js +++ b/src/formats/geojson/GeoJSONParser.js @@ -217,14 +217,19 @@ define(['../../error/ArgumentError', * @param {RenderableLayer} layer A {@link RenderableLayer} to hold the shapes created for each GeoJSON * geometry. If null, a new layer is created and assigned to this object's [layer]{@link GeoJSONParser#layer} * property. + * @param {Fcuntion} callbackFunction An optional function that will be executed when the GeoJSON is fully + * parsed and all the renderables have been added to the layer. It will pass, as parameter, the layer to which + * the callback belongs to. */ - GeoJSONParser.prototype.load = function ( shapeConfigurationCallback, layer) { + GeoJSONParser.prototype.load = function ( shapeConfigurationCallback, layer, callbackFunction) { if (shapeConfigurationCallback) { this._shapeConfigurationCallback = shapeConfigurationCallback; } - + if (callbackFunction) { + this._callbackFunction = callbackFunction; + } this._layer = layer || new RenderableLayer(); if (this.isDataSourceJson()){ @@ -326,6 +331,10 @@ define(['../../error/ArgumentError', Logger.logMessage(Logger.LEVEL_SEVERE, "GeoJSON", "parse", "missingGeoJSONType")); } + + if (this._callbackFunction && typeof this._callbackFunction === "function") { + this._callbackFunction(this.layer); + } } } };