Select to view content in your preferred language

Zoom to selected

2782
12
Jump to solution
04-14-2017 10:04 AM
GregRieck
Frequent Contributor

Hello, I am using WAB 2.2 Jewelry box theme. I have features selected and would now like to zoom to those selected features. How do I zoom to selected features on the map?

Thank You,

Greg

0 Kudos
12 Replies
GregRieck
Frequent Contributor

Robert,

You are correct, the array has a zero length. So how do I get this to work? How do I make it "wait" for the selection to complete to activate the zoom to portion of the code? 

Greg

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Greg,

   The selectFeatures is a deferred returning method so you just need to use a callback function like you do for any deferred.

cableLayer.selectFeatures(cableSelectQuery, cableLayer.SELECTION_NEW, lang.hitch(this, function(results){
  var selMgr = SelectionMgr.getInstance();
  var geom = selMgr.getUnionGeometryBySelectedFeatures(cableLayer);
  this.map.setExtent(geom.getExtent().expand(1.2), true);
}));
GregRieck
Frequent Contributor

Robert,

Thank you for the efforts that got it.

Greg

0 Kudos