Select to view content in your preferred language

Create a Datasource from a FeatureLayer

1741
5
03-04-2022 07:41 AM
RobertScheitlin__GISP
MVP Emeritus

I am struggling to figure out how to create a DataSource from a FeatureLayer that is created in a Widget.tsx.

I am not allowing the user to select a DataSource, I am creating a FeatureLayer in code and then adding it to the map. Now I want to open this FeatureLayer in the Table widget so I need a DataSource to pass.

@ShengdiZhang 

Tags (2)
5 Replies
Dvirus
by
Regular Contributor
0 Kudos
clc
by
Regular Contributor

I am facing the same problem for the same reasons. My widget creates a FeatureLayer and I would like this FeatureLayer to be viewed in the AttributeTable. I have no input datasource. Thanks for any suggestions.

agrescavage
Emerging Contributor

Did you ever solve this? I've been trying to figure out how to do this as well. The documentation seems to imply this is possible/expected, but the documentation and examples aren't of much help.

0 Kudos
clc
by
Regular Contributor

Nope.

I agreed the documentation seems to imply that it is possible but it remained  mystery for me. I tried to use their example in the Widget Development guide: "1.2 Use a widget's output data source" with a dummy input data source (to get the schema), but I still cannot figure how to load my own generated features.  

0 Kudos
clc
by
Regular Contributor

So I came back to it and managed to get a solution with my dummy input source. I used the Esri example  "1.2 Use a widget's output data source" for the setting.tsx file. Then in my widget.tsx file, I did not use the DataSourceComponent and just use the DataSourceManager to get an instance of my output datasource:

  const [myDSout, setMyDSout] = useState<FeatureLayerDataSource>(null)
  DataSourceManager.getInstance().createDataSource(props.outputDataSources[0]).then((result: FeatureLayerDataSource) => {
    setMyDSout(result)
  })
Then from my array of graphics, I created and array of records and used the setSourceRecords method. Finally just like in their example, I used the setStatus  et setCountStatus method. 
 
As you can see, I did not use the dummy input datasource at all in the widget.tsx file, it was just in the setting.tsx file to provide a data source id for my output datasource. I'd like to get rid of this dummy input data source as the Esri documentation states that in the createDataSource method of the DataSourceManager: "The parameter can be a data source id, data source config JSON or DataSourceConstructorOptions" but I have been unsuccessful.
I tried to pass the following parameter:
  const myOutJson = {
    id: `${props.id}-ouput`,
    type: DataSourceTypes.FeatureLayer,
    label: `${props.manifest.name}-output`,  
    isDataInDataSourceInstance: true,
    isOutputFromWidget: true
  } as IMDataSourceJson
But I got the following error: "Datasource without origin data source must save the schema in app config." which was mentioned in their documentation. I tried to add a schema file in my app config, but do not know the exact syntax (and I am not sure that my parameter outOutJson is right either...) .
Any help for creating a data source config JSON would be appreciated.
Thanks
0 Kudos