Skip to content

Commit

Permalink
move custom layer menu logic to _Control
Browse files Browse the repository at this point in the history
 - all layer types now support `layerControlLayerInfos.menu` property
  • Loading branch information
green3g committed Feb 27, 2017
1 parent 2d346f8 commit 5f1f817
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
18 changes: 3 additions & 15 deletions viewer/js/gis/dijit/LayerControl/controls/Dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,13 @@ define([
}));
menu.addChild(new MenuSeparator());
}

},
_initCustomMenu: function () {
// add custom sublayer menu items if we only have one sublayer
if (!this._hasSublayers) {
array.forEach(this.controlOptions.menu, lang.hitch(this, '_addMenuItem', menu));
array.forEach(this.controlOptions.menu, lang.hitch(this, '_addMenuItem', this.layerMenu));
}
},
_addMenuItem: function (menu, menuItem) {
//create the menu item
var item = new MenuItem(menuItem);
item.set('onClick', lang.hitch(this, function () {
topic.publish('layerControl/' + menuItem.topic, {
layer: this.layer,
subLayer: this.layer.layerInfos[0],
iconNode: this.iconNode,
menuItem: item
});
}));
menu.addChild(item);
},
// toggle all sublayers on/off
_toggleAllSublayers: function (state) {
array.forEach(this._sublayerControls, function (control) {
Expand Down
20 changes: 19 additions & 1 deletion viewer/js/gis/dijit/LayerControl/controls/_Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define([
'dojo/dom-attr',
'dojo/fx',
'dojo/html',
'dijit/MenuItem',
'./../plugins/LayerMenu',
'dojo/text!./templates/Control.html'
], function (
Expand All @@ -24,6 +25,7 @@ define([
domAttr,
fx,
html,
MenuItem,
LayerMenu,
template
) {
Expand Down Expand Up @@ -91,6 +93,7 @@ define([
leftClickToOpen: true
});
this.layerMenu.startup();
this._initCustomMenu();
} else {
domClass.remove(this.menuNode, 'fa, layerControlMenuIcon, ' + this.icons.menu);
domStyle.set(this.menuClickNode, 'cursor', 'default');
Expand All @@ -117,6 +120,21 @@ define([
layer.on('visibility-change', lang.hitch(this, '_visibilityChange'))
);
},
_initCustomMenu: function () {
array.forEach(this.controlOptions.menu, lang.hitch(this, '_addCustomMenuItem', this.layerMenu));
},
_addCustomMenuItem: function (menu, menuItem) {
//create the menu item
var item = new MenuItem(menuItem);
item.set('onClick', lang.hitch(this, function () {
topic.publish('layerControl/' + menuItem.topic, {
layer: this.layer,
iconNode: this.iconNode,
menuItem: item
});
}));
menu.addChild(item);
},
// add on event to expandClickNode
_expandClick: function () {
this._expandClickHandler = on(this.expandClickNode, 'click', lang.hitch(this, '_expandClicked'));
Expand Down Expand Up @@ -259,4 +277,4 @@ define([
}
});
return _Control;
});
});

0 comments on commit 5f1f817

Please sign in to comment.