Skip to content

Commit

Permalink
Merge branch 'develop' into fix/layer-control-topic-inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
green3g committed Feb 3, 2016
2 parents 46ab98c + 5df75a5 commit 263cac6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 40 deletions.
55 changes: 50 additions & 5 deletions viewer/js/gis/dijit/LayerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,22 @@ define([
this.overlayReorder = false;
this.vectorReorder = false;
}
this._addLayerControls(this.layerInfos);
this._subscribeToTopics();
},
_subscribeToTopics: function () {
this._removeLayerControlsHandler = topic.subscribe('layerControl/removeLayerControls', lang.hitch(this, function (layers) {
this._removeLayerControls(layers);
}));
this._addLayerControlsHandler = topic.subscribe('layerControl/addLayerControls', lang.hitch(this, function (layerInfos) {
this._addLayerControls(layerInfos);
}));
},
_addLayerControls: function (layerInfos) {
// load only the modules we need
var modules = [];
// push layer control mods
array.forEach(this.layerInfos, function (layerInfo) {
array.forEach(layerInfos, function (layerInfo) {
// check if control is excluded
var controlOptions = layerInfo.controlOptions;
if (controlOptions && controlOptions.exclude === true) {
Expand All @@ -139,7 +151,7 @@ define([
}, this);
// load and go
require(modules, lang.hitch(this, function () {
array.forEach(this.layerInfos, function (layerInfo) {
array.forEach(layerInfos, function (layerInfo) {
// exclude from widget
var controlOptions = layerInfo.controlOptions;
if (controlOptions && controlOptions.exclude === true) {
Expand All @@ -153,6 +165,38 @@ define([
this._checkReorder();
}));
},
// remove the control given an array of layers
_removeLayerControls: function (layers) {
// helper function to determine which children's layer have a match in the layers parameter
function _filterList (entry) {
return layers.reduce(function (prior, curr) {
return (curr === entry.layer) || prior;
}, false);
}
// get a list of ALL the layers that meet the criteria
var layerControlList = this._overlayContainer.getChildren().filter(function (c) {
return _filterList(c);
}).concat(
this._vectorContainer.getChildren().filter(function (c) {
return _filterList(c);
})).concat(
this.getChildren().filter(function (c) {
return _filterList(c);
}));
// follow the same logic as when the layers were added
array.forEach(layerControlList, lang.hitch(this, function (layerControl) {
if (this.separated) {
if (layerControl._layerType === 'overlay') {
this._overlayContainer.removeChild(layerControl);
} else {
this._vectorContainer.removeChild(layerControl);
}
} else {
this.removeChild(layerControl);
}
layerControl.destroy();
}));
},
// create layer control and add to appropriate _container
_addControl: function (layerInfo, Control) {
var layerControl = new Control({
Expand All @@ -170,14 +214,15 @@ define([
}, layerInfo.controlOptions)
});
layerControl.startup();
var position = layerInfo.position || 0;
if (this.separated) {
if (layerControl._layerType === 'overlay') {
this._overlayContainer.addChild(layerControl, 'first');
this._overlayContainer.addChild(layerControl, position);
} else {
this._vectorContainer.addChild(layerControl, 'first');
this._vectorContainer.addChild(layerControl, position);
}
} else {
this.addChild(layerControl, 'first');
this.addChild(layerControl, position);
}
},
// move control up in controller and layer up in map
Expand Down
17 changes: 12 additions & 5 deletions viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ define([
// ^args
templateString: folderTemplate,
_expandClickHandler: null,
_handlers: [],
postCreate: function () {
this.inherited(arguments);
// Should the control be visible or hidden?
Expand All @@ -47,26 +48,26 @@ define([
} else {
this._setSublayerCheckbox(false, checkNode);
}
on(checkNode, 'click', lang.hitch(this, function () {
this._handlers.push(on(checkNode, 'click', lang.hitch(this, function () {
if (domAttr.get(checkNode, 'data-checked') === 'checked') {
this._setSublayerCheckbox(false, checkNode);
} else {
this._setSublayerCheckbox(true, checkNode);
}
this.control._setVisibleLayers();
this._checkboxScaleRange();
}));
})));
html.set(this.labelNode, this.sublayerInfo.name);
this._expandClick();
if (this.sublayerInfo.minScale !== 0 || this.sublayerInfo.maxScale !== 0) {
this._checkboxScaleRange();
this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange'));
this._handlers.push(this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')));
}
},
// add on event to expandClickNode
_expandClick: function () {
var i = this.icons;
this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, function () {
this._handlers.push(this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, function () {
var expandNode = this.expandNode,
iconNode = this.expandIconNode;
if (domStyle.get(expandNode, 'display') === 'none') {
Expand All @@ -82,7 +83,7 @@ define([
}).play();
domClass.replace(iconNode, i.folder, i.folderOpen);
}
}));
})));
},
// set checkbox based on layer so it's always in sync
_setSublayerCheckbox: function (checked, checkNode) {
Expand All @@ -106,6 +107,12 @@ define([
if ((min !== 0 && scale > min) || (max !== 0 && scale < max)) {
domClass.add(node, 'layerControlCheckIconOutScale');
}
},
destroy: function () {
this.inherited(arguments);
this._handlers.forEach(function (h) {
h.remove();
});
}
});
return _DynamicFolder;
Expand Down
50 changes: 29 additions & 21 deletions viewer/js/gis/dijit/LayerControl/controls/_DynamicSublayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ define([
'dojo/text!./templates/Sublayer.html',
'dojo/i18n!./../nls/resource'
], function (
declare,
lang,
array,
on,
domClass,
domStyle,
domAttr,
fx,
html,
Menu,
MenuItem,
topic,
WidgetBase,
TemplatedMixin,
sublayerTemplate,
i18n
) {
declare,
lang,
array,
on,
domClass,
domStyle,
domAttr,
fx,
html,
Menu,
MenuItem,
topic,
WidgetBase,
TemplatedMixin,
sublayerTemplate,
i18n
) {
var _DynamicSublayer = declare([WidgetBase, TemplatedMixin], {
control: null,
sublayerInfo: null,
Expand All @@ -43,6 +43,7 @@ define([
templateString: sublayerTemplate,
i18n: i18n,
_expandClickHandler: null,
_handlers: [],
postCreate: function () {
this.inherited(arguments);
// Should the control be visible or hidden?
Expand All @@ -58,24 +59,24 @@ define([

this._setSublayerCheckbox(false, checkNode);
}
on(checkNode, 'click', lang.hitch(this, function () {
this._handlers.push(on(checkNode, 'click', lang.hitch(this, function () {
if (domAttr.get(checkNode, 'data-checked') === 'checked') {
this._setSublayerCheckbox(false, checkNode);
} else {
this._setSublayerCheckbox(true, checkNode);
}
this.control._setVisibleLayers();
this._checkboxScaleRange();
}));
})));
html.set(this.labelNode, this.sublayerInfo.name);
this._expandClick();
if (this.sublayerInfo.minScale !== 0 || this.sublayerInfo.maxScale !== 0) {
this._checkboxScaleRange();
this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange'));
this._handlers.push(this.control.layer.getMap().on('zoom-end', lang.hitch(this, '_checkboxScaleRange')));
}
//set up menu
if (this.control.controlOptions.menu &&
this.control.controlOptions.menu.length) {
this.control.controlOptions.menu.length) {
domClass.add(this.labelNode, 'menuLink');
domClass.add(this.iconNode, 'menuLink');
this.menu = new Menu({
Expand Down Expand Up @@ -120,6 +121,7 @@ define([
domClass.replace(iconNode, i.expand, i.collapse);
}
}));
this._handlers.push(this._expandClickHandler);
},
// set checkbox based on layer so it's always in sync
_setSublayerCheckbox: function (checked, checkNode) {
Expand All @@ -143,6 +145,12 @@ define([
if ((min !== 0 && scale > min) || (max !== 0 && scale < max)) {
domClass.add(node, 'layerControlCheckIconOutScale');
}
},
destroy: function () {
this.inherited(arguments);
this._handlers.forEach(function (h) {
h.remove();
});
}
});
return _DynamicSublayer;
Expand Down
22 changes: 13 additions & 9 deletions viewer/js/gis/dijit/LayerControl/plugins/legendUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,19 @@ define([
}, row, 'last');

domConst.place(this._image(legend, layerId, layer), symbol);
}, this);
// place legend in the appropriate sublayer expandNode
// or if a single layer use control expandNode
if (layer.layerInfos.length > 1) {
var sublayerExpandNode = registry.byId(layer.id + '-' + _layer.layerId + '-sublayer-control').expandNode;
html.set(sublayerExpandNode, ''); //clear "No Legend" placeholder
domConst.place(table, sublayerExpandNode);
} else {
domConst.place(table, expandNode);
}, this);
if (layer.layerInfos.reduce(function (prior, curr) {
return (curr.id === _layer.layerId) || prior;
}, false)) {
// place legend in the appropriate sublayer expandNode
// or if a single layer use control expandNode
if (layer.layerInfos.length > 1) {
var sublayerExpandNode = registry.byId(layer.id + '-' + _layer.layerId + '-sublayer-control').expandNode;
html.set(sublayerExpandNode, ''); //clear "No Legend" placeholder
domConst.place(table, sublayerExpandNode);
} else {
domConst.place(table, expandNode);
}
}
}, this);
},
Expand Down

0 comments on commit 263cac6

Please sign in to comment.