Select to view content in your preferred language

How to retrieve the Fields available in a Dynamic map's sub-layers

2380
10
08-15-2011 09:04 PM
StephenLead
Regular Contributor III
See the sample below, which adds a DynamicMapServiceLayer to a map using the URL:

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/MapServer

Navigating to this REST endpoint in a browser shows the component Layers, and each layer's Fields.

How can I retrieve this information programatically? I need a list of the available layers (0,1,2) and each layer's available fields (eg layer 0 contains objectid, lifecyclestatus, incident_number, etc)

My goal is to add this information to a Query function, so I need to know that I can search layer 1 for the field collection_time, etc.

Looping through the layerInfos tells me about each available layer - how can I retrieve information on the fields? (One option is to create a new feature layer from each layer and add it to the map, but I'd really like to avoid this workaround).

Thanks,
Steve

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>layer infos</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.4/js/dojo/dijit/themes/claro/claro.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.4"></script>
    <script type="text/javascript">
      dojo.require("esri.map");

      function init() {
        var map = new esri.Map("map");
        
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
        map.addLayer(basemap);

        var url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/MapServer/";
        var dynLayer = new esri.layers.ArcGISDynamicMapServiceLayer(url);
        map.addLayer(dynLayer);

        dojo.connect(dynLayer, "onLoad", function() {
            var infos = dynLayer.layerInfos;
            for (var i = 0; i <= infos.length - 1; i++) {
                var layerId = infos.id;
                var restEndPoint = url + layerId;

                //restEndPoint is the layer's URL - how can I retrieve its fields?

            }
        });
        
      }

      dojo.addOnLoad(init);
    </script>
  </head>
  <body class="claro">
    <div id="map" style="width:900px; height:600px; border:1px solid #000;"></div>
  </body>
</html>
0 Kudos
10 Replies
AdrianMarsden
Regular Contributor II
Ah, that'll be it then :cool: another good reason to get my code sorted, so I can move to 10 (currently shifting an ArcGIS Image Server Service off ArcIMS, in order for me to migrate the rest to 10, before moving the rest of my stuff to AGS)
0 Kudos