Select to view content in your preferred language

Publish data from LayerList Widget?

3385
5
08-06-2015 10:33 PM
RahmathUnissa
Deactivated User

Hello,

In the LayerList widget I am trying to publish the layer info  after checking/unchecking the checkbox.

In layerlistview.js I am saving the info in an array which is declared as global, As per my previous queries I can only publish the data from widget.js which inherits the Basewidget but not from layerlistview.js.

I tried passing the array from layerlistview.js to widget.js but nothing worked.

Can anyone help me or suggest me on how to publish the data from this widget?

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Rahmath,

   The LayerListView.js has a direct link back to the Widget.js using the "this.layerListWidget" so if you have a global property in the Widget.js like the operLayerInfos (an example of a global var in the Widget.js that already exists) then you can send your data to that var using "this.layerListWidget.operLayerInfos"

RahmathUnissa
Deactivated User

Hi Robert,

Thank you for the response. Although, I got to know one new thing about using global property from your reply.But I am stuck with something as explained below.

I have a global variable in LayerListView.js (not in widget.js) and the variable's value keep changing after performing on-click events.

Each time I use click event I update the value of the variable and this value I need to pass/use in another widget..

Appreciate any suggestions/help.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ratmath,

I have a global variable in LayerListView.js (not in widget.js) and the variable's value keep changing after performing on-click events.

Your global var does not have to stay in your LayerListView. You say that it is there now but it would be better for you to move it to your Widget.js. Your variable values may be changing all the time as most do but the variable name should be constant, so I don't understand what the concern is.

0 Kudos
RahmathUnissa
Deactivated User

Robert,

I did try to use the way which you have mentioned in your replies.

Below is the an explaination of what I am trying to do.(Trying to explain, Hope It will be clear)

1)  On opening the LayerList widget all information gets loaded, events are binded and Layer list is displayed.

2) I am trying to use the click event from the LayerListView.js and to get the layer id of the selected layer on each click.

In LayerListView.js there is function (at line 300) as defined below. This function is triggered on start and I want to use the value based on each click event.

_onCkSelectNodeClick: function(layerInfo, ckSelect, evt) {

      if (ckSelect.checked) {

var mylayerid= layerInfo.id  ---------------------->(want to use/publish this value everytime a checkbox is checked)

        layerInfo.setTopLayerVisible(true);

      } else {

        layerInfo.setTopLayerVisible(false);

      }

      evt.stopPropagation();

    },

variable "mylayerid" I declared  it globally in LayeListView.js, but how/where can i call/use this value in widget.js?

I have used a test function in widget.js after this.showlayers() function which did not execute.

3) Next, I want to use this value and publish it on each new click.

Appreciate the Help!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Rahmath,

  So it would simply look like this then (line 3 and line 15 - 16):

LayerListView.js

    _onCkSelectNodeClick: function(layerInfo, ckSelect, evt) {
      if (ckSelect.checked) {
        this.layerListWidget.mylayerid = layerInfo.id;
        layerInfo.setTopLayerVisible(true);
      } else {
        layerInfo.setTopLayerVisible(false);
      }
      evt.stopPropagation();
    },

Widget.js

    var clazz = declare([BaseWidget], {
      /*jshint unused: false*/
      //these two properties is defined in the BaseWiget 
      baseClass: 'jimu-widget-layerList',
      name: 'layerList',

      //layerListView: Object{}
      //  A module is responsible for show layers list
      layerListView: null,

      //operLayerInfos: Object{}
      //  operational layer infos
      operLayerInfos: null,

      //This is your global var for mylayerid
      mylayerid: null,