Skip to content

Commit

Permalink
Merge pull request #617 from roemhildtg/fix-603-sublayer-menu
Browse files Browse the repository at this point in the history
Fixes sublayer menu not appearing for single dynamic layer
  • Loading branch information
tmcgee authored Oct 9, 2016
2 parents 3d12b9a + ab1c132 commit 2838839
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
45 changes: 40 additions & 5 deletions viewer/js/config/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ define([
'esri/tasks/GeometryService',
'esri/layers/ImageParameters',
'gis/plugins/Google',
'dojo/i18n!./nls/main'
], function (units, Extent, esriConfig, /*urlUtils,*/ GeometryService, ImageParameters, GoogleMapsLoader, i18n) {
'dojo/i18n!./nls/main',
'dojo/topic'
], function (units, Extent, esriConfig, /*urlUtils,*/ GeometryService, ImageParameters, GoogleMapsLoader, i18n, topic) {

// url to your proxy page, must be on same machine hosting you app. See proxy folder for readme.
esriConfig.defaults.io.proxyUrl = 'proxy/proxy.ashx';
Expand Down Expand Up @@ -46,6 +47,23 @@ define([
return ip;
}

//some example topics for listening to menu item clicks
//these topics publish a simple message to the growler
//in a real world example, these topics would be used
//in their own widget to listen for layer menu click events
topic.subscribe('layerControl/hello', function (event) {
topic.publish('growler/growl', {
title: 'Hello!',
message: event.layer._titleForLegend + ' ' + event.subLayer.name + ' says hello'
});
});
topic.subscribe('layerControl/goodbye', function (event) {
topic.publish('growler/growl', {
title: 'Goodbye!',
message: event.layer._titleForLegend + ' ' + event.subLayer.name + ' says goodbye'
});
});

return {
// used for debugging your app
isDebug: true,
Expand Down Expand Up @@ -183,7 +201,14 @@ define([
layerControlLayerInfos: {
swipe: true,
metadataUrl: true,
expanded: true
expanded: true,

//override the menu on this particular layer
menu: [{
topic: 'hello',
label: 'Say Hello',
iconClass: 'fa fa-smile-o'
}]
}
/*
//examples of vector tile layers (beta in v3.15)
Expand Down Expand Up @@ -391,7 +416,17 @@ define([
layerControlLayerInfos: true,
separated: true,
vectorReorder: true,
overlayReorder: true
overlayReorder: true,

//create a example sub layer menu that will
//apply to all layers of type 'dynamic'
subLayerMenu: {
dynamic: [{
topic: 'goodbye',
iconClass: 'fa fa-frown-o',
label: 'Say goodbye'
}]
}
}
},
bookmarks: {
Expand Down Expand Up @@ -560,4 +595,4 @@ define([

}
};
});
});
20 changes: 19 additions & 1 deletion viewer/js/gis/dijit/LayerControl/controls/Dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ define([
}));
menu.addChild(new MenuSeparator());
}

// add custom sublayer menu items if we only have one sublayer
if (!this._hasSublayers) {
array.forEach(this.controlOptions.menu, lang.hitch(this, '_addMenuItem', menu));
}
},
_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) {
Expand Down Expand Up @@ -222,4 +240,4 @@ define([
}
});
return DynamicControl;
});
});
2 changes: 1 addition & 1 deletion viewer/js/gis/dijit/LayerControl/plugins/LayerMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ define([
}
}
});
});
});

0 comments on commit 2838839

Please sign in to comment.