I am trying to select(highlight) some features that are found at a map service. The selection is based on mouse clicking on map by the user. I am using Arcgis Javascript Api 3.15

Here are my steps.

1-First, I load my map service in to my map.

mapService = new ArcGISDynamicMapServiceLayer(mapServiceUrl);

2-Second, I prepared my query that i want to use in order to select a feature

circle = new Circle({center: evt.mapPoint, geodesic: true, radius: 1, radiusUnit: "esriMiles"});    
var query = new Query();
query.geometry = circle;

Please note that the "evt" came when the on map click event is triggered by the user when he clicks on the map.

Now,The user have the option to select features based on a specific layer, lets say that he choosed the featurelayer that has id "1".

i want to retrieve the feature layer from the mapservice so i can call the "selectFeatures" method from it. i am thinking something like this.

var selectedFeatureLayerByUser = mapService.getFeatureLayerById("1");//This is was i am looking for
selectedFeatureLayerByUser .setSelectionSymbol(new SimpleFillSymbol().setOutline(null).setColor("#F0F"));
selectedFeatureLayerByUser.selectFeatures(query ,FeatureLayer.SELECTION_NEW);

I am hoping to find some ideas like the previous example because all the examples i saw, loads a new feature layer then add this feature layer at the map like the following.

featureLayer = new FeatureLayer(mapService + "/1");
featureLayer.setSelectionSymbol(new SimpleFillSymbol().setOutline(null).setColor("#F0F"));
featureLayer.selectFeatures(query ,FeatureLayer.SELECTION_NEW);

which is very confusing to me because i already have a mapservice that contains the featurelayer ,which i think the last example is not the best practice to add a feature layer that was already added by the map service.

Can someone help me with that?

  • Please, read the 'arcgis' tag description, and rettag the question accordingly. Tks. – Andre Silva Feb 25 '16 at 15:51
  • note that ArcGISDynamicMapServiceLayer uses export to return an image of the current extent , so you can't highlight this last , you have two choice : using Graphic Layer and add result as graphic , or using feature layer ( which also extend Graphic layer ) for each service's layers as the above example – Springer F Feb 25 '16 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.