I've managed to successfully create and add a data source to map, preserving its rendering and giving it DataSource capabilities (add to table, select tool, etc.). However, those DataSource capabilities are lost as soon as the layer is reordered in the layer list widget. My FeatureLayer and DataSource are defined as follows:
let layer = new FeatureLayer({
source: featureset, // autocast as a Collection of new Graphic()
objectIdField: "OBJECTID",
geometryType: "polygon",
popupTemplate: template,
fields: swath.value.fields,
title: 'Hail Swath ' + dt,
opacity: 0.8,
layerId: 0,
})
const data: DataSourceJson = {
id: 'hail_ds_' + dt,
layerId: layer.id,
type: DataSourceTypes.FeatureLayer,
label: layer.title,
}
const dataJson = Immutable(data)
const dataSourceOptions = {
id: 'hail_ds_' + dt,
layer: layer,
layerId: layer.id,
dataSourceJson: dataJson,
}
dsManager.current.createDataSource(dataSourceOptions).then((source) => {
map.current.view.map.add(layer)
console.log(layer.id)
map.current.createJimuLayerView(
layer, map.current.id, layer.id, source, true
).then((response) => {
console.log(response)
setStatus('Hail from ' + dt + ' added')
})
}).catch((error) => {
console.error('Error creating DataSource:', error);
});
Unsure why reordering removes DataSource functionality, I assume it is something to do with the layerId property, but I cannot find a sensible configuration of that property that makes it work, so it may not be that at all.
This post is a follow-up on runtime FeatureLayer / DataSource creation, for more prior context as to how I got here, reference this post:
https://community.esri.com/t5/arcgis-experience-builder-questions/loss-of-renderer-with-runtime-created-data-source/m-p/1540095#M14963