Select to view content in your preferred language

Getting access to featurelayers that are already in the map

845
4
01-19-2012 11:06 AM
GarethMann
Deactivated User
All of the samples that work with feature layers define a feature layer and then set it to the full URL of a map service and then add that layer to the map. But what happens if my featurelayer is already in the map because I have already added the entire map service with all the layers I need via "ArcGISDynamicMapServiceLayer"?

I.e. lets say I want to modify the symbology of a specific layer that is already in the map, how do I get access to it?
0 Kudos
4 Replies
derekswingley1
Deactivated User
...what happens if my featurelayer is already in the map because I have already added the entire map service with all the layers I need via "ArcGISDynamicMapServiceLayer"?

Can you elaborate on how this works? I'm not sure what you mean.

You can get a reference to a layer using map.getLayer("<layer_id>"). layer_id is the (optional) id you specify in your layer's options when you create it. If your layer doesn't have an id, the map automatically generates one. If you don't know a layer's ID, look at map.layerIds(tiled and dynamic map service IDs) or map.graphicsLayerIds(graphics and feature layer IDs).
0 Kudos
GarethMann
Deactivated User
Thanks Swingley that is useful. But I think there is a very fundamental concept of all this that I have not yet grasped.

My map service has a total of 4 feature layers in it (3 polygon layers and 1 polyline layer). I already added the map service to the map (with all 4 layers of course as they are all in one mxd project which sits within the map service). I added them to the map by defining an "ArcGISDynamicMapServiceLayer" and specifying the URL of the map service.

Now I want to allow a user to interact with the interface and specify how to symbolize one specific feature layer within that map service.

The samples that show how to symbolize feature layers (under the category "Renderers") all show how you can take a single layer from an existing map service, render it in a specific way, and then add it to the map. If I was to do this then I would end up having that specific feature layer in the map twice right? That is not what I want at all. I want to access a specific layer within the map service that has already been added to the map.

Using the map.layerIds property that you suggested only gives me access to the single map service that I have in the map, not the individual feature layers that are contained within that map service.
0 Kudos
derekswingley1
Deactivated User
I think we need to talk a bit more about the differences between a dynamic map service layer and a feature layer.

My map service has a total of 4 feature layers in it (3 polygon layers and 1 polyline layer). I already added the map service to the map (with all 4 layers of course as they are all in one mxd project which sits within the map service). I added them to the map by defining an "ArcGISDynamicMapServiceLayer" and specifying the URL of the map service.

So far so good.


Now I want to allow a user to interact with the interface and specify how to symbolize one specific feature layer within that map service.

The samples that show how to symbolize feature layers (under the category "Renderers") all show how you can take a single layer from an existing map service, render it in a specific way, and then add it to the map. If I was to do this then I would end up having that specific feature layer in the map twice right?

Currently, you can't apply a new renderer to a dynamic map service. You will be able to do it with version 10.1 of ArcGIS Server, but unti then you'll need to use a feature layer. And yes, adding a feature layer from a map service that's already added to your map as a dynamic service will duplicate the layer (the feature layer will be vector graphics, and you can change their symbols, and the layer in the dynamic map service will appear as it does it ArcMap). To get around the duplication, you can hide the layer in your dynamic map service using setVisibleLayers.


I want to access a specific layer within the map service that has already been added to the map.

Sorry, not possible until 10.1.


Using the map.layerIds property that you suggested only gives me access to the single map service that I have in the map, not the individual feature layers that are contained within that map service.

Use that to turn off the layer you need to display as a feature layer.

It's also worth mentioning one of the fundamental differences between a dynamic map service layer and a feature layer:  the dynamic map service layer retrieves a single image from the server while a feature layer retrieves feature geometry and attributes. You might recognize this as raster (dyn. map service) vs. vector (feature layer) data.
0 Kudos
GarethMann
Deactivated User
Thanks for the comprehensive response Swingley. It appears I have been going about this the wrong way entirely.

The system is somewhat counter-intuitive to somebody that is used to dealing with ESRI data in ArcMap or ArcIMS, or even the old ARCGIS Server using .NET. Traditionaly the purpose of an mxd file was to group various layers together in a "project" but to still allow modification and editing of those layers in that project. So this new way of treating an mxd as a static snapshot of data represents a reversal of that traditional concept.

Essentially the best way to go about planning a solution with the Javascript API is to place every featurelayer that one intends to use in a seperate mxd file and host each one in a seperate map service. This will offer the most flexibility in symbolizing and ordering layers. And seems to be the most efficient way of retrieving layers.

To get around the duplication, you can hide the layer in your dynamic map service using setVisibleLayers.


But this is somewhat redudant, you are suggesting to add the layer in the map twice and then hide one of them. Surely the optimum strategy would be to remove the featurelayer from the mxd in that map service entirely and then place it in a seperate map service alltogether correct? That way I would not need to go through the additional step of adding it to the map twice and then hiding one of them. Luckily for me the featurelayer that i intend to allow modification of sits at the very bottom of the TOC, if it was somewhere in the middle then 3 seperate map services would be neccesary (1 for the layers ontop of the layer that will be modified, 1 for the layer that will be modified, and 1 for the layers that will sit underneath the layer that will be modified). This is why I imagine that the method of storing these layers that allows the best flexibility is to place each one in seperate mxds and seperate map services.
0 Kudos