Select to view content in your preferred language

How to get fields of Dynamic Layer hosted by ArcGIS Server?

235
3
Jump to solution
09-04-2024 01:58 PM
ForrestLin
Frequent Contributor

How to get fields of Dynamic Layer hosted by ArcGIS Server using JavaScript?

ForrestLin_0-1725483838327.png

 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

You can create a FeatureLayer object from the REST endpoint URL, and get the information from its fields collection after it loads:

const featureLayer = new FeatureLayer({
	url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
});

featureLayer.when(function() {
	featureLayer.fields.forEach(function(field) {
		console.info(field.name + " ( type: " + field.type + ", alias: " + field.alias + " )");
	});
});

featureLayer.load();

 

View solution in original post

0 Kudos
3 Replies
JoelBennett
MVP Regular Contributor

You can create a FeatureLayer object from the REST endpoint URL, and get the information from its fields collection after it loads:

const featureLayer = new FeatureLayer({
	url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
});

featureLayer.when(function() {
	featureLayer.fields.forEach(function(field) {
		console.info(field.name + " ( type: " + field.type + ", alias: " + field.alias + " )");
	});
});

featureLayer.load();

 

0 Kudos
ForrestLin
Frequent Contributor

@JoelBennett 

Thanks.

0 Kudos
ForrestLin
Frequent Contributor
  public loadFields(url: string): Promise<Field[]> {
    const featureLayer = new FeatureLayer({ url });
    return featureLayer.load().then((layer: FeatureLayer) => {
          return layer.fields;
      });
  }
0 Kudos