Select to view content in your preferred language

Access layer features and data in Experience Builder Widget Development

4829
21
11-02-2023 10:01 AM
Labels (1)
diplonics
Emerging Contributor
Long background in Openlayers but taking on the Experience Builder Widget development challenge and so far okay. However can't fathom how to access a layers data after its added to the map. Could someone point me to a tutorial or resource on what I thought I could easily where I want to generate a UI element containing some of the layer attribute data after it loads. So I need to get the data and loop through it. I can get the data fine and display it on the map but can't seem to access it through the layer, view or layerView objects.
 
Code currently using to get the data is as follows:

 

const layer = new this.GeoJSONLayer({
	url: requestURL,
	customParameters: {
		request: this.state.bbox,
	},
	title: "New data",
	renderer: {
		type: "simple",
		symbol: {
			type: "simple-line",
			width: 2,
			Color: "blue"
		}
	}
});
JimuMapView.view.map.add(layer);
// After the layer is created try to build UI element from layer data.
layer.on('layerview-create', (event) => {
	try{
		const results = event.layerView.queryFeatures();
		const graphics = results.features;
		console.log(graphics);				//Just returns null
	}catch (error){
		console.error("query failed: ", error);
	}
})

 

0 Kudos
21 Replies
diplonics
Emerging Contributor

Agree it should be just a case of if/else try/catch once the return has been resolved. However, I'm obviously not understanding the promise flow properly.

In the sample code if/else where the console.log(no data) line of code runs, it does output correctly once the .then has been resolved. However, just before that console.log runs the errors shown in the image about 'can't resolve layer view' happen.

The .catch at the end does not run so I must be structuring something else wrong..

I think I need to catch the error before the .then as it gets resolved after the .queryFeatures I'd imagine.

So can I put a .catch before the .then!!

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GeoJSONLayer.html#queryFea...

Maybe you could query the featureCount before querying the actual data.

GIS Developer
City of Arlington, Texas
0 Kudos