Layer Toggle and Zoom To

649
9
07-13-2018 02:24 PM
joerodmey
MVP Alum

Looking to have a WAB widget to toggle between layers and zoom to the layer that turns on. Basically I want to have the toggle functionality as in Robert's widget: https://community.esri.com/docs/DOC-8592-layer-toggle-button-widget-version-22-01132017  with the added functionality to zoom to the "on layer".

-Joe

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus

Joe,

   In the LayerToggleWidget widget.js just make this change to the onOpen function (line 13).

      onOpen: function() {
        this.setToggleLayer();
        var lObjs = [];
        array.map(this.toggleLayerIds, lang.hitch(this, function(id){
          var lyrNode = this.layerStructure.getNodeById(id);
          lyrNode.on('toggle-change', this.setCheckedState(lyrNode));
          lObjs.push(lyrNode);
        }));
        if (!this.isToggling) {
          this.isToggling = true;
          this.toggleLayer(lObjs);
          setTimeout(lang.hitch(this, function() {
            this.map.setExtent(lObjs[0]._layerInfo.layerObject.fullExtent);
            this.isToggling = false;
            WidgetManager.getInstance().closeWidget(this);
            if(lObjs[0].isToggledOn()){
              domClass.add(this.parentContainer, "jimu-state-selected");
            }else{
              domClass.remove(this.parentContainer, "jimu-state-selected");
            }
          }), 300);
        }
      },
0 Kudos
joerodmey
MVP Alum

I tried this change to the .js in both server and client folders and it doesn't zoom to the layer

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Strange it worked for me when I tested it on the traffic cameras layer from the preview site 

0 Kudos
joerodmey
MVP Alum

I'm still hosting this locally in WAB...shouldn't make a difference though

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Do you see any errors in the console?

0 Kudos
joerodmey
MVP Alum

Just the one:

0 Kudos
joerodmey
MVP Alum

Any ideas?

Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Joe,

   I don't know why you would be getting that error. I have tested this with several layers and it works without issue. Is there anything unusual about the layer(s) you are attempting to toggle and zoom to?

0 Kudos
joerodmey
MVP Alum

Not really. Just feature services. These layers are CAD drawings that were converted into GIS

0 Kudos