Is there a way to implement a listener in a widget.js for extent-change events occurring in the map?
I need to be able to toggle the visibility of a feature layer (that is added by other events from the widget) based upon the map's extent. The offending workflow is that:
1. Button on a widget panel is deactivated until a specific map extent (zoomed in) is achieved.
2. Upon button click, add the feature layer and set it visible.
The problem with this is that there is no listener in the event that the user zooms out. I need to be able to toggle off the visibility of that feature layer if the map extent exceeds a certain value.
Thanks for any input!
Solved! Go to Solution.
James,
I might be missing something in your workflow but it sounds as simple as adding a extent-change listener to the map in your widget startup then:
startup: function(){
this.inherited(arguments);
this.own(this.map.on("extent-change", checkExtent));
},
checkExtent: function(evt){
if(evt.lod > 12){
//enable the button
}else{
//diable the button
}
},
James,
I might be missing something in your workflow but it sounds as simple as adding a extent-change listener to the map in your widget startup then:
startup: function(){
this.inherited(arguments);
this.own(this.map.on("extent-change", checkExtent));
},
checkExtent: function(evt){
if(evt.lod > 12){
//enable the button
}else{
//diable the button
}
},
Thanks Robert,
My task is simply to make a feature layer invisible if the current map extent exceeds a value. Right now, that feature layer is made visible by a button click, which that button is deactivated until that extent threshold is met. This is fine, except that I need to turn off that visibility if the user zooms out too far (because it causes performance problems).
I'll try to implement your example!
Thanks,
James
Robert,
I can fire the event as you suggest in the startup function() however how do I enable that function anytime the map extent changes (after the startup has finished)?
Perhaps I need a listener on the draw event of the Feature Layer instead?
Thanks again!
The listener is added at widget startup but it will fire the checkExtent method any time the maps extent changes.
Ok thanks, I must not be implementing correctly.