Select to view content in your preferred language

Cannot Create Datasource from Publicly Shared Layer

433
2
01-06-2025 07:26 AM
Labels (1)
JeffreyThompson2
MVP Frequent Contributor

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.

JeffreyThompson2_0-1736177038646.png

GIS Developer
City of Arlington, Texas
0 Kudos
2 Replies
YueyangLi
Esri Contributor

Hi @JeffreyThompson2 ,

 

Thanks for raising the issue. I tested creating a data source based on a public feature layer item but couldn’t reproduce the error. Could you share a data source JSON that can reproduce it? Did you log in when reproducing the issue? It would be even better if you could click this line to show why it’s trying to read 'token'.

YueyangLi_0-1736304391236.png

 

Thanks,

Yueyang

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

JeffreyThompson2_0-1736342351792.png

//dataSourceJson object extracted from Chrome Dev Tools
{
    "id": "realEstate4",
    "type": "FEATURE_LAYER",
    "sourceLabel": "RealEstate - Easement",
    "layerId": "4",
    //correct file path in orginal object
    "url": "...filePath/RealEstate/MapServer/4",
    "geometryType": "esriGeometryPolygon"
}

The error stack from the Promise result reads: Error: data source id: realEstate0, TypeError: Cannot read properties of undefined (reading 'token')
at ...filePath/cdn/17/jimu-core/index.js:2:165965

Yes, I should be logged in. And layers that require some sort of authentication load without issue.

GIS Developer
City of Arlington, Texas
0 Kudos