Need help building a custom legend

I tried to build a custom legend that could work with CDSView. I am able to get the labels right, however, unable to render glyphs in the legend.

I have posted the issue with details here:

Please help me out with this.