I am using ArcGIS API for JavaScript 3.7.
I am trying to see if I can select features in the same fashion that shift+click and dragging lets you zoom into the map by drawing a rectangle. The trouble that I am encountering is that I want this functionality on a certain layer of the map, but I do not know if this layer is ready yet. I've tried using the following:
map.on('load', function initSelectToolbar(event) {
selectionToolbar = new Draw(event.map);
var selectQuery = new Query();
on(selectionToolbar, "DrawEnd", function (geometry) {
selectionToolbar.deactivate();
selectQuery.geometry = geometry;
featureLayer.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW);
});
});
I would like to see if it is possible to run this code when I know for sure that the layer is ready. As far as I am aware, I can't change the feature layer the code references once it is loaded in.
EDIT:
It looks like I got it to work. I found a way to grab the layers URL using map.getLayer(layerId).url
(how I missed that is beyond me), created a new feature layer for selection, and removed it when the user was done. I still think this could be done better though.