Skip to content

Commit

Permalink
Turn all sublayers on/off affecting other layers fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
btfou committed Oct 1, 2014
1 parent bcf5c87 commit 50aff39
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
4 changes: 0 additions & 4 deletions viewer/js/gis/dijit/LayerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ define([
}, this);
this._checkReorder();
}));



window.map = this.map;
},
// create layer control and add to appropriate _container
_addControl: function (layerInfo, LayerControl) {
Expand Down
19 changes: 9 additions & 10 deletions viewer/js/gis/dijit/LayerControl/controls/Dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ define([
_layerType: 'overlay', // constant
_esriLayerType: 'dynamic', // constant

_sublayerControls: [], // sublayer/folder controls
//_sublayerControls: [], // sublayer/folder controls
_hasSublayers: false, // true when sublayers created

constructor: function () {
this._sublayerControls = [];
},

_layerTypePreInit: function () {
if (this.layer.layerInfos.length > 1 && this.controlOptions.sublayers) {
// we have sublayer controls
Expand Down Expand Up @@ -83,15 +87,10 @@ define([

// toggle all sublayers on/off
_toggleAllSublayers: function (state) {
if (state) {
var visLayers = [];
array.forEach(this.layer.layerInfos, function (info) {
visLayers.push(info.id);
});
this.layer.setVisibleLayers(visLayers);
} else {
this.layer.setVisibleLayers([-1]);
}
array.forEach(this._sublayerControls, function (control) {
control._setSublayerCheckbox(state);
});
this._setVisibleLayers();
},

// add folder/sublayer controls per layer.layerInfos
Expand Down
47 changes: 30 additions & 17 deletions viewer/js/gis/dijit/LayerControl/controls/_Control.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/_base/array',
//'dojo/_base/array',
'dojo/on',
'dojo/topic',
'dojo/dom-construct',
Expand All @@ -14,7 +14,7 @@ define([
], function (
declare,
lang,
array,
//array,
on,
topic,
domConst,
Expand Down Expand Up @@ -78,24 +78,24 @@ define([

var layer = this.layer,
controlOptions = this.controlOptions;

// set checkbox
this._setLayerCheckbox(layer, this.checkNode);

// wire up layer visibility
on(this.checkNode, 'click', lang.hitch(this, '_setLayerVisibility', layer, this.checkNode));

// set title
html.set(this.labelNode, this.layerTitle);

// wire up updating indicator
layer.on('update-start', lang.hitch(this, function () {
domStyle.set(this.layerUpdateNode, 'display', 'inline-block'); //font awesome display
}));
layer.on('update-end', lang.hitch(this, function () {
domStyle.set(this.layerUpdateNode, 'display', 'none');
}));

// create layer menu
this.layerMenu = new LayerMenu({
control: this,
Expand All @@ -104,13 +104,13 @@ define([
leftClickToOpen: true
});
this.layerMenu.startup();

// if layer has scales set
if (layer.minScale !== 0 || layer.maxScale !== 0) {
this._checkboxScaleRange();
this._scaleRangeHandler = layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange'));
}

// if layer scales change
this.layer.on('scale-range-change', lang.hitch(this, function () {
if (layer.minScale !== 0 || layer.maxScale !== 0) {
Expand All @@ -124,10 +124,10 @@ define([
}
}
}));

// a function in each control widget for layer type specifics like legends and such
this._layerTypeInit();

// show expandNode
// no harm if click handler wasn't created
if (controlOptions.expanded && controlOptions.sublayers) {
Expand Down Expand Up @@ -219,13 +219,26 @@ define([
},

// anything the widget may need to do after update
_updateEnd: function () {
if (this._esriLayerType === 'dynamic' && this._sublayerControls) {
array.forEach(this._sublayerControls, function (control) {
var checked = (array.indexOf(this.layer.visibleLayers, control.sublayerInfo.id) !== -1) ? true : false;
control._setSublayerCheckbox(checked, control.checkNode);
_updateEnd: function () {
// how to handle external layer.setVisibleLayers() ???
/*if (this._esriLayerType === 'dynamic' && this._sublayerControls) {
if (this.layer.visibleLayers.length === 1 && this.layer.visibleLayers[0] !== -1) {
return;
}
var visLayers = [];
array.forEach(this.layer.visibleLayers, function (id) {
visLayers.push(id);
var info = this.layer.layerInfos[id];
if (info.parentLayerId !== -1) {
visLayers.push(info.parentLayerId);
}
}, this);
}
array.forEach(this._sublayerControls, function (control) {
if (array.indexOf(visLayers, control.sublayerInfo.id) !== -1) {
control._setSublayerCheckbox(true);
}
});
}*/

// anything needing before update layer state
if (!this._layerState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ define([

// set checkbox based on layer so it's always in sync
_setSublayerCheckbox: function (checked, checkNode) {
checkNode = checkNode || this.checkNode;
if (checked) {
domAttr.set(checkNode, 'data-checked', 'checked');
domClass.replace(checkNode, 'fa-check-square-o', 'fa-square-o');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ define([

// set checkbox based on layer so it's always in sync
_setSublayerCheckbox: function (checked, checkNode) {
checkNode = checkNode || this.checkNode;
if (checked) {
domAttr.set(checkNode, 'data-checked', 'checked');
domClass.replace(checkNode, 'fa-check-square-o', 'fa-square-o');
Expand Down

1 comment on commit 50aff39

@btfou
Copy link
Contributor Author

@btfou btfou commented on 50aff39 Oct 1, 2014

Choose a reason for hiding this comment

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

When toggle all dynamic sublayers on/off the check state of the sublayer checkboxes are all set to checked or unchecked, and then setVisibleLayers() is called based on the checkbox states the same as if user toggled a sublayer.

To prevent other layers from being affected by toggling all sublayers of other dynamic controls the _sublayerControls array is assigned in the constructor of Dynamic.js.

Dynamic layer controls are no longer aware if layer.setVisibleLayers() is called externally. A solution is developing but will require some more work.

Please sign in to comment.