Select features sample not actually selecting features

664
3
Jump to solution
04-30-2012 08:24 AM
BenStewart
New Contributor III
I am using the sample here (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm) on my own data. I have successfully implemented it once using a feature service from ArcGIS Online (http://maps4.arcgisonline.com/ArcGIS/rest/services/World_Bank/WB_World_Bank_Projects/MapServer/3). However, when I try to replace it with my own feature service (sorry, behind my firewall, no link) the event that is fired "onDrawEnd" does not have a reference to the relevant layer (featureLayer in block below).

Am I missing something? I don't know why the featureLayer reference is not working for one link when it worked for the other. Both versions show the features on the map fine.

function initSelectToolbar(map) {  //This little bit is to enable drawing for item selection  selectionToolbar = new esri.toolbars.Draw(map);  var selectQuery = new esri.tasks.Query();   dojo.connect(selectionToolbar, "onDrawEnd", function(geometry) {   selectQuery.geometry = geometry;   featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);   selectionToolbar.deactivate();  });  }
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
In the sample you're referring to, the featureLayer variable is global. Is it a global in your app?

If it is, can you post a more complete code sample?

View solution in original post

0 Kudos
3 Replies
derekswingley1
Frequent Contributor
In the sample you're referring to, the featureLayer variable is global. Is it a global in your app?

If it is, can you post a more complete code sample?
0 Kudos
BenStewart
New Contributor III
That's the answer, kind of. It was declared as a global variables, but I had a var before the vairable definition in the init function. Once I removed that, everything was golden.

Thanks a lot! I never would have remembered that
0 Kudos
derekswingley1
Frequent Contributor
It's one of those tricky parts of JavaScript:  scope and the var keyword. Glad you got it fixed.
0 Kudos