Legend Control
The LegendControl acts as a high-level manager for map legends within a Mapbox environment.
It coordinates the lifecycle, visual state, and unit synchronization (Metric/Imperial) of legends. This class handles:
Shared Legends: Uses reference counting to ensure a single legend ID can be used by multiple layers, only removing the UI when the last layer is removed.
Unit Conversion: Supports dynamic toggling between Imperial and Metric units across all hosted legends.
UI Management: Automatically manages a LegendContainerView, including the injection of separators and specialized LegendView instances.
Types
A lifecycle utility that facilitates the "Try Install" pattern between a Host and a LegendControl.
Defines a contract for a UI component (usually an Activity or Fragment) capable of hosting a LegendControl.
Properties
The background color of the legend container.
Max height (dp) of each hosted LegendView's scrollable content area. Host apps can mirror this when sizing the outer getView, or adjust independently via layout params.
Indicates whether tapping the legend view toggles between metric and imperial units. This state should be used by the UI to add a click handler.
Units applied to the hosted legends. Updating this value propagates the new units to each registered legend.
When true, new and updated legends use light text on a dark panel (see setDarkTheme).
Functions
Returns the LegendContainerView associated with this control. This view acts as the visual parent for all individual legend items.
Removes a legend it from the UI if no longer needed.
Replaces a registered legend in the cache and refreshes its view. Use when applying host-side presentation overrides that must survive toggleUnits.
Switches the legend panel to a dark map-overlay style (semi-transparent black panel, white labels). Re-applies presentation to legends already on the control.
Default title color for legends added while the container host color is in effect.
Toggles the measurement units between METRIC and IMPERIAL if toggleUnitsOnTap is true. This function is intended to be called by the UI (e.g., from a click listener).