From 4b3156a33a2a583ed140697496e374e0fb7d457c Mon Sep 17 00:00:00 2001 From: AlexThomasEOG Date: Tue, 1 Mar 2016 14:52:41 -0600 Subject: [PATCH 1/4] Control dynamic map service sublayers These changes allow the user to have granular control over each subLayer in a dynamic Map service. Now, instead of having to just use the name of the layer in the map, you can override it to whatever you'd like. you can also redefine the min/max scale of the subLayer. see the layerInfo properties defined here: https://developers.arcgis.com/javascript/jsapi/layerinfo-amd.html In addition to the subLayerInfo support, i've added two other properties to the layerControlLayerInfos object. 1) subLayerInfos : array of layerInfos that should override the dynamic map service's default layerInfos 2) excludedLayers : an array of layer ids that should not be exposed in the map service 3) includeUnspecifiedLayers: boolean --> if true, then all layers in the dynamic map service will be added, not just the ones listed in subLayerInfos. the excludeLayers list will still be honored. layerControlLayerInfos: { //layerIds: [0, 2, 4, 5, 8, 9, 10, 12, 21] includeUnspecifiedLayers : true, excludedLayers : [1,3], subLayerInfos: [{id:0,name:"Layer 1",defaultVisibility:false},{id:2,name:"Layer 2"},{id:4,name:"Layer 3"},{id:5,name:"Layer 4"},{id:8,name:"Layer 5"},{id:9},{id:10},{id:12,name:"Layer 6"},{id:21,name:"Layer 7"}] }, --- viewer/js/config/viewer.js | 5 +- .../dijit/LayerControl/controls/Dynamic.js | 47 +++++++++------ .../LayerControl/controls/_DynamicFolder.js | 9 +++ .../LayerControl/controls/_DynamicSublayer.js | 10 +++- viewer/js/viewer/_MapMixin.js | 59 ++++++++++++++++++- 5 files changed, 109 insertions(+), 21 deletions(-) diff --git a/viewer/js/config/viewer.js b/viewer/js/config/viewer.js index c0ee61064..6547c2ff3 100644 --- a/viewer/js/config/viewer.js +++ b/viewer/js/config/viewer.js @@ -133,7 +133,10 @@ define([ layerIds: [2, 4, 5, 8, 12, 21] }, layerControlLayerInfos: { - layerIds: [0, 2, 4, 5, 8, 9, 10, 12, 21] + //layerIds: [0, 2, 4, 5, 8, 9, 10, 12, 21] + includeUnspecifiedLayers : true, + //excludedLayers : [1,3], + subLayerInfos: [{id:0,name:"Layer 1",defaultVisibility:false},{id:2,name:"Layer 2"},{id:4,name:"Layer 3"},{id:5,name:"Layer 4"},{id:8,name:"Layer 5"},{id:9},{id:10},{id:12,name:"Layer 6"},{id:21,name:"Layer 7"}] }, legendLayerInfos: { layerInfo: { diff --git a/viewer/js/gis/dijit/LayerControl/controls/Dynamic.js b/viewer/js/gis/dijit/LayerControl/controls/Dynamic.js index c872142d7..974139148 100644 --- a/viewer/js/gis/dijit/LayerControl/controls/Dynamic.js +++ b/viewer/js/gis/dijit/LayerControl/controls/Dynamic.js @@ -100,29 +100,40 @@ define([ _createSublayers: function (layer) { // check for single sublayer - if so no sublayer/folder controls if (layer.layerInfos.length > 1) { + var allLayers = array.map(layer.layerInfos, function (l) { + return l.id; + }); array.forEach(layer.layerInfos, lang.hitch(this, function (info) { + // see if there was any override needed from the subLayerInfos array in the controlOptions + var sublayerInfo = array.filter(this.controlOptions.subLayerInfos, function (sli) { + return sli.id === info.id; + }).shift(); + lang.mixin(info, sublayerInfo); var pid = info.parentLayerId, slids = info.subLayerIds, controlId = layer.id + '-' + info.id + '-sublayer-control', control; - if (pid === -1 && slids === null) { - // it's a top level sublayer - control = new DynamicSublayer({ - id: controlId, - control: this, - sublayerInfo: info, - icons: this.icons - }); - domConst.place(control.domNode, this.expandNode, 'last'); - } else if (pid === -1 && slids !== null) { - // it's a top level folder - control = new DynamicFolder({ - id: controlId, - control: this, - sublayerInfo: info, - icons: this.icons - }); - domConst.place(control.domNode, this.expandNode, 'last'); + // it's a top level + if (pid === -1 || allLayers.indexOf(pid) === -1) { + if (slids === null) { + // it's a top level sublayer + control = new DynamicSublayer({ + id: controlId, + control: this, + sublayerInfo: info, + icons: this.icons + }); + domConst.place(control.domNode, this.expandNode, 'last'); + } else if (slids !== null) { + // it's a top level folder + control = new DynamicFolder({ + id: controlId, + control: this, + sublayerInfo: info, + icons: this.icons + }); + domConst.place(control.domNode, this.expandNode, 'last'); + } } else if (pid !== -1 && slids !== null) { // it's a nested folder control = new DynamicFolder({ diff --git a/viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js b/viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js index 184512574..f70c9ca65 100644 --- a/viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js +++ b/viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js @@ -36,6 +36,15 @@ define([ _handlers: [], postCreate: function () { this.inherited(arguments); + // Should the control be visible or hidden (depends on subLayerInfos)? + if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) { + var subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) { + return sli.id; + }); + if (array.indexOf(subLayerInfos, this.sublayerInfo.id) < 0) { + domClass.add(this.domNode, 'layerControlHidden'); + } + } // Should the control be visible or hidden? if (this.control.controlOptions.layerIds && array.indexOf(this.control.controlOptions.layerIds, this.sublayerInfo.id) < 0) { domClass.add(this.domNode, 'layerControlHidden'); diff --git a/viewer/js/gis/dijit/LayerControl/controls/_DynamicSublayer.js b/viewer/js/gis/dijit/LayerControl/controls/_DynamicSublayer.js index c245e5548..e9a7d0fbd 100644 --- a/viewer/js/gis/dijit/LayerControl/controls/_DynamicSublayer.js +++ b/viewer/js/gis/dijit/LayerControl/controls/_DynamicSublayer.js @@ -46,6 +46,15 @@ define([ _handlers: [], postCreate: function () { this.inherited(arguments); + // Should the control be visible or hidden (depends on subLayerInfos)? + if (this.control.controlOptions.subLayerInfos && !this.control.controlOptions.includeUnspecifiedLayers) { + var subLayerInfos = array.map(this.control.controlOptions.subLayerInfos, function (sli) { + return sli.id; + }); + if (array.indexOf(subLayerInfos, this.sublayerInfo.id) < 0) { + domClass.add(this.domNode, 'layerControlHidden'); + } + } // Should the control be visible or hidden? if (this.control.controlOptions.layerIds && array.indexOf(this.control.controlOptions.layerIds, this.sublayerInfo.id) < 0) { domClass.add(this.domNode, 'layerControlHidden'); @@ -56,7 +65,6 @@ define([ if (array.indexOf(this.control.layer.visibleLayers, this.sublayerInfo.id) !== -1) { this._setSublayerCheckbox(true, checkNode); } else { - this._setSublayerCheckbox(false, checkNode); } this._handlers.push(on(checkNode, 'click', lang.hitch(this, function () { diff --git a/viewer/js/viewer/_MapMixin.js b/viewer/js/viewer/_MapMixin.js index ca0e9a8c5..396db7094 100644 --- a/viewer/js/viewer/_MapMixin.js +++ b/viewer/js/viewer/_MapMixin.js @@ -159,9 +159,66 @@ define([ if (idOptions.exclude !== true) { this.identifyLayerInfos.push(idOptions); } + if (layer.layerControlLayerInfos) { + l.on('load', lang.hitch(this, '_applyLayerControlOptions', layer.layerControlLayerInfos)); + } + } + }, + _applyLayerControlOptions: function (controlOptions, args) { + if (typeof controlOptions.includeUnspecifiedLayers === 'undefined' && typeof controlOptions.subLayerInfos === 'undefined' && typeof controlOptions.excludedLayers === 'undefined') { + return; + } + var esriLayerInfos = [], + layer = args.layer; + // Case 1: only show the layers that are explicitly listed + if (!controlOptions.includeUnspecifiedLayers && controlOptions.subLayerInfos && controlOptions.subLayerInfos.length !== 0) { + var subLayerInfos = array.map(controlOptions.subLayerInfos, function (sli) { + return sli.id; + }); + array.forEach(layer.layerInfos, function (li) { + if (array.indexOf(subLayerInfos, li.id) !== -1) { + esriLayerInfos.push(li); + } + }); + // Case 2: show ALL layers except those in the excluded list + } else if (controlOptions.excludedLayers) { + array.forEach(layer.layerInfos, function (li) { + if (array.indexOf(controlOptions.excludedLayers, li.id) === -1) { + esriLayerInfos.push(li); + } + }); + // Case 3: just override the values found in the subLayerInfos + } else if (controlOptions.subLayerInfos) { + // show ALL layers that are in the map service's layerInfos, but take care to override the properties of each subLayerInfo as configured + this._mixinLayerInfos(layer.layerInfos, controlOptions.subLayerInfos); + return; + } + // Finally, if we made use of the esriLayerInfos, make sure to apply all the subLayerInfos that were defined to our new array of esri layer infos + if (controlOptions.subLayerInfos) { + this._mixinLayerInfos(esriLayerInfos, controlOptions.subLayerInfos); + } + layer.layerInfos = esriLayerInfos; + }, + _mixinLayerInfos: function (esriLayerInfos, subLayerInfos) { + // for each of the sublayers, go through the subLayerInfos from the controlOptions and see if defaultVisiblity is set to true or false + // then set each of the layer.layerInfos defaultVisibility appropriately + // assume defaultVisibility is true if it's not defined + if (subLayerInfos && subLayerInfos.length !== 0) { + array.forEach(subLayerInfos, function (sli) { + if (typeof sli.defaultVisibility === 'undefined') { + sli.defaultVisibility = true; + } + }); + array.forEach(esriLayerInfos, function (li) { + var sli = array.filter(subLayerInfos, function (s) { + return s.id === li.id; + }).shift(); + if (sli) { + lang.mixin(li, sli); + } + }); } }, - initMapComplete: function (warnings) { if (warnings && warnings.length > 0) { this.handleError({ From 6627e80a3caf848f36d4480823a717af7045c665 Mon Sep 17 00:00:00 2001 From: AlexThomasEOG Date: Tue, 1 Mar 2016 14:55:04 -0600 Subject: [PATCH 2/4] reverted viewer.js reverted viewer.js --- viewer/js/config/viewer.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/viewer/js/config/viewer.js b/viewer/js/config/viewer.js index 6547c2ff3..c0ee61064 100644 --- a/viewer/js/config/viewer.js +++ b/viewer/js/config/viewer.js @@ -133,10 +133,7 @@ define([ layerIds: [2, 4, 5, 8, 12, 21] }, layerControlLayerInfos: { - //layerIds: [0, 2, 4, 5, 8, 9, 10, 12, 21] - includeUnspecifiedLayers : true, - //excludedLayers : [1,3], - subLayerInfos: [{id:0,name:"Layer 1",defaultVisibility:false},{id:2,name:"Layer 2"},{id:4,name:"Layer 3"},{id:5,name:"Layer 4"},{id:8,name:"Layer 5"},{id:9},{id:10},{id:12,name:"Layer 6"},{id:21,name:"Layer 7"}] + layerIds: [0, 2, 4, 5, 8, 9, 10, 12, 21] }, legendLayerInfos: { layerInfo: { From bf69c2a55a39f79eadef87c580713d73a6306b30 Mon Sep 17 00:00:00 2001 From: AlexThomasEOG Date: Tue, 1 Mar 2016 14:58:15 -0600 Subject: [PATCH 3/4] Reorganize _Control in order to destroy Reorganize _Control in order to destroy --- .../dijit/LayerControl/controls/_Control.js | 93 ++++++++++--------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/viewer/js/gis/dijit/LayerControl/controls/_Control.js b/viewer/js/gis/dijit/LayerControl/controls/_Control.js index b716ffa5a..6dd6a8b08 100644 --- a/viewer/js/gis/dijit/LayerControl/controls/_Control.js +++ b/viewer/js/gis/dijit/LayerControl/controls/_Control.js @@ -44,6 +44,7 @@ define([ if (params.controller) { this.icons = params.controller.icons; } // if not you've got bigger problems + this._handlers = []; }, postCreate: function () { this.inherited(arguments); @@ -67,7 +68,7 @@ define([ if (this.layer.loaded) { this._initialize(); } else { - this.layer.on('load', lang.hitch(this, '_initialize')); + this._handlers.push(this.layer.on('load', lang.hitch(this, '_initialize'))); } }, // initialize the control @@ -80,17 +81,8 @@ define([ 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 if ((controlOptions.noMenu !== true && this.controller.noMenu !== true) || (this.controller.noMenu === true && controlOptions.noMenu === false)) { this.layerMenu = new LayerMenu({ @@ -109,19 +101,6 @@ define([ 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) { - this._checkboxScaleRange(); - this._scaleRangeHandler = layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')); - } else { - this._checkboxScaleRange(); - if (this._scaleRangeHandler) { - this._scaleRangeHandler.remove(); - this._scaleRangeHandler = null; - } - } - })); // a function in each control widget for layer type specifics like legends and such this._layerTypeInit(); // show expandNode @@ -131,30 +110,36 @@ define([ } // esri layer's don't inherit from Stateful // connect to update events to handle "watching" layers - layer.on('update-start', lang.hitch(this, '_updateStart')); - layer.on('update-end', lang.hitch(this, '_updateEnd')); - layer.on('visibility-change', lang.hitch(this, '_visibilityChange')); + this._handlers.push( + on(this.checkNode, 'click', lang.hitch(this, '_setLayerVisibility', layer, this.checkNode)), + layer.on('scale-range-change', lang.hitch(this, '_scaleRangeChange')), + layer.on('update-start', lang.hitch(this, '_updateStart')), + layer.on('update-end', lang.hitch(this, '_updateEnd')), + layer.on('visibility-change', lang.hitch(this, '_visibilityChange')) + ); }, // add on event to expandClickNode _expandClick: function () { - var i = this.icons; - this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, function () { - var expandNode = this.expandNode, - iconNode = this.expandIconNode; - if (domStyle.get(expandNode, 'display') === 'none') { - fx.wipeIn({ - node: expandNode, - duration: 300 - }).play(); - domClass.replace(iconNode, i.collapse, i.expand); - } else { - fx.wipeOut({ - node: expandNode, - duration: 300 - }).play(); - domClass.replace(iconNode, i.expand, i.collapse); - } - })); + this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, '_expandClicked')); + this._handlers.push(this._expandClickHandler); + }, + _expandClicked: function () { + var i = this.icons, + expandNode = this.expandNode, + iconNode = this.expandIconNode; + if (domStyle.get(expandNode, 'display') === 'none') { + fx.wipeIn({ + node: expandNode, + duration: 300 + }).play(); + domClass.replace(iconNode, i.collapse, i.expand); + } else { + fx.wipeOut({ + node: expandNode, + duration: 300 + }).play(); + domClass.replace(iconNode, i.expand, i.collapse); + } }, // removes the icons and cursor:pointer from expandClickNode and destroys expandNode _expandRemove: function () { @@ -206,8 +191,21 @@ define([ domClass.add(node, 'layerControlCheckIconOutScale'); } }, + _scaleRangeChange: function () { + if (this.layer.minScale !== 0 || this.layer.maxScale !== 0) { + this._checkboxScaleRange(); + this._scaleRangeHandler = this.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')); + } else { + this._checkboxScaleRange(); + if (this._scaleRangeHandler) { + this._scaleRangeHandler.remove(); + this._scaleRangeHandler = null; + } + } + }, // anything the widget may need to do before update _updateStart: function () { + domStyle.set(this.layerUpdateNode, 'display', 'inline-block'); //font awesome display // clone a layer state before layer updates for use after update this._layerState = lang.clone({ visible: this.layer.visible, @@ -216,6 +214,7 @@ define([ }, // anything the widget may need to do after update _updateEnd: function () { + domStyle.set(this.layerUpdateNode, 'display', 'none'); // how to handle external layer.setVisibleLayers() ??? // // without topics to get/set sublayer state this will be challenging @@ -234,6 +233,12 @@ define([ if ((r.visible && domAttr.get(this.checkNode, 'data-checked') === 'unchecked') || (!r.visible && domAttr.get(this.checkNode, 'data-checked') === 'checked')) { this._setLayerCheckbox(this.layer, this.checkNode); } + }, + destroy: function () { + this.inherited(arguments); + this._handlers.forEach(function (h) { + h.remove(); + }); } }); return _Control; From 2660f1bf94036cdcceeb211c3d245d1d41db1bc2 Mon Sep 17 00:00:00 2001 From: AlexThomasEOG Date: Mon, 7 Mar 2016 20:12:15 -0600 Subject: [PATCH 4/4] Move layerInfo mixin into the LayerControl widget This change caught some layers at a point where they were already loaded. As a result, we'll need to explicitly set the visibleLayers on the layer --- viewer/js/gis/dijit/LayerControl.js | 74 ++++++++++++++++++++++++++++- viewer/js/viewer/_MapMixin.js | 58 ---------------------- 2 files changed, 73 insertions(+), 59 deletions(-) diff --git a/viewer/js/gis/dijit/LayerControl.js b/viewer/js/gis/dijit/LayerControl.js index 994b4aa44..2c44eb93e 100644 --- a/viewer/js/gis/dijit/LayerControl.js +++ b/viewer/js/gis/dijit/LayerControl.js @@ -200,9 +200,17 @@ define([ }, // create layer control and add to appropriate _container _addControl: function (layerInfo, Control) { + var layer = (typeof layerInfo.layer === 'string') ? this.map.getLayer(layerInfo.layer) : layerInfo.layer; + if (layerInfo.controlOptions && (layerInfo.type === 'dynamic' || layerInfo.type === 'feature')) { + if (layer.loaded) { + this._applyLayerControlOptions(layerInfo.controlOptions, layer); + } else { + layer.on('load', lang.hitch(this, '_applyLayerControlOptions', layer.controlOptions)); + } + } var layerControl = new Control({ controller: this, - layer: (typeof layerInfo.layer === 'string') ? this.map.getLayer(layerInfo.layer) : layerInfo.layer, // check if we have a layer or just a layer id + layer: layer, layerTitle: layerInfo.title, controlOptions: lang.mixin({ noLegend: null, @@ -226,6 +234,70 @@ define([ this.addChild(layerControl, position); } }, + _applyLayerControlOptions: function (controlOptions, layer) { + if (typeof controlOptions.includeUnspecifiedLayers === 'undefined' && typeof controlOptions.subLayerInfos === 'undefined' && typeof controlOptions.excludedLayers === 'undefined') { + return; + } + var esriLayerInfos = []; + // Case 1: only show the layers that are explicitly listed + if (!controlOptions.includeUnspecifiedLayers && controlOptions.subLayerInfos && controlOptions.subLayerInfos.length !== 0) { + var subLayerInfos = array.map(controlOptions.subLayerInfos, function (sli) { + return sli.id; + }); + array.forEach(layer.layerInfos, function (li) { + if (array.indexOf(subLayerInfos, li.id) !== -1) { + esriLayerInfos.push(li); + } + }); + // Case 2: show ALL layers except those in the excluded list + } else if (controlOptions.excludedLayers) { + array.forEach(layer.layerInfos, function (li) { + if (array.indexOf(controlOptions.excludedLayers, li.id) === -1) { + esriLayerInfos.push(li); + } + }); + // Case 3: just override the values found in the subLayerInfos + } else if (controlOptions.subLayerInfos) { + // show ALL layers that are in the map service's layerInfos, but take care to override the properties of each subLayerInfo as configured + this._mixinLayerInfos(layer.layerInfos, controlOptions.subLayerInfos); + this._setSublayerVisibilities(layer); + return; + } + // Finally, if we made use of the esriLayerInfos, make sure to apply all the subLayerInfos that were defined to our new array of esri layer infos + if (controlOptions.subLayerInfos) { + this._mixinLayerInfos(esriLayerInfos, controlOptions.subLayerInfos); + } + layer.layerInfos = esriLayerInfos; + this._setSublayerVisibilities(layer); + }, + _setSublayerVisibilities: function (layer) { + var visibleIds = array.map(array.filter(layer.layerInfos, function (li) { + return li.defaultVisibility; + }), function (l) { + return l.id; + }); + layer.setVisibleLayers(visibleIds); + }, + _mixinLayerInfos: function (esriLayerInfos, subLayerInfos) { + // for each of the sublayers, go through the subLayerInfos from the controlOptions and see if defaultVisiblity is set to true or false + // then set each of the layer.layerInfos defaultVisibility appropriately + // assume defaultVisibility is true if it's not defined + if (subLayerInfos && subLayerInfos.length !== 0) { + array.forEach(subLayerInfos, function (sli) { + if (typeof sli.defaultVisibility === 'undefined') { + sli.defaultVisibility = true; + } + }); + array.forEach(esriLayerInfos, function (li) { + var sli = array.filter(subLayerInfos, function (s) { + return s.id === li.id; + }).shift(); + if (sli) { + lang.mixin(li, sli); + } + }); + } + }, // move control up in controller and layer up in map _moveUp: function (control) { var id = control.layer.id, diff --git a/viewer/js/viewer/_MapMixin.js b/viewer/js/viewer/_MapMixin.js index 396db7094..f265319dd 100644 --- a/viewer/js/viewer/_MapMixin.js +++ b/viewer/js/viewer/_MapMixin.js @@ -159,64 +159,6 @@ define([ if (idOptions.exclude !== true) { this.identifyLayerInfos.push(idOptions); } - if (layer.layerControlLayerInfos) { - l.on('load', lang.hitch(this, '_applyLayerControlOptions', layer.layerControlLayerInfos)); - } - } - }, - _applyLayerControlOptions: function (controlOptions, args) { - if (typeof controlOptions.includeUnspecifiedLayers === 'undefined' && typeof controlOptions.subLayerInfos === 'undefined' && typeof controlOptions.excludedLayers === 'undefined') { - return; - } - var esriLayerInfos = [], - layer = args.layer; - // Case 1: only show the layers that are explicitly listed - if (!controlOptions.includeUnspecifiedLayers && controlOptions.subLayerInfos && controlOptions.subLayerInfos.length !== 0) { - var subLayerInfos = array.map(controlOptions.subLayerInfos, function (sli) { - return sli.id; - }); - array.forEach(layer.layerInfos, function (li) { - if (array.indexOf(subLayerInfos, li.id) !== -1) { - esriLayerInfos.push(li); - } - }); - // Case 2: show ALL layers except those in the excluded list - } else if (controlOptions.excludedLayers) { - array.forEach(layer.layerInfos, function (li) { - if (array.indexOf(controlOptions.excludedLayers, li.id) === -1) { - esriLayerInfos.push(li); - } - }); - // Case 3: just override the values found in the subLayerInfos - } else if (controlOptions.subLayerInfos) { - // show ALL layers that are in the map service's layerInfos, but take care to override the properties of each subLayerInfo as configured - this._mixinLayerInfos(layer.layerInfos, controlOptions.subLayerInfos); - return; - } - // Finally, if we made use of the esriLayerInfos, make sure to apply all the subLayerInfos that were defined to our new array of esri layer infos - if (controlOptions.subLayerInfos) { - this._mixinLayerInfos(esriLayerInfos, controlOptions.subLayerInfos); - } - layer.layerInfos = esriLayerInfos; - }, - _mixinLayerInfos: function (esriLayerInfos, subLayerInfos) { - // for each of the sublayers, go through the subLayerInfos from the controlOptions and see if defaultVisiblity is set to true or false - // then set each of the layer.layerInfos defaultVisibility appropriately - // assume defaultVisibility is true if it's not defined - if (subLayerInfos && subLayerInfos.length !== 0) { - array.forEach(subLayerInfos, function (sli) { - if (typeof sli.defaultVisibility === 'undefined') { - sli.defaultVisibility = true; - } - }); - array.forEach(esriLayerInfos, function (li) { - var sli = array.filter(subLayerInfos, function (s) { - return s.id === li.id; - }).shift(); - if (sli) { - lang.mixin(li, sli); - } - }); } }, initMapComplete: function (warnings) {