It's possible to restrict a feature action

1170
9
Jump to solution
06-19-2017 05:34 AM
ZdeněkSoldán
Occasional Contributor

Hello, 

I have a feature action that load data from feature in map to widget. I need this feature action available only from feature's pop up. But the isFeatureSupported function is called also when I want to use the Search widget where the feature layer is configured for searching and even when I open the Attribute table. 

The feature action should read information from specific feature after select the feature in the map so in Search widget and Attribute table widget the feature action doesn't know needed data and I recive a lot of errors.

It's possible to disable somehow this feature action in this two widgets?

Thanks for any help

Zdenek

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ZdeněkSoldán
Occasional Contributor

Robert,

Thank you that help partly but I still had a problem with my onReceiveData function. Function with the same name is in the Attribute Table widget. Somehow these functions with the same names didn't cooperate. So I renamed my function in my feature action and in my widget and now it works fine. 

View solution in original post

9 Replies
RobertScheitlin__GISP
MVP Emeritus

Zdenek,

   Where you you have the featureaction file located (file location) in your app? I have featureactions that are part of specific widget that are only available to that widget.

0 Kudos
ZdeněkSoldán
Occasional Contributor

Robert,

I have it the same the file is in folder of one widget and the feature action is only in manifest.json file in this widget. But the feature actions is called even if I search in Search Widget. And when I once open this widget and after that open the attribute table function onReceiveData from code below is called.

WidgetManager.getInstance().triggerWidgetOpen(this.widgetId)
          .then(function (attrWidget) {
            // console.log(layerInfo);
            // console.log(featureSet);
            attrWidget.onReceiveData(null, null, {
              target: "ShowInVES",
              layerInfo: layerInfo,
              featureSet: featureSet
            });
          });

The code is from featureaction js file.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdenek,

   You are right after some testing I see that the FeatureAction gets called by other widgets. So what you have to do is check for the existence of your variable or field or what ever it is that is causing your errors and check for that in your isFeatureSupported function. 

0 Kudos
ZdeněkSoldán
Occasional Contributor

Robert,

I know which variable is causing my errors but I need this variable in isFeatureSupported function. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdenek,

   I am not sure I understand the problem... The variable you have access to in the isFeatureSupported are the Featureset and layer. Can you not determine from either of those if your action should be enabled?

0 Kudos
ZdeněkSoldán
Occasional Contributor

Robert,

I think that isFeatureSupported function is ignored in this case. Here is the function

isFeatureSupported: function (featureSet, layer) {
        if (!featureSet || !layer || !layer.id) {
          return false;
        }
        try {
        console.log("isfeauresuported")
        console.log(featureSet)
        console.log(layer)
        var layerInfos = LayerInfos.getInstanceSync();
        console.log(layerInfos)
        console.log(layer.id)
        var layerInfo = layerInfos.getLayerInfoById(layer.id);
        console.log(layerInfo)
        //musi byt splneny vsechny podminky aby byla akce dostupna
        return featureSet.features.length && layerInfo.id.match(/eZadost_VMP*/) || layerInfo.id.match(/eZadost_VPD*/) && layerInfo && layerInfo.getSupportTableInfo()
          .then(function (tableInfo) {
            return tableInfo && tableInfo.isSupportedLayer && tableInfo.isSupportQuery;
          });
        }
        catch(err){
          //console.log(err)
          return false;
        }
      },

In the case of searching in Search widget when isFeatureSupported function is called the layerInfo object is null and I have defined layerInfo object in return. So I think it shouldn't call the function but it does.

0 Kudos
ZdeněkSoldán
Occasional Contributor

Try and Catch is my workaround that works but I would prefer more clear solution.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdenek,

  So Just do this:

var layerInfos = LayerInfos.getInstanceSync();
if(!layerInfos){
  return false;
}

ZdeněkSoldán
Occasional Contributor

Robert,

Thank you that help partly but I still had a problem with my onReceiveData function. Function with the same name is in the Attribute Table widget. Somehow these functions with the same names didn't cooperate. So I renamed my function in my feature action and in my widget and now it works fine.