Skip to content

Commit

Permalink
feat(layer-loader): add layer_removed event
Browse files Browse the repository at this point in the history
LayerLoader now fires two events: LAYER_ADDED when it adds a layer to the map, and
LAYER_REMOVED when it removes a layer from the map (the layer might still be present in
the layer selector - an errored layer for example - as it's removed from the map).
These events can be used to determine how many layers of each kind are loaded at the moment.
  • Loading branch information
AleksueiR committed Apr 23, 2015
1 parent 7028b25 commit cd1cb89
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/js/RAMP/Modules/eventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,30 @@ define([],
LAYER_LOADED: "layerLoader/layer-loaded",

/**
* Indicates that a map layer has been added to the layer selector
* Indicates that a map layer has been added to the layer selector. This means the LayerLoader has added a layer to the map.
*
* @event LayerLoader.LAYER_ADDED
* @for LayerLoader
* @param event {Object}
* @param event.layer {Object} layer object that has been added
* @param event.layerCounts {Object} layer counts
*
*/
LAYER_ADDED: "layerLoader/layer-added",

/**
* Indicates that a map layer has been removed to the layer selector. This means the LayerLoader has removed a layer from the map.
* When a layer errors, it's removed from the map, but it might still be in the layer selector in the error state.
*
* @event LayerLoader.LAYER_REMOVED
* @for LayerLoader
* @param event {Object}
* @param event.layer {Object} layer object that has been added
* @param event.layerCounts {Object} layer counts
*
*/
LAYER_REMOVED: "layerLoader/layer-removed",

/**
* Indicates that a map layer has updated. This means the data it is showing is visible and up-to-date
*
Expand Down
9 changes: 6 additions & 3 deletions src/js/RAMP/Modules/layerLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ define([
//object to make state decisions
map.addLayer(layer, insertIdx);

// publish LAYER_ADDED event for every user-added layer
topic.publish(EventManager.LayerLoader.LAYER_ADDED, { layer: layer });

//derive initial state
switch (layer.ramp.load.state) {
case "loaded":
Expand Down Expand Up @@ -348,6 +345,9 @@ define([
}
break;
}

// publish LAYER_ADDED event for every added layer
topic.publish(EventManager.LayerLoader.LAYER_ADDED, { layer: layer, layerCounts: RAMP.layerCounts });
}

return {
Expand Down Expand Up @@ -514,6 +514,9 @@ define([
configCollection.splice(configIdx, 1);

RAMP.layerRegistry[evt.layerId] = undefined;

// publish LAYER_REMOVED event for every removed layer
topic.publish(EventManager.LayerLoader.LAYER_REMOVED, { layer: layer, layerCounts: RAMP.layerCounts });
},

/**
Expand Down

0 comments on commit cd1cb89

Please sign in to comment.