Skip to content

Commit

Permalink
Merge branch 'develop' into feature/updated-basemaps-widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgee committed Mar 26, 2016
2 parents 25a3893 + fc7e160 commit 51ec28a
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 65 deletions.
74 changes: 73 additions & 1 deletion viewer/js/gis/dijit/LayerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
47 changes: 29 additions & 18 deletions viewer/js/gis/dijit/LayerControl/controls/Dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
93 changes: 49 additions & 44 deletions viewer/js/gis/dijit/LayerControl/controls/_Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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({
Expand All @@ -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
Expand All @@ -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 () {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 9 additions & 1 deletion viewer/js/gis/dijit/LayerControl/controls/_DynamicSublayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 () {
Expand Down
1 change: 0 additions & 1 deletion viewer/js/viewer/_MapMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ define([
}
}
},

initMapComplete: function (warnings) {
if (warnings && warnings.length > 0) {
this.handleError({
Expand Down

0 comments on commit 51ec28a

Please sign in to comment.