how to include text from json (REST) to a legend?

386
1
Jump to solution
11-08-2022 10:07 AM
nadja_swiss_parks
Occasional Contributor II

I'm trying to add a description to a legend. I figured out how to show the legend and how to add the description if it is a plain text. I'm stuck on how to pass the description to the legend. Could anyone help me?

I created a minimal example: https://codepen.io/nwp_nadja_bernhard/pen/yLEVdZz 

The code in question starts at row 173;
in the function fetchAsync (row 177) I manage to address the desired text -> desc;
in the function create_legend (row 204) I manage to add a static text in the desired place "content" -> description - currently commented;

--> How can I pass the text into the legend content?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Sage_Wall
Esri Contributor

Hi @nadja_swiss_parks I think you need to await the response from your fetchAsync() function.

You can check out how I got it to work in this codepen ( https://codepen.io/sagewall/pen/zYaNmMq?editors=0011 ) .  I wrapped the entire script in (async () => {})() so it would run asynchronously and then just await  the fetchAsync response on line 254, and I think it's working with those modifications if I understood the question correctly.

View solution in original post

1 Reply
Sage_Wall
Esri Contributor

Hi @nadja_swiss_parks I think you need to await the response from your fetchAsync() function.

You can check out how I got it to work in this codepen ( https://codepen.io/sagewall/pen/zYaNmMq?editors=0011 ) .  I wrapped the entire script in (async () => {})() so it would run asynchronously and then just await  the fetchAsync response on line 254, and I think it's working with those modifications if I understood the question correctly.