Select to view content in your preferred language

extent-change Listener?

2040
5
Jump to solution
04-14-2017 01:30 PM
JamesCrandall
MVP Alum

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!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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
  }
},

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

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
  }
},
JamesCrandall
MVP Alum

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

0 Kudos
JamesCrandall
MVP Alum

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! 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

The listener is added at widget startup but it will fire the checkExtent method any time the maps extent changes.

JamesCrandall
MVP Alum

Ok thanks, I must not be implementing correctly. 

0 Kudos