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
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);
}
},
I tried this change to the .js in both server and client folders and it doesn't zoom to the layer
Strange it worked for me when I tested it on the traffic cameras layer from the preview site
I'm still hosting this locally in WAB...shouldn't make a difference though
Do you see any errors in the console?
Just the one:
Any ideas?
Thanks
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?
Not really. Just feature services. These layers are CAD drawings that were converted into GIS