Many thanks to Robert and others for helping our community with their custom widgets.
I personally use Robert's Identify, LocalLayer widgets to identify a few. Each of these widgets have their own configuration files.
Since most of the times the layers that are utilized in the widgets are the same, I found myself to duplicate most of the configuration in each widget configuration.
It would be ideal, if the widgets could share the same config file. So, in the config.json the widgets point to the same config file.
Comments?
Example in the config.json
"widgetPool": {
...........................
....................................
"widgets": [
{
"name": "Identify",
"label": "Identify",
"version": "1.2.0.2",
"IsController": false,
"uri": "widgets/Identify/Widget",
"config": "configs/COMMON/config.json",
"index": 4,
"id": "widgets_Identify_Widget_54"
}
....................
...........................
"widgetOnScreen": {
"widgets": [
{
"uri": "widgets/LocalLayer/Widget",
"id": "widgets_LocalLayer_Widget_55",
"name": "LocalLayer",
"label": "Local Layer Widget",
"config": "configs/COMMON/config.json",
},
...............................
......................................................
Solved! Go to Solution.
Lefteris,
I saw you had another question about a select in your widgets html. I don't see that question any more but just in case here is some comments on your code:
/*global define*/ define([ 'dojo/_base/declare', 'dijit/_WidgetsInTemplateMixin', 'dojo/on', 'dojo/_base/array', 'jimu/BaseWidget', 'dojo/_base/lang', 'jimu/LayerInfos/LayerInfos', /*I try to put all dojo/dijit items that are needed for the html but not for use in the js code last in the list*/ 'dijit/form/Select' ], function ( declare, _WidgetsInTemplateMixin, on, array, BaseWidget, lang, LayerInfos ) { //To create a widget, you need to derive from BaseWidget. return declare([BaseWidget, _WidgetsInTemplateMixin], { baseClass: 'jimu-widget-BufferSelection', postCreate: function () { this.inherited(arguments); }, startup: function () { this.inherited(arguments); /*Because layerinfos is a defered you need to lang hitch so that "this" is in the proper scope*/ LayerInfos.getInstance(this.map, this.map.itemInfo).then(lang.hitch(this, function (layerInfosObject) { this.resultLayers = []; /*Because getLayerInfoArray is a defered you need to lang hitch so that "this" is in the proper scope*/ layerInfosObject.getLayerInfoArray().forEach(lang.hitch(this, function (layerInfo, index) { var option = { value: index, label: layerInfo.title }; //console.log(layerInfo); this.resultLayers.push(option); })); this.select1.addOption(this.resultLayers); })); } }); });
Lefteris,
Sure you could do this by manually setting the config file path in the main config to a common config file. The builder app will always handle the assignment of the widgets config file automatically in code though and you would just need to switch it manually.
That's what I thought. When I tried this, the wab wouldn't even render the page.
"name": "Identify",
"label": "Identify",
"version": "1.2.0.2",
"IsController": false,
"uri": "widgets/Identify/Widget",
"config": "configs/LocalLayer/config_Local Layer Widget.json"
"index": 4,
"id": "widgets_Identify_Widget_54"
Lefteris,
even though the layer object at similar they need to be identical. Have you checked that?
I am not sure how this will work. Since the config_identify.json file has some settings before the layers object, the identity tool need to access these settings to initialize the widget. By modifying the config.json as I posted above, the identify widget will not have access to the settings (since the LocalLayer config file does not have them), and therefore it will fail.
Leftris,
Sorry I should have been more explicit. You would have to add all the parameters from the Identify widget to the combined_config.json file so anything not in the Identify widget config needs to be added to the LL config json.
Lefteris,
I saw you had another question about a select in your widgets html. I don't see that question any more but just in case here is some comments on your code:
/*global define*/ define([ 'dojo/_base/declare', 'dijit/_WidgetsInTemplateMixin', 'dojo/on', 'dojo/_base/array', 'jimu/BaseWidget', 'dojo/_base/lang', 'jimu/LayerInfos/LayerInfos', /*I try to put all dojo/dijit items that are needed for the html but not for use in the js code last in the list*/ 'dijit/form/Select' ], function ( declare, _WidgetsInTemplateMixin, on, array, BaseWidget, lang, LayerInfos ) { //To create a widget, you need to derive from BaseWidget. return declare([BaseWidget, _WidgetsInTemplateMixin], { baseClass: 'jimu-widget-BufferSelection', postCreate: function () { this.inherited(arguments); }, startup: function () { this.inherited(arguments); /*Because layerinfos is a defered you need to lang hitch so that "this" is in the proper scope*/ LayerInfos.getInstance(this.map, this.map.itemInfo).then(lang.hitch(this, function (layerInfosObject) { this.resultLayers = []; /*Because getLayerInfoArray is a defered you need to lang hitch so that "this" is in the proper scope*/ layerInfosObject.getLayerInfoArray().forEach(lang.hitch(this, function (layerInfo, index) { var option = { value: index, label: layerInfo.title }; //console.log(layerInfo); this.resultLayers.push(option); })); this.select1.addOption(this.resultLayers); })); } }); });
Thank you Robert. Yes, I deleted the posts because I thought it was a simple and naive question and I should try a bit harder to try it out. I keep forgetting to keep the scope of the function with the lang.hitch.
Thank you!