Skip to content

Commit

Permalink
Fixes #603 and adds menu examples in viewer config
Browse files Browse the repository at this point in the history
  • Loading branch information
green3g committed Oct 8, 2016
1 parent 3d12b9a commit 065ffb7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
35 changes: 29 additions & 6 deletions viewer/js/config/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ 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';
esriConfig.defaults.io.proxyUrl = 'proxy/proxy.aspx';
esriConfig.defaults.io.alwaysUseProxy = false;

// add a proxy rule to force specific domain requests through proxy
Expand Down Expand Up @@ -46,6 +47,14 @@ define([
return ip;
}

//some example topics for listening to menu item clicks
topic.subscribe('layerControl/hello', function(event){
alert(event.layer._titleForLegend + ' ' + event.subLayer.name + ' says hello');
});
topic.subscribe('layerControl/goodbye', function(event){
alert(event.layer._titleForLegend + ' ' + event.subLayer.name + ' says goodbye');
});

return {
// used for debugging your app
isDebug: true,
Expand Down Expand Up @@ -183,7 +192,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 +407,14 @@ define([
layerControlLayerInfos: true,
separated: true,
vectorReorder: true,
overlayReorder: true
overlayReorder: true,
subLayerMenu: {
dynamic: [{
topic: 'goodbye',
iconClass: 'fa fa-frown-o',
label: 'Say goodbye'
}]
}
}
},
bookmarks: {
Expand Down Expand Up @@ -560,4 +583,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;
});
});

0 comments on commit 065ffb7

Please sign in to comment.