-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
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 9f97bc1
Better fix for layer control widget
duckblaster aaf4a96
Fix missing semicolon
duckblaster 50961bb
Merge branch 'develop' into fix-layer-control-widget
tmcgee edc4559
Merge branch 'develop' into fix-layer-control-widget
tmcgee 9d39bf4
Merge branch 'develop' into fix-layer-control-widget
DavidSpriggs bfc9710
Merge branch 'develop' into fix-layer-control-widget
tmcgee e32c6c6
Merge branch 'develop' into fix-layer-control-widget
DavidSpriggs cbde577
Merge branch 'develop' into fix-layer-control-widget
tmcgee 1d11c7b
Merge branch 'develop' into fix-layer-control-widget
tmcgee 80584f1
Merge branch 'develop' into fix-layer-control-widget
tmcgee 5bd1277
Merge branch 'develop' into fix-layer-control-widget
tmcgee bae4ec9
Merge branch 'develop' into fix-layer-control-widget
tmcgee 2bbc4c0
Merge branch 'develop' into fix-layer-control-widget
tmcgee b7dfefc
Merge branch 'develop' into fix-layer-control-widget
tmcgee 7a9735a
Merge branch 'develop' into fix-layer-control-widget
tmcgee 7c6432f
Merge branch 'develop' into fix-layer-control-widget
tmcgee bb2a387
Merge branch 'develop' into fix-layer-control-widget
tmcgee 85d88dc
Merge branch 'develop' into fix-layer-control-widget
tmcgee c4a6ac5
Merge branch 'develop' into fix-layer-control-widget
tmcgee f791b20
Merge branch 'develop' into fix-layer-control-widget
tmcgee 42aa7f2
Merge branch 'develop' into fix-layer-control-widget
tmcgee baa3cfd
Merge branch 'develop' into fix-layer-control-widget
tmcgee d846350
Merge branch 'develop' into fix-layer-control-widget
tmcgee ca71139
Merge branch 'develop' into fix-layer-control-widget
tmcgee 859a9f4
Merge branch 'develop' into fix-layer-control-widget
tmcgee 3e755f9
Merge branch 'develop' into fix-layer-control-widget
tmcgee 93ebd2e
Merge branch 'develop' into fix-layer-control-widget
tmcgee 7346011
Merge branch 'develop' into fix-layer-control-widget
tmcgee 1dc0f0f
Merge branch 'develop' into fix-layer-control-widget
tmcgee 4f19453
Merge branch 'develop' into fix-layer-control-widget
tmcgee 6e2bbee
Merge branch 'develop' into fix-layer-control-widget
tmcgee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) { | ||
|
@@ -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) { | ||
var setLayers = lang.hitch(self, self._visibleLayersToSetLayers)(visibleLayers); | ||
originalSetVisibleLayers.apply(this, [setLayers]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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) {
There was a problem hiding this comment.
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)