Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly update layer control widget when visible layers change #702

Closed
wants to merge 32 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
78e92dc
Correctly update layer control widget when visible layers change
duckblaster Mar 21, 2017
9f97bc1
Better fix for layer control widget
duckblaster Mar 21, 2017
aaf4a96
Fix missing semicolon
duckblaster Mar 21, 2017
50961bb
Merge branch 'develop' into fix-layer-control-widget
tmcgee Apr 12, 2017
edc4559
Merge branch 'develop' into fix-layer-control-widget
tmcgee Apr 13, 2017
9d39bf4
Merge branch 'develop' into fix-layer-control-widget
DavidSpriggs May 24, 2017
bfc9710
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jun 14, 2017
e32c6c6
Merge branch 'develop' into fix-layer-control-widget
DavidSpriggs Jun 20, 2017
cbde577
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jun 28, 2017
1d11c7b
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jul 3, 2017
80584f1
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jul 8, 2017
5bd1277
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jul 10, 2017
bae4ec9
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jul 22, 2017
2bbc4c0
Merge branch 'develop' into fix-layer-control-widget
tmcgee Aug 5, 2017
b7dfefc
Merge branch 'develop' into fix-layer-control-widget
tmcgee Aug 5, 2017
7a9735a
Merge branch 'develop' into fix-layer-control-widget
tmcgee Aug 7, 2017
7c6432f
Merge branch 'develop' into fix-layer-control-widget
tmcgee Aug 23, 2017
bb2a387
Merge branch 'develop' into fix-layer-control-widget
tmcgee Sep 8, 2017
85d88dc
Merge branch 'develop' into fix-layer-control-widget
tmcgee Sep 8, 2017
c4a6ac5
Merge branch 'develop' into fix-layer-control-widget
tmcgee Sep 12, 2017
f791b20
Merge branch 'develop' into fix-layer-control-widget
tmcgee Sep 18, 2017
42aa7f2
Merge branch 'develop' into fix-layer-control-widget
tmcgee Sep 29, 2017
baa3cfd
Merge branch 'develop' into fix-layer-control-widget
tmcgee Oct 21, 2017
d846350
Merge branch 'develop' into fix-layer-control-widget
tmcgee Nov 2, 2017
ca71139
Merge branch 'develop' into fix-layer-control-widget
tmcgee Nov 5, 2017
859a9f4
Merge branch 'develop' into fix-layer-control-widget
tmcgee Nov 8, 2017
3e755f9
Merge branch 'develop' into fix-layer-control-widget
tmcgee Nov 28, 2017
93ebd2e
Merge branch 'develop' into fix-layer-control-widget
tmcgee Dec 9, 2017
7346011
Merge branch 'develop' into fix-layer-control-widget
tmcgee Dec 24, 2017
1dc0f0f
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jan 7, 2018
4f19453
Merge branch 'develop' into fix-layer-control-widget
tmcgee Jan 20, 2018
6e2bbee
Merge branch 'develop' into fix-layer-control-widget
tmcgee Feb 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions viewer/js/gis/dijit/LayerControl/controls/Dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ define([
if (this.layer.layerInfos.length > 1 && this.controlOptions.sublayers) {
// we have sublayer controls
this._hasSublayers = true;
this._visLayersHandler = aspect.after(this.layer, 'setVisibleLayers', lang.hitch(this, '_onSetVisibleLayers'), true);
this._aspectSetVisibleLayers();
}
},
// create sublayers and legend
Expand Down Expand Up @@ -180,12 +180,16 @@ define([
// i.e. layer 3 (the group) is not in array but it's sublayers are; sublayers will show
// so check and if group is off also remove the sublayers
var layer = this.layer,
setLayers = [];
setLayers = [],
visibleLayers = [];
array.forEach(query('.' + layer.id + '-layerControlSublayerCheck'), function (i) {
if (domAttr.get(i, 'data-checked') === 'checked') {
setLayers.push(parseInt(domAttr.get(i, 'data-sublayer-id'), 10));
visibleLayers.push(parseInt(domAttr.get(i, 'data-sublayer-id'), 10));
}
});
array.forEach(visibleLayers, function (visibleLayer) {
setLayers.push(visibleLayer);
});
array.forEach(layer.layerInfos, function (info) {
if (info.subLayerIds !== null && array.indexOf(setLayers, info.id) === -1) {
array.forEach(info.subLayerIds, function (sub) {
Expand All @@ -204,23 +208,46 @@ define([
layer.refresh();
topic.publish('layerControl/setVisibleLayers', {
id: layer.id,
visibleLayers: setLayers
visibleLayers: visibleLayers
});
// set aspect handler
this._visLayersHandler = aspect.after(this.layer, 'setVisibleLayers', lang.hitch(this, '_onSetVisibleLayers'), true);
this._aspectSetVisibleLayers();
},
_onSetVisibleLayers: function (visLayers) {
var visibleIds = [];
array.forEach(this.layer.layerInfos, function (info) {
if (array.indexOf(visLayers, info.id) !== -1) {
visibleIds.push(info.id);
}
if (info.parentLayerId !== -1 && array.indexOf(visibleIds, info.parentLayerId) === -1) {
visibleIds.push(info.parentLayerId);
_aspectSetVisibleLayers: function () {
var self = this;
this._visLayersHandler = aspect.around(this.layer, 'setVisibleLayers', lang.hitch(this, function (originalSetVisibleLayers) {
return function (visibleLayers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be return lang.hitch(this, function(visibleLayers) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And eliminate the use of self (for consistency)

var setLayers = lang.hitch(self, self._visibleLayersToSetLayers)(visibleLayers);
originalSetVisibleLayers.apply(this, [setLayers]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line shouldn't pass the modified setLayers, it should pass the visibleLayers that the api expects to receive.

lang.hitch(self, self._onSetVisibleLayers)(visibleLayers);
};
}));
},
_visibleLayersToSetLayers: function (visibleLayers) {
var layer = this.layer,
setLayers = [];
array.forEach(visibleLayers, function (visibleLayer) {
setLayers.push(visibleLayer);
});
array.forEach(layer.layerInfos, function (info) {
if (info.subLayerIds !== null && array.indexOf(setLayers, info.id) === -1) {
array.forEach(info.subLayerIds, function (sub) {
if (array.indexOf(setLayers, sub) !== -1) {
setLayers.splice(array.indexOf(setLayers, sub), 1);
}
});
} else if (info.subLayerIds !== null && array.indexOf(setLayers, info.id) !== -1) {
setLayers.splice(array.indexOf(setLayers, info.id), 1);
}
});
if (!setLayers.length) {
setLayers.push(-1);
}
return setLayers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here

},
_onSetVisibleLayers: function (visLayers) {
array.forEach(this._sublayerControls, function (control) {
if (array.indexOf(visibleIds, control.sublayerInfo.id) !== -1) {
if (array.indexOf(visLayers, control.sublayerInfo.id) !== -1) {
control._setSublayerCheckbox(true);
} else {
control._setSublayerCheckbox(false);
Expand Down