Select to view content in your preferred language

How can I disable visibility of a group layer???

5189
14
Jump to solution
08-22-2014 05:49 AM
ErikLima
Occasional Contributor

Hi!!!

I have a problem with group layer on widget LayerList... disable visibility (checkbox) of the layers don't work, neither when I unckeck the group layer that contain the layers that I have disable visibility...

Somebody had this problem?? How can I resolve it???

0 Kudos
1 Solution

Accepted Solutions
ErikLima
Occasional Contributor

Hi, people!

Problem resolved!

How I already had replaced the widget Beta 1 by Beta 2, I discovered that a array was being created wrong, including the indexs of groups. So I manipulated this array to remove all index of all groups before send to toggle the visibility.

This array is manipulated in ...\jimu.js\LayerInfos\LayerInfoForMapService.js, the method is "setSubLayerVisible". Follows the code of my solution:

   // Gets the correspondent layer info

   getLayerInfo: function(layerInfos, id) {

      var layerInfo = null;

      for (var i = 0; layerInfos.length; i++) {

        if (layerInfos.id == id) {

          layerInfo = layerInfos;

          break;

        }

      }

      return layerInfo;

    },

    // Removes all indexs of all groups

    clearVisibleLayers: function(visibleLayers, layerInfos) {

      var myVisibleLayers = lang.clone(visibleLayers);

      var myLayerInfos = layerInfos;

      var layerInfo = null;

      array.forEach(visibleLayers, lang.hitch(this, function(idVisibleLayer){

        layerInfo = this.getLayerInfo(myLayerInfos, idVisibleLayer)

        if (layerInfo && layerInfo.subLayerIds != null) {

          var index = array.indexOf(myVisibleLayers, idVisibleLayer);

          myVisibleLayers.splice(index, 1);

        }

      }), this);

      return myVisibleLayers;

    },

    setSubLayerVisible: function(subLayerId, visible) {

      var ary = [],

        index;

      if (subLayerId !== null) {

        // Here is the alteration

        ary = lang.clone(this.originOperLayer.layerObject.visibleLayers);

        ary = this.clearVisibleLayers(ary, this.originOperLayer.layerObject.layerInfos);

        index = array.indexOf(ary, subLayerId);

        if (visible) {         

          if (index < 0) {

            ary.push(subLayerId);

            this.originOperLayer.layerObject.setVisibleLayers(ary);

          }

        } else {         

          if (index >= 0) {

            ary.splice(index, 1);

          }

          if (ary.length === 0) {

            ary.push(-1);

          }

          this.originOperLayer.layerObject.setVisibleLayers(ary);

        }

      }

    },

View solution in original post

0 Kudos
14 Replies
TimWitt2
MVP Alum

Erik,

are you talking about ArcGIS Desktop, Javascript API, Flex?

If it is a webapplication can you post some code?

Tim

0 Kudos
ErikLima
Occasional Contributor

The aplication was created by App Builder for Javascript... the widget is LayerList

0 Kudos
ErikLima
Occasional Contributor

Hello people!!

Some idea??

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Erik,

   I have not seen this behavior. Which version of the beta are you using?

0 Kudos
ErikLima
Occasional Contributor

Robert, tanks for your answer!

I created my application with AppBuilder Beta 1, but I have replaced only the  LayerList widget from Beta 2 and anything changed.

What version are you using?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Erik,

   I am using Beta 3. There is likely things that they changed in the StemApp from Beta 1 to Beta 2 that don't work with you just copying just the LayerListWidget from Beta 2 into Beta 1.

0 Kudos
ErikLima
Occasional Contributor

Do you think that if I copy the LayerListWidget from Beta 3 can works??

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

No, as I mentioned there was probably some core event or function changed in the StemApp that needs the widget and the StemApp to be on the same version. Mixing versions is not a recommended practice.

0 Kudos
ErikLima
Occasional Contributor

Understood!

So what's your recommendation for resolve this problem???

0 Kudos