I believe I have found a bug in the createDataSource function in Developer Edition 1.16. I have made a custom widget designed to make a datasource from a Feature Layer. It works successfully on dozens of layers, but it failed on a specific set of layers. Here are the functions, I use.
const fetchDataSourceJson = async (dsId: string, layer: object) : Promise<IMDataSourceJson> => {
const dsJson = await dataSourceJsonCreator.createDataSourceJsonByJSAPILayer(dsId, layer)
//console.log(dsJson)
return dsJson
}
const createDataSource = async (dsId: string, layer: object) : Promise<DataSource> => {
const dsJson = await fetchDataSourceJson(dsId, layer)
const dsOptions: FeatureLayerDataSourceConstructorOptions = {
id: dsId,
dataSourceJson: dsJson
}
//console.log(dsOptions)
return DataSourceManager.getInstance().createDataSource(dsOptions)
}
const makeLayerView = async (dsId: string, layer) => {
const dataSource = await createDataSource(layer.id, layer)
const layerView = await jimuMapView.addLayerAndCreateJimuLayerView(layer, dataSource)
//console.log(layerView)
}After some research, we discovered that the layers it fails on are shared Publicly. All of the other layers are either shared to the Organization, to a Group, or are Hosted layers. Setting the sharing level to Organization fixed the problem with these layers.
During the createDataSource function, a Promise is rejected because a token is undefined. I assume the issue is that a Public layer does not generate a token while other ways of sharing do and that this was not an intentional programing choice.
