Select to view content in your preferred language

Loss of renderer with runtime-created data source

2103
13
Jump to solution
09-18-2024 06:36 AM
jwilner_amica
Occasional Contributor

Following this post, I created a DataSource from a programmatically generated FeatureLayer.

https://community.esri.com/t5/arcgis-experience-builder-questions/making-runtime-featurelayers-regis...

However, when that DataSource is added to map, it loses its renderer that was defined before. The renderer being used displays some color never used in my UniqueValueRenderer. The code is as follows:

                let layer = new FeatureLayer({
                  source: featureset,  // autocast as a Collection of new Graphic()
                  objectIdField: "OBJECTID",
                  geometryType: "polygon",
                  popupTemplate: template,
                  fields: swath.value.fields,
                  title: 'Hail Swath ' + dt,
                  opacity: 0.8
                })
                layer.renderer = {
                  type: "unique-value",  // autocasts as new UniqueValueRenderer()
                  // @ts-ignore
                  field: "diameter_in_label",
                  defaultSymbol: {
                    type: "simple-fill",
                    outline: line,
                    color: [209, 0, 152, 1.0]
                  },
                  uniqueValueInfos: [{
                    value: '0.75"',
                    symbol: {
                      type: "simple-fill",  // autocasts as new SimpleFillSymbol()
                      color: [255, 255, 190, 1.0],
                      outline: line
                    }
                  }, ... ** Omitted long renderer **
                  }]
                }
 
                const data: DataSourceJson = {
                  id: 'Hail Swath ' + dt,
                  layerId: layer.id,
                  type: DataSourceTypes.FeatureLayer,
                  label: layer.title,
                }

                const dataJson = Immutable(data)
                const dataSourceOptions = {
                  id: 'Hail Swath ' + dt,
                  layer: layer,
                  dataSourceJson: dataJson,
                }

                dsManager.current.createDataSource(dataSourceOptions).then((source) => {
                  const sourceId = source.id
                  const addMapData = {
                    jimuMapViewId: map.current.id,
                    dataSourceId: sourceId,
                    dataChangeType: DataChangeType.Create,
                    dataChangeStatus: DataChangeStatus.Fulfilled
                  }

                  let mapDatas = { sourceId: addMapData }
                  map.current.addOrRemoveDataOnMap(mapDatas)
 
                }).catch((error) => {
                  console.error('Error creating DataSource:', error);
                });
 
Any help would be appreciated, thank you!
0 Kudos
13 Replies
MohammedHilal_K
Occasional Contributor

When I use jimuMapView.addLayerToMap(dsId, customLayerId) inside a loop, the DataAction ("Add to Table") works only for the last item in the array. If I add a single layer, the data action works perfectly. I've noticed this behavior in both Experience Builder versions 1.14 and 1.15.

However, when using addOrRemoveDataOnMap, I don't encounter this issue, but the layer ordering doesn't follow the intended sequence. In contrast, with addLayerToMap(), I can use await since it returns a promise.
Any help?

0 Kudos
QunSun
by Esri Contributor
Esri Contributor

@MohammedHilal_K Can you try calling jimuMapView.addLayerToMap() serially to solve this problem? Similar to the following code

async function addMultipleLayersToMapOneByOne(items) {
    for (const item of items) {
      const { dataSourceId, targetLayerId } = item;
      await jimuMapView.addLayerToMap(dataSourceId, targetLayerId);
    }
  }
0 Kudos
MohammedHilal_K
Occasional Contributor

@QunSun @jwilner_amica 
still Not working. Also in targetLayerId, what Id it actually required? I'm using 'Wolrd Hillshade' as basemap with no predefined layers. 
Also below code works for me for MapImageLayer and FeatureLayer. but what about FeatureService? how can we pass the FeatureService to createJimuLayerView?

jimuMapView.view.map.add(featureService)
jimuMapView.createJimuLayerView(featureService, jimuMapView.id, index, dataSourcetrue)

am creating feature service using below code, but after added to the map, data action(add to table ) is not available. 
await Layer.fromArcGISServerUrl({
            url: url
          })


Any help?
0 Kudos
YueyangLi
Esri Contributor

@MohammedHilal_K

targetLayerId is a custom ID you want to set to the layer, as long as you ensure that the ID does not conflict with other layer IDs.

The data action (add to table) is available only for the data sources supporting the query. Layer.fromArcGISServerUrl(featureServiceUrl) will return a Maps SDK group layer, that doesn't support query. The workaround is adding the layers/tables under the feature service individually.

0 Kudos