I am a little stuck here and I hope someone can point me to the right place.
Using the ArcGIS-js-api in Angular / Typescript
I am able to display a WebMap via an internal Portal instance.
I can access the Layers that the Map is composed of but I am unable to get the layer as a featureLayer.
All of the examples I see are adding a featureLayer to the map.
How can I get a featureLayer from the Map?
Solved! Go to Solution.
It looks like it is a problem with Typings. The code works when casting directly:
Paul,
If you are taking 3.x then it is as simple as:
var incidentLayer = map.getLayer("incidentLayer");
This assumes you know the id of the layer.
Thanks for the response,
I am using 4.8 and there is no getLayer method on the Map
Paul,
Be sure to add a tag to your post or some text stating the API version your are targeting.
So in 4.x when using a WebMap you just use the WebMaps findLayerById
https://developers.arcgis.com/javascript/latest/api-reference/esri-WebMap.html#findLayerById
I did try that and I get the same issue as when I loop through the Layer Collection
FindLayerById returns a Layer and I don't know how to cast to a FeatureLayer
Type 'Layer' is not assignable to type 'FeatureLayer'.
Property 'capabilities' is missing in type 'Layer'.
Paul,
Is it really a FeatureLayer in the Web Map then? Are you sure it is not a Whole MapService and thus a MapImageLayer?
When I loop through the layers the type is feature
Our C# code on Xamarin with the .Net API autocasts the same layer as expected.
Paul,
If that is the case then when you use findLayerById then the returned layer will already be a FeatureLayer class.
Isn't there a way to do this without providing the value through a hard-coded string?
Something like:
var layers = this.map.getLayers();
// process layers in a for-each loop...
It looks like it is a problem with Typings. The code works when casting directly: