import legend/layerlist widget into custom widget

1143
9
05-31-2018 09:08 AM
scottmiller10
New Contributor II

My goal is to import the legend and layerlist widgets into my custom widget so I can use them all in one panel. Is this something I can do? 

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus

Scott,


  Absolutely. Just add a few dives to your panel and set the styling for height and width and when you use the constructor method on the Legend and LayerList just place them in those divs.

scottmiller10
New Contributor II

Thanks for your help! The legend works, but it only shows up in my custom widget when I open up the legend widget. Is there a way to do this, maybe put the constructor in the legend.startup()? I think it happens because it only constructs the legend in legend.onOpen().

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Scott,

The legend works, but it only shows up in my custom widget when I open up the legend widget

???

I thought you where placing the Legend widget inside your custom widget panel? So what do you mean when you open the Legend widget?

scottmiller10
New Contributor II

Robert, 

I went into the Legend widget and pointed the constructors html parameter to a div in my custom widget. I wasn't aware that I could import the entire Legend into my custom widget. How do I go about doing that?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Scott,

  Maybe you should show some code as it seems like we are not understanding each other.

0 Kudos
scottmiller10
New Contributor II

In the Legend widget's function onOpen(), I changed the Legend constructor to 

this.legend = new Legend(legendParams, document.getElementById('legend'));

the 'legend' element is the name of the <div> in my custom widget, where I want the legend to appear. 

This makes it so that when I open the Legend widget from the panel, the Legend items appear in my custom widget in the 'legend' div. 

It works great, but I would like it to work without having to open the Legend widget from the panel.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Scott,

   So are you talking about a WAB Widget? If so that is why I am confused since you are posting in the JS API space and not the WAB space.

0 Kudos
scottmiller10
New Contributor II

Yes, sorry I wasn't aware they were different. Is there a way I can redirect my post?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Scott,


  I will move it to the WAB space. So now that I understand you are using WAB this changes things. On is that in your custom widget you do not want to add the WAB otb Legend widget but just add the JS API Legend dijit.


0 Kudos