Select to view content in your preferred language

Creation of empty FeatureLayer

1312
4
Jump to solution
07-21-2022 05:55 PM
Aeseir
by
Frequent Contributor

Is it possible to create an empty feature layer that is populated by client side data later on?

I've only been able to create FeatureLayer when I have data to populate

1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

Yes it can be done easily. You can create an empty client-side FeatureLayer by setting its source property to an empty array. Then you can add and remove features from it by calling applyEdits method. 

This is explained here: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#creating...

This sample shows the process: https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection-edits/

View solution in original post

4 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

Yes it can be done easily. You can create an empty client-side FeatureLayer by setting its source property to an empty array. Then you can add and remove features from it by calling applyEdits method. 

This is explained here: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#creating...

This sample shows the process: https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection-edits/

Aeseir
by
Frequent Contributor

I've tried doing a empty [] for source previously but then it just throws this error: table feature layer can't be displayed. Hence this question :).

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

Please read the doc from the link I provided above. Creating a FeatureLayer section in FeatureLayer doc has a section called Add an array of client-side features. This section explains all required schema properties you need to set to successfully initialize your client-side FeatureLayer. You must set the geometryType property in the class constructor to let the api know that you are creating a spatial FeatureLayer. Otherwise, the api assumes you are creating a non-spatial FeatureLayer and non spatial FeatureLayer cannot be added to the map. 

 

 

 

 

0 Kudos
Aeseir
by
Frequent Contributor

Yep read it through, eventually came across another similar post that resolved it through GeometryType (as per your message here)

0 Kudos