Select to view content in your preferred language

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

5190
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
14 Replies
RobertScheitlin__GISP
MVP Emeritus

Get Beta 3 and just copy your config.json and your widget *.json files into a new Beta 3 App that you build. Unless you have done some actually changes to the stem apps javascript files (the coding files, not just configuration changes), then just moving your configuration changes to a new app will not be hard at all.

0 Kudos
ErikLima
Occasional Contributor

Robert,

I have much changes and customizations in many widgets, so in this case the effort is very high...

I was trying to force the toggle of visibility "manually" in the event click. In this event I have the layerInfo of the layer that I want manipulate the visibility. How can I set your visibility only getting the layerInfo?

Or have an other function that put the ID of my MapService and it do this?

Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Erik,

   It was a poor decision to invest that much time in making code changes to a Beta 1. Beta 3 does not have the issue you are speaking of so my advice is to try and find what has changed  (a emitted event name change or something) between Beta1 and beyond.

0 Kudos
ErikLima
Occasional Contributor

Ok, Robert!

I will go try do it!!

Thanks again!!!

0 Kudos
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);

        }

      }

    },

0 Kudos