lowgas

dynamically grabbing layers from a FeatureService

Discussion created by lowgas on Jan 7, 2011
Latest reply on Jan 7, 2011 by lowgas
is it possible to dynamically grab the layers from a feature service?

currently i have the layers hardcoded in my application... i have been tinkering some,
and can do this:
 var tmp = "http://myserver/ArcGIS/rest/services/webedit/FeatureServer/";
 var max = 9;
 for(var i=0;i<max;i++){
  var fl = new esri.layers.FeatureLayer(tmp+i,{
   mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
   outFields:["*"]
  });
  editLayers.push(fl);
 }



however this is not ideal, because i sitll must go out to look at the service to see what to set the max to....

i would love to do something like:
 //var tmp = "http://myserver/ArcGIS/rest/services/webedit/FeatureServer/";
        var tmp = new esri.layers.featurelayer(myservice);
 var max = tmp.layers.count;

 for(var i=0;i<max;i++){
  var fl = new esri.layers.FeatureLayer(tmp+i,{
   mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
   outFields:["*"]
  });
  editLayers.push(fl);
 }


this way, the gis guys can go about changing the service how they want.. and i wont have to make any changes to my application.... heh. the gis team only get my services for a short time, then im off to other projects.

Outcomes