Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes sublayer menu not appearing for single dynamic layer #617

Merged
merged 3 commits into from Oct 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 40 additions & 5 deletions viewer/js/config/viewer.js
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
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
Expand Up @@ -120,4 +120,4 @@ define([
}
}
});
});
});