Hi all,
I'm trying to create a simple custom widget that works like the following:
- In the Settings, the user can select an item (a featureclass / layer) from ArcGIS Online
- In the actual widget during runtime, when the user presses the button in the widget, the widget adds onto the map the exact same features as that featureclass / layer but without it being linked to that ArcGIS Online featureclass (i.e. any changes i make in experience builder I DO NOT want it to show up on ArcGIS Online).
I want the added data to also be editable and accessible by other widgets, so I think that means I have to create a new datasource. Currently in my widget.tsx I have the following sort of function for when the button is pressed:
const handleAddLayer = (evt) => {
evt.preventDefault()
console.log()
console.log("YAY Button Pressed")
const dsManager = DataSourceManager.getInstance()
dsManager.createAllDataSources().then(()=>{
if (props.useDataSources.length >= 1) {
for (let i = 0; i < props.useDataSources.length; i++) {
const dsSource = props.useDataSources[i]
const ogds = dsManager.getDataSource(dsSource.dataSourceId)
const ogJson = ogds.getDataSourceJson()
//New ID
const newid = dsSource.dataSourceId + '_copy_' + Date.now()
//Create New Datasource
dsManager.createDataSource({
id: newid,
dataSourceJson: ogJson
})
}
}
})
}
Currently I haven't added the code to add the map (which I will do later), but I keep getting an error that I'm failing to create the datasource and I'm not sure why. If someone can offer some insight and help me out that would be greatly appreciated.
Code seems good.
Error messages and snapshots will help.
Hi @jsu,
To achieve your goal, you don’t need to create a copy of the data source, because the original and the copy share the same service/item. Once you call apply edits, the changes will also be reflected on ArcGIS Online. Instead, you can try "ogds.setRecords()" to update the loaded records only.
Best,
Yueyang
But it sounded like he did not want it applied to AGOL, or at least not applied as an edit to the Layer?
This sounds like creating a 'collection bucket' feature service, which might be able to have the same data structures (individual features) copied into or referenced, might be what is being attempted here.
it's interesting though.