Select to view content in your preferred language

Display data from pop up in custom widget

1628
8
Jump to solution
10-17-2016 06:26 AM
ZdeněkSoldán
Regular Contributor

Hello,

I created my feature action similar to ViewInAttributeTableFeatureAction but it opens a different widget. But I have some issues with receiving data in the widget that feature action opens. In original  ViewInAttributeTable Feature Action is an object FeatureSet that holds the attributes of the selected element. I dug out the attributes from object featureSet by use featureSet.features[0].attributes. Is there any easier way how to do this? And when I have all parametrs saved in a variable how can I display them in the widget? I tried use   in html and this.test.value = variable with attributes in onReceiveData function in JS but it shows me nothing (nothing in widget and neither error message).

 

Thanks for any help

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   For sending data from the FeatureAction code to the widget you would use a global var in the widget. As your FeatureAction is already opening the widget that means you have a reference to the widget so you just need to wait for the widget to actually open and then set the widgets global var with the data you want to send to it. You can not use widget communication as the FeatureAction can not use publishData.

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   For sending data from the FeatureAction code to the widget you would use a global var in the widget. As your FeatureAction is already opening the widget that means you have a reference to the widget so you just need to wait for the widget to actually open and then set the widgets global var with the data you want to send to it. You can not use widget communication as the FeatureAction can not use publishData.

ZdeněkSoldán
Regular Contributor

So..in FeatureAction in method onExecute I have a object featureSet. I need attributes from this object so the global var shoud be like this featureSet.features[0].attributes? And where to define global var?  

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   I think you should re-read my last post. In the onExecute method you set the global var (that is in the widget) once the widget is opened.

0 Kudos
ZdeněkSoldán
Regular Contributor

Robert, 

I am sorry but I am lost. I am quite new autodidact in JS programming so I would need more deeply explanation if you be so kind. 

Here is my onExecute method:

onExecute: function(featureSet, layer) {
      if (!featureSet || !layer) {
        return;
       }
      var layerInfos = LayerInfos.getInstanceSync();
      var layerInfo = layerInfos.getLayerInfoById(layer.id);
      featureSet.displayFieldName = layer.objectIdField;

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

in main widget.js code I have function onReceiveData:

onReceiveData: function(name, source, params) {
        /*jshint unused:vars*/
        if (params && params.target === "ShowInVES") {
           params.layer = params.layer || params.layerInfo;
           
          }
        
        console.log(params.featureSet);
        
        this.test.value = datafields.featureSet;
       },‍‍‍‍‍‍‍‍‍‍‍‍‍

and in widget.html I have <div data-dojo-attach-point ="test">
                                          </div>

But it shows nothing.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   Do you get the console log from the onRecieveData function? One issue I see is that:

this.test.value = datafields.featureSet;

You are setting a div's value to datafields.featureSet. Normally a div does not have a value. If you are trying to set the text inside a div you need to use:

 this.test.innerHTML = "blah blah";‍‍
0 Kudos
ZdeněkSoldán
Regular Contributor

Yes I do,

console log in function gave me what I expected. Thank you with explanation of div properties I changed it to innerHtml but it still shows nothing even if I changed it to:

   

this.test.innerHtml = "blah blah";
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

  Sorry that was a syntax error on my part it was suppose to be this.test.innerHTML = "blah blah";

0 Kudos
ZdeněkSoldán
Regular Contributor

Robert,

now it works! Thank you for your patience.

0 Kudos