I am building a FeatureAction for my custom widget. I want to allow only features of services defined in the widget's config.json to have access to this FeatureAction. So I need the contents of the config.json file.
I could get it from the widget object using the WidgetManager, problem is that when the widget is not loaded the object won't be found. I don't want to force the user to open the widget before using the FeatureAction. Is there a way to accomplish this?
Here's a conceptual and simplified example of what I am trying to accomplish.
isFeatureSupported: function(featureSet) {
if (featureSet.features.length !== 1)
var feature = featureSet.features[0]
var config = getWidgetConfig() // how?
return config.supportedServices.includes(feature.layer.url)
},
Kevin,
How would the widget not be loaded if this is a feature action of that widget?...
I use a test like this to make sure the action is only shown for a particular widget.
isFeatureSupported: function(featureSet, layer){
var supported = false;
supported = featureSet.features.length > 1 && layer;
var tWidget = WidgetManager.getInstance().getWidgetById(this.widgetId);
if(tWidget && tWidget.state === 'active'){
return supported;
}else{
return false;
};
},
Robert Scheitlin, GISP escreveu:
How would the widget not be loaded if this is a feature action of that widget?...
I don't know. `getWidgetById()` only works after I open the widget. The code you provided actually forces the user to open and keep the widget open for the FeatureAction to work.
Edit: I found a solution in case anyone is curious:
_getWidgetObj: function(widgetId) {
return this.appConfig.widgetOnScreen.widgets
.concat(this.appConfig.widgetPool.widgets)
.find(function(widget){
return widget.id === widgetId
})
},
The function above will find the widget object regardless of it being loaded or not.
Kevin,
Here is a more simple one line solution: