esri.dijit.Legend events - None documented, but are there any?

852
2
Jump to solution
08-16-2012 10:33 AM
JoanneMcGraw
Occasional Contributor III
I realize the documentation for esri.dijit.Legend details no events for it, but I'm wondering if anyone is aware of any that are behind the scenes that I could tap into.

I am providing functionality to dynamically change the rendering for a layer and the user may decide to display 5 legend items or 10 legend items (just as an example). My problem is that if they choose to display the layer using 5, the legend is displayed in the <DIV> fine...it's height and width is dynamically updated to the appropriate size for what the Legend returned. If the user changes to display the layer using 10 legend items, the Legend <DIV>'s content is updated but its size is not. I have to manually resize its container to get the <DIV> itself to resize so I can see the additional entries.

Anyway, I'm fine with introducing the resizing code myself, but I need a Legend event to trap to trigger when to do so. Is there something that will help me with this?

Cheers
jtm
0 Kudos
1 Solution

Accepted Solutions
JoanneMcGraw
Occasional Contributor III
Thank you, geos_rfleet, for your response. After posting the thread yesterday, I approached the problem differently and implemented a solution which is very similar to what I believe you suggest in your post. Rather than using a Legend event, use the GUI library's container events to trigger a resize of the panel.

Rather than Dojo, I am using ExtJs which similarly has events associated with its Panels (or Panes in Dojo). So, instead of trying to ensure the Panel containing the legend's DIV is large enough to display all of the legend's items, I am now simply ensure the legend Panel's size is directly linked to its container's size. If the container (a dialog-like window) is resized, the legend's Panel is resized to fit into the available space whether that means all the legend items are visible or not. This way, if the legend returns more items than can be seen in the legend Panel's current size, the user can manually expand the container it is in to view what was previously hidden.

Alternatively, for anyone who is looking into how to deal with a similar problem, I initially simply ensured the legend Panel's size was large enough to accommodate the most legend items possible (there is a limit of 11 introduced by our application). So, even if only 5 are asked for, there is enough room to show 11 in case the user changes the number later. This approach is certainly the simplest to employ for this type of a problem, but is only possible if you know the maximum number of items you will need to accommodate.

Cheers,
jtm

View solution in original post

0 Kudos
2 Replies
__Rich_
Occasional Contributor III
I realize the documentation for esri.dijit.Legend details no events for it, but I'm wondering if anyone is aware of any that are behind the scenes that I could tap into.

I am providing functionality to dynamically change the rendering for a layer and the user may decide to display 5 legend items or 10 legend items (just as an example). My problem is that if they choose to display the layer using 5, the legend is displayed in the <DIV> fine...it's height and width is dynamically updated to the appropriate size for what the Legend returned. If the user changes to display the layer using 10 legend items, the Legend <DIV>'s content is updated but its size is not. I have to manually resize its container to get the <DIV> itself to resize so I can see the additional entries.

Anyway, I'm fine with introducing the resizing code myself, but I need a Legend event to trap to trigger when to do so. Is there something that will help me with this?

Cheers
jtm

This sounds like a CSS issue and should really, IMHO, be addressed at the root cause.  (div elements should expand according to their contents when used out-of-the-box)

But having said that, the author of the dijit might have written some code that prevents you solving it 'properly' so maybe you'll be forced into some post-update manual adjustments, can't tell for sure without delving into the matter.

Anyway, on the subject of events that might exist, I use the Dojo extension for Firebug so I can see this:

[ATTACH=CONFIG]17032[/ATTACH]

(viewing http://help.arcgis.com/en/webapi/javascript/arcgis/demos/widget/widget_legendvisible.html )

Obviously any non-documented event you hook into may be subject to change without notification blah, blah...

Also looks like it lists any method that starts with "on" as an event so "private" (prefixed with _) 'events' don't show up.

Of course you could dojo.connect onto any method and listen for it being called, but that would be very naughty! 😉
0 Kudos
JoanneMcGraw
Occasional Contributor III
Thank you, geos_rfleet, for your response. After posting the thread yesterday, I approached the problem differently and implemented a solution which is very similar to what I believe you suggest in your post. Rather than using a Legend event, use the GUI library's container events to trigger a resize of the panel.

Rather than Dojo, I am using ExtJs which similarly has events associated with its Panels (or Panes in Dojo). So, instead of trying to ensure the Panel containing the legend's DIV is large enough to display all of the legend's items, I am now simply ensure the legend Panel's size is directly linked to its container's size. If the container (a dialog-like window) is resized, the legend's Panel is resized to fit into the available space whether that means all the legend items are visible or not. This way, if the legend returns more items than can be seen in the legend Panel's current size, the user can manually expand the container it is in to view what was previously hidden.

Alternatively, for anyone who is looking into how to deal with a similar problem, I initially simply ensured the legend Panel's size was large enough to accommodate the most legend items possible (there is a limit of 11 introduced by our application). So, even if only 5 are asked for, there is enough room to show 11 in case the user changes the number later. This approach is certainly the simplest to employ for this type of a problem, but is only possible if you know the maximum number of items you will need to accommodate.

Cheers,
jtm
0 Kudos