I'm using a variation of the latest patented Jeffrey Thompson EB 1.16 method of adding new layers+datasources to an EB map widget, from a custom widget.
Link to Jeffrey's code sample:Add/Remove Layers 3.0 - Full Settings Panel Support for Enterprise Deployment
However the Table widget that i have linked to the map widget is throwing random datasource-not-found errors, for example: "Can not find data source: 19442c5c7d2-layer-5".
These errors happen randomly, with about a quarter of the added layers, and prevent the data table from displaying correctly in the table widget. It's not the same layer(s) each time which error, but a random subset of layers. Note that i'm typically adding multiple layers at the same time, depending on which theme the user selects. That means i'm calling my addLayer() function below multiple times in quick succession.
Has anyone seen this sort of thing before? I'm using EB 1.16.
I include some code snippets below:
export async function addLayer(mapView, layerList, layerIndex, visible, labels=null) {
const layer = layerList.layers[layerIndex];
// Has the layer already been added to the map?
let mlayer = mapView.view.map.layers.find((l) => { return (l.myIndex != undefined && l.myIndex == layerIndex) });
if (mlayer == undefined) { // If not, then add it.
var newlayer = createLayer(layer, layerIndex, visible, labels); // A complicated function that creates a new FeatureLayer/GroupLayer/ImageLayer/etc.
if (newlayer != null) {
addLayerAndDataSource(mapView, newlayer);
}
} else {
console.log('Layer: \'' + layer.name + '\' is already on map.');
}
}
function addLayerAndDataSource(jmv, layer, index = -1) {
if (index == -1) { // Just append it to end of layer list
jmv.view.map.add(layer);
} else { // Insert it at a specific order in the layer list
jmv.view.map.add(layer, index);
}
if (layer.type === 'feature') {
reactiveUtils.when(() => layer.loaded, () => { makeLayerView(jmv, layer); })
} else if (layer.type === 'group') {
// Need to also make the views & data sources for all the child featurelayers.
layer.allLayers.forEach((childlayer) => {
if (childlayer.type === 'feature') {
reactiveUtils.when(() => childlayer.loaded, () => { makeLayerView(jmv, childlayer); })
}
});
}
}
const makeLayerView = async (jmv, layer) => {
const dataSource = await createDataSource(layer.id, layer);
const layerView = await jmv.createJimuLayerView(layer, null, 0, dataSource, true);
}
const createDataSource = async (dsId: string, layer: object): Promise<DataSource> => {
const dsJson = await fetchDataSourceJson(dsId, layer);
const dsOptions: FeatureLayerDataSourceConstructorOptions = {
id: dsId,
dataSourceJson: dsJson
}
return DataSourceManager.getInstance().createDataSource(dsOptions);
}
const fetchDataSourceJson = async (dsId: string, layer: object): Promise<IMDataSourceJson> => {
const dsJson = await dataSourceJsonCreator.createDataSourceJsonByJSAPILayer(dsId, layer);
return dsJson;
}