DefaultMapControlsViewModel
Default implementation of MapControlsViewModel.
This ViewModel manages the visibility of map controls based on available space and navigation state. For proper operation, the free roam state must be set via setIsFreeRoam method, which affects the visibility of certain controls like the add road event button.
Measurement mechanism
Controls visibility is calculated based on their measured heights and available space. The measurement flow works as follows:
All visibility states are initialized to
trueso controls can render and be measuredComposable reports each control's height via
set*Height()methodsOnce all heights are known, updateMapControlsVisibilityInternal calculates which controls fit
Controls that don't fit are hidden (visibility = false)
Composable-side requirements
The Composable must report height ONLY when the control is visible. Otherwise, a measurement loop occurs:
Control visible -> height = 255 -> ViewModel hides control
Control hidden -> height = 10 (empty) -> ViewModel shows control
Repeat infinitely (UI flickers)
Correct implementation in MapControl:
.onSizeChanged {
if (visibility) { // Only measure when visible
onHeightChanged(it.height)
}
}Properties
Observable state indicating whether the add road event button should be visible. Shown when all conditions are met:
Observable state indicating whether the compass control should be visible. Visibility depends on available vertical space.
Observable state indicating whether the follow button can be hidden. True for non-pedestrian routes, false for pedestrian routes.
Observable state indicating whether the my location (follow) button should be visible. This control has the highest priority and is shown when any space is available.
Observable state of the remaining vertical space after all visible controls are placed. Null if controls haven't been measured yet, otherwise the unused height in pixels.
Observable state indicating whether the traffic and parking button should be visible. Visibility depends on available space and whether the route is pedestrian.
Observable state indicating whether the zoom controls should be visible. Visibility depends on available vertical space.
Functions
Sets the measured height of the add road event button. Used for calculating visibility based on available space.
Sets the measured height of the compass control. Used for calculating visibility based on available space.
Sets the measured height of the my location (follow) button. Used for calculating visibility based on available space.
Updates the free roam state which affects the visibility of certain controls. In free roam mode, the add road event button may be shown if space permits.
Sets the total available height for map controls area. This triggers recalculation of which controls can fit in the available space.
Sets the measured height of the traffic and parking control. Used for calculating visibility based on available space.
Sets the measured height of the zoom controls. Used for calculating visibility based on available space.