Skip to content

Commit

Permalink
feat(layer-selector): remove/add feature layer placeholder toggle bas…
Browse files Browse the repository at this point in the history
…ed on wms presence

If there is at least one wms layer, adds a placeholder toggle to feature layers to have
two columns of toggles in layer selector. WMS layers have visibility and query toggles.
  • Loading branch information
AleksueiR committed Apr 29, 2015
1 parent 216f3ce commit be7e596
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/js/RAMP/Modules/filterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,70 @@ define([
topic.subscribe(EventManager.Map.ZOOM_END, function () {
setLayerOffScaleStates();
});

// subscribe to Layer added event which is fired every time a layer is added to the map through layer loader
topic.subscribe(EventManager.LayerLoader.LAYER_ADDED, function (args) {
updateLayersStateMatrix(args.layerCounts, true);
});

// on each remove check if there are still wms layers in the layer list
topic.subscribe(EventManager.LayerLoader.LAYER_REMOVED, function (args) {
updateLayersStateMatrix(args.layerCounts, false);
});
}

function updateLayersStateMatrix(layerCounts, isLayerAdded) {
var featureLayerGroup = layerGroups[GlobalStorage.layerType.feature],
wmsLayerGroup = layerGroups[GlobalStorage.layerType.wms];

if (layerCounts.wms === 1 && isLayerAdded) {

featureLayerGroup.layerItems.forEach(function (layerItem) {
LayerItem.addStateMatrixParts(layerItem.stateMatrix, LayerItem.partTypes.TOGGLES,
[
LayerItem.toggles.PLACEHOLDER
],
[
LayerItem.state.DEFAULT,
LayerItem.state.UPDATING,
LayerItem.state.OFF_SCALE
]
);

layerItem.refresh();
});

wmsLayerGroup.layerItems.forEach(function (layerItem) {
LayerItem.addStateMatrixParts(layerItem.stateMatrix, LayerItem.partTypes.TOGGLES,
[
LayerItem.toggles.QUERY
],
[
LayerItem.state.DEFAULT,
LayerItem.state.UPDATING,
LayerItem.state.OFF_SCALE
]
);

layerItem.refresh();
});

} else if (layerCounts.wms === 0 && !isLayerAdded) {
featureLayerGroup.layerItems.forEach(function (layerItem) {
LayerItem.removeStateMatrixParts(layerItem.stateMatrix, LayerItem.partTypes.TOGGLES,
[
LayerItem.toggles.PLACEHOLDER
],
[
LayerItem.state.DEFAULT,
LayerItem.state.UPDATING,
LayerItem.state.OFF_SCALE
]
);

layerItem.refresh();
});
}
}

function getStateMatrixTemplate(layerType, layerRamp) {
Expand Down

0 comments on commit be7e596

Please sign in to comment.