map.getLayer(id) always retuns null

7958
11
06-23-2011 06:40 PM
JesseMetcalfe
New Contributor
Hi,
I want to access a layer from my mapservice so that I can query and apply definition expression to it.
But I am always getting null valye when I access map.getLayer("id") method.

Any help on the right direction is greatly appreciated.

Jesse
Tags (2)
0 Kudos
11 Replies
NitinBele
New Contributor
In my case I want to access sublayer from a parent layer in the map service.I m too getting null reference when I fire map.getLayer() function.

Any help please ?

Lucas
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jesse,

   Make sure you are passing the getlayer the name of the Map Service as you have it named in the app.

<esri:ArcGISDynamicMapServiceLayer id="Parcels" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer"/>
var arc:ArcGISDynamicMapServiceLayer = map.getLayer("Parcels") as ArcGISDynamicMapServiceLayer();  
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lucas,

   You can not retrieve a sublayer from the map using this or any function, only a whole Map Service.
0 Kudos
NitinBele
New Contributor
Thank you Robert,

Then could you please suggest me the way to perform Definition query on the sublayer of map service ?

I think that only setting <featureLayer>.url (<layerpath>) and <featureLayer>.definitionexpression wont surve the purpose ?

Please suggest.

Lu.
0 Kudos
NitinBele
New Contributor
Just to mention that My map service has 4 feature classes (0,1,2,3) and 3 tables (4,5,6).My requirement is to define query on featureclass -1.
I know that var layer:ArcGISDynamicMapServiceLayer = map.getLayer("Parcels") as ArcGISDynamicMapServiceLayer(); will give me reference of Map Service.

Do I have to publish that feature class seperately ?

Lu.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lu,

   You said
My requirement is to define query on featureclass -  1
Well the QueryTask allows you to specify the exact layer of  the map service that you which to query.

Set the URL to the ArcGIS Server REST resource that represents a single layer or table, e.g.  http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5.  Note the number "5" at the end of the URL which indicates which  specific layer you want to query when querying a map service or a  feature service.  For an image server, the map service itself is the 'single' layer, so  the URL would end with "/MapServer" (without a number).
Now if you only want to visually display a particular layer of a map service on the map than setting the layerDefinitions for the ArcGISDynamicMapServiceLayer is the way to go. A featurelayer is a option but this places all the rendering strain on the client machine and is be overkill for your requirement.

ArcGISDynamicMapServiceLayer info:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/ArcGISDynamicMapServiceLayer.html

QueryTask Info:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/tasks/QueryTask.html
0 Kudos
NitinBele
New Contributor
Thanks Robert,

That was really helpfull.However I am using FeatureLayer for defining expression and I need to move to layerDefinition.

I did not fully understood the concept of layerDefinitions though.
let say my map service is -
<address>/ArcGIS/rest/services/XYZ/MapServer
It has three Feature Classes -
a - <address>ArcGIS/rest/services/XYZ/MapServer/0
b - <address>ArcGIS/rest/services/XYZ/MapServer/1
c - <address>ArcGIS/rest/services/XYZ/MapServer/2

Now I want to assign LayerDefinition expression (Name = "ABC") to <address>ArcGIS/rest/services/XYZ/MapServer/1
then what should go to my layerDefinitions array ?

     myDynamicLayer.layerDefinitions = [
         null,
         "Name = 'ABC'",
         null,
         ];
Please suggest ?

Lu
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Lu,

   The layerDefinitions array is a array that contains a sql statement for every layer in the map service. In your case it would look like:

myDynamicLayer.layerDefinitions = [null, "NAME = 'ABC'", null];
0 Kudos
NitinBele
New Contributor
Thanks Robert, it worked like charm.

Lucas.
0 Kudos