I'm trying to build a custom widget using the typescript setup as described in Create a custom widget | ArcGIS API for JavaScript 4.7.
Here's the essence of what the widget does:
1. User sees a map, and can click anywhere to add points.
2. Points are added to a local graphics collection, which is used as source for default layer.
3. That layer is passed to the widget, which then should render a list item for each feature in the collection.
The problem: My individual <li> elements are not rendering correctly.
In my widget code, I am using a private method to render the individual <li> items, although this seems unnecessary. (It also didn't work to render them directly inside the .map() method.)
Here's the code that seems to be giving me problems:
<SPAN class="comment token">// Public method</SPAN>
<SPAN class="token function">render</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">(</SPAN>
<SPAN class="operator token"><</SPAN>div<SPAN class="operator token">></SPAN>
<SPAN class="operator token"><</SPAN>ul<SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>layer<SPAN class="punctuation token">.</SPAN>source<SPAN class="punctuation token">.</SPAN><SPAN class="token function">map</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">,</SPAN> index<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">let</SPAN> item <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">_renderItem</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">,</SPAN> index<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'item'</SPAN><SPAN class="punctuation token">,</SPAN> item<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> item<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>ul<SPAN class="operator token">></SPAN>
<SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>div<SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">// Private method</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="token function">_renderItem</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">,</SPAN> index<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> any <SPAN class="punctuation token">{</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'feature'</SPAN><SPAN class="punctuation token">,</SPAN> feature<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'attributes'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="operator token"><</SPAN>li key<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">{</SPAN>index<SPAN class="punctuation token">}</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">{</SPAN>feature<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'attributes'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>li<SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>If I console log "item" on line 8, it gives me an object like the following:
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"vnodeSelector"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"li"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"properties"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"key"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">2</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"text"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"test 3"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"domNode"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">null</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I am expecting a dom node instead. So my widget renders a <ul> filled with [object Object] strings. I'm not sure what I'm doing wrong. I tried to mimic the way that other widgets use .map() (for example in this one arcgis-js-api/Feature.tsx at 4master · Esri/arcgis-js-api · GitHub ).
I'll attach the whole app if anyone is interested in taking a look. Feeling kinda stuck. It's written in typescript. Run npm install and then run npm run dev to start the typescript compiler, then open index.html in a browser or host with something like http-server.
I'm still learning typescript, so there are some compiling errors, but I don't think that has anything to do with my problem.
Thank you to anyone who's read this far!