MapScaleView
Displays a legend with distance information for the associated map.
Declaration
@MainActor @preconcurrency struct MapScaleViewOverview
You can use this with Map as a standalone view, for example:
struct ScaleTestView: View {
@Namespace var mapScope
var body: some View {
VStack {
Map(scope: mapScope)
MapCompass(scope: mapScope)
}
.mapScope(mapScope)
}
}The scale indicator grows and shrinks (although visually, its frame is static) based on the zoom level of the map. By default the leading edge remains anchored and the trailing edge moves as the scale changes. If the scale is trailing aligned, then it may be more visually appealing to anchor the ScaleView to the trailing edge
ZStack(alignment: .trailing) {
Map(mapScope)
MapScaleView(anchorEdge: .trailing, scope: mapScope)
}
.mapScope(mapScope)You can also use MapScaleView with the mapControls(_:) modifier, as shown in this example:
Map()
.mapControls {
MapScaleView()
}