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.
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.
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.
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).