Select to view content in your preferred language

How to get the data source for added layer?

1232
6
Jump to solution
09-18-2024 05:42 PM
Labels (1)
Ming
by
Frequent Contributor
With Experience Builder Developer edition v1.15, after add a feature layer to map, is there any event knows that the data source has been updated?
In following code, the dsObservations is undefined.
 
 const fullObservationsLayer: __esri.FeatureLayer = new FeatureLayer({
                    url: props.config.fullObservationsUrl
                  })
                  currentJimuMapView.view.map.add(fullObservationsLayer)
                  currentJimuMapView.view.whenLayerView(fullObservationsLayer)
                    .then(async function (layerView) {
                      const dsManager = DataSourceManager.getInstance()
                      const dsMain = dsManager.getDataSource(currentJimuMapView.dataSourceId)
                      await dsMain.childDataSourcesReady()
                      const dsObservations: FeatureLayerDataSource = dsManager.getDataSource(`${dsMain.id}-${layerView.layer.id}`) as FeatureLayerDataSource
                    })
                    .catch(function (error) {
                      console.log(error.message)
                    })
 
Thanks for any idea!
 
Or this following link is the only way to add data source to map for Experience Builder Developer edition?
0 Kudos
1 Solution

Accepted Solutions
JeffreyThompson2
MVP Frequent Contributor

It took me about a year to fully understand this concept, but adding data to the map and creating an Experience Builder datasource are two entirely separate things. Adding a layer to the map will make it appear visually, but many of the advanced data functions will not be available. 

To get all of the data functions, you must convert your FeatureLayer to a datasource and send a message to the framework notifying it of a new datasource. Your code does not do these things. If you need all of the data functions, you need to use some code like in the link above. The solution in this post found a better version of my code. https://community.esri.com/t5/arcgis-experience-builder-questions/loss-of-renderer-with-runtime-crea...

Also here is a complete working widget that add and removes layers as datasources. https://community.esri.com/t5/experience-builder-custom-widgets/add-remove-layers-2-0/ta-p/1540096

GIS Developer
City of Arlington, Texas

View solution in original post

6 Replies
JeffreyThompson2
MVP Frequent Contributor

It took me about a year to fully understand this concept, but adding data to the map and creating an Experience Builder datasource are two entirely separate things. Adding a layer to the map will make it appear visually, but many of the advanced data functions will not be available. 

To get all of the data functions, you must convert your FeatureLayer to a datasource and send a message to the framework notifying it of a new datasource. Your code does not do these things. If you need all of the data functions, you need to use some code like in the link above. The solution in this post found a better version of my code. https://community.esri.com/t5/arcgis-experience-builder-questions/loss-of-renderer-with-runtime-crea...

Also here is a complete working widget that add and removes layers as datasources. https://community.esri.com/t5/experience-builder-custom-widgets/add-remove-layers-2-0/ta-p/1540096

GIS Developer
City of Arlington, Texas
Ming
by
Frequent Contributor

Awesome @JeffreyThompson2 , thank you so much!

0 Kudos
SerjStol
Frequent Contributor

Thanks! I suspected this to be the case as I was confused about adding data sources and adding a layer to the map. There is also client and server side output data sources, which I don't quite understand. I am just trying to implement addition of output feature layer to the map but rather do it in the same way that Add Data widget does it. Runtime data source sample widget doesnt help much...

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

Be aware that there is a major breaking change at 1.16. The devs removed the hacky way we have been making datasources and created some new functions to facilitate the process. This post has code for making a datasource from an API FeatureLayer in 1.16.

https://community.esri.com/t5/arcgis-experience-builder-questions/cannot-create-datasource-from-publ...

GIS Developer
City of Arlington, Texas
SerjStol
Frequent Contributor

Thanks for the headsup. I have to use 1.14 ExB Dev due to it being the version compatible with Enterprise 11.3. I import the custom widget to Portal.

Is this method you mention the same way Add Data widget is doing it? I am currently trying to reverse engineer it. I see it publishes a message and I should be able to use "Add to Map" data action trigger on the Map Widget when the data source is created.

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

I don't think it's exactly the same, but it is similar.

GIS Developer
City of Arlington, Texas
0 Kudos