Hi Team,
In ExpBuilder, in Data tab, I have added a webmap and used it as source for map widget. And in our custom widgets, we are trying to access the datasources of every layer (our webmap has group layers, sub layers, feature layers). However, the datasource objects of all layers are undefined. And DatasourceManagerInstance::datasources has only one object which is datasource of WebMap.
Here is the snippet Im using to retrieve instance of datasource of layers. Always getting the 'Data source object is undefined.'. How can we fix this.
Another point, if we use function 'getOrCreateLayerDataSource' on JimuLayerView, its creating a datasource instance but this instance is different and the datasource instance used by OOTB widgets of ExpB for eg., Select widget is different.
Please guide.
const allJimuLayerViews = jimuMapView.getAllJimuLayerViews()
// Ensure all layer views are loaded
jimuMapView.whenAllJimuLayerViewLoaded().then(() => {
// Use DataSourceManager to get existing data sources
const dataSourceManager = DataSourceManager.getInstance();
const dataSourcePromises = allJimuLayerViews.map(jlv => {
const dataSourceId = jlv.layerDataSourceId; // Assuming layerDataSourceId is available
if (dataSourceId) {
return dataSourceManager.getDataSource(dataSourceId);
} else {
console.error('Layer DataSource ID not found for layer view:', jlv);
return Promise.resolve(null); // Return null if dataSourceId is not found
}
});
Promise.all(dataSourcePromises).then(dsObjs => {
dsObjs.forEach(dsObj => {
if (dsObj) {
console.error('Data source object is defined.');
} else {
console.error('Data source object is undefined.');
}
});
}).catch(error => {
console.error('Error retrieving data sources:', error);
});
});
Thanks in advance.