Getting Field information off Sublayer of a MapImage Layer

1351
3
Jump to solution
10-03-2018 08:03 PM
deleted-user----ypwdOWHsd
New Contributor III

Hi,

I am creating an application with arcgis js 4.8 api. I bring in a WebMap into this application, which has a MapImage Layer. This MapImage Layer has multiple sublayers. I need to know the fields that exist in these sublayers, and I also need to know the type of each field (number, string... etc). The sublayer interface is here: Sublayer | API Reference | ArcGIS API for JavaScript 4.9. I can use the "popupTemplate" in the sublayer and then go into the fieldInfos property of that to get the names of the fields, however that does not have the type information for each field. Does anyone have any idea how to get the type information for each field of a sublayer?

Thanks

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Cameron,

   Full field info data is not available from the Sublayer object you will have to get the sublayer url and make an esriRequest to the sublayer to get the field data.

esriRequest(layer.findSublayerById(0).url, {
  responseType: "json",
  query: "f=json"
}).then(function(response){
  // The requested data
  var lyrJson = response.data;
  console.log(lyrJson.fields);
});

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Cameron,

   Full field info data is not available from the Sublayer object you will have to get the sublayer url and make an esriRequest to the sublayer to get the field data.

esriRequest(layer.findSublayerById(0).url, {
  responseType: "json",
  query: "f=json"
}).then(function(response){
  // The requested data
  var lyrJson = response.data;
  console.log(lyrJson.fields);
});
deleted-user----ypwdOWHsd
New Contributor III

Understood. Thanks a lot Robert!

0 Kudos
MartinLohoff
New Contributor

Hi at all.

Since API version 4.15 you can access the field property auf a sublayer. For details see Sublayer | ArcGIS API for JavaScript 4.16 . Just call the function "load" of the sublayer. After that you can access all fields.

Best regards

Martin

0 Kudos