GeoJson Callback

Implementation of callback for GeoJSON with a sample
This commit is contained in:
GabrielePrestifilippo 2016-05-18 23:09:32 +02:00
parent 66d7086f24
commit fdeee2dcdc
2 changed files with 18 additions and 5 deletions

View File

@ -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");

View File

@ -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);
}
}
}
};