1

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.

asked Mar 20, 2019 at 18:23

1 Answer 1

2

You can check if a specific layer is loaded (using map.addLayer) with the map's layer-add-result event. Since this event fires when any layer is loaded (including the basemaps), you have to check for the specific layer

map.addLayer(featureLayer);
map.on('layer-add-result', function(addLayer){
 if (addLayer.layer === featureLayer){
 console.log(featureLayer);
 }
});

If you're using map.addLayers to add multiple layers, you can use the layers-add-result event

map.addLayers([featureLayer]);
map.on('layers-add-result', function (){
 console.log(featureLayer);
});
answered Mar 21, 2019 at 12:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.