We have "rolled our own" legend in Experience Builder because the out-of-box legend lacks functionality we needed it. It works fine for most things. Of course it has a key defecit ... it depends on the renderer settings of the ReST endpoint of the feature layer to determine what symbology to should be for the layers, and to draw a little symbol. This is SUPER tedious to deal with because there are so many types of layers and symbologies, that you need a giant chunk of switch or if-then logic to figure out what each layer type is and how to draw a symbol.
We keep thinking, there must be some standard Esri way of doing this? It is bonkers that Esri is expecting us to recreate all the logic for legend rendering, right?
But we just can't find any examples that really cover all the potential cases for layer types and generate a cute little symbol swatch like we see in the AGO map viewers. I thought I found the source code for it in Esri's GitHub once ... specifically the source for the Experience Builder Dev Edition Legend Widget... but when I went back later to use it, I couldn't find it again.
Additionally, not only can we not find a complete example of the logic to handle the layer types for legend rendering, but we also do not see how to access the symbolization settings that are stored in the "visualization" tab for an AGO item. In other words, a feature layer might have some renderer defined for it, but it appears that the settings in the visualization tab for an AGO item can override the ReST endpoint. An example is a layer I created that has a Drawing Info value of:
{"labelingInfo":null,"renderer":{"label":"Survey Point","symbol":{"angle":0,"color":[255,0,0,255],"outline":{"color":[255,255,0,255],"width":1},"size":8,"style":"esriSMSCircle","type":"esriSMS","xoffset":0,"yoffset":0},"type":"simple"},"transparency":0}
However, five minutes ago I changed the fill color to purple, not red (so it should be something like [255,0,128,255] instead of [255,0,0,255]). So the ReST endpoint either gets overridden by the visualization setting, or takes a while to update from it. However, we would really like to just be able to directly access the updated visualization setting. Which I cannot seem to figure out how to find in the ArcGIS Online API ... I can't even find it in the ArcGIS Online Assistant.
So what is the standard method by which someone would render their own legend symbolx? Do we really need to re-invent a wheel that Esri has conquered a million times over?