1- import SwiftUI
21import MapboxMaps
2+ import SwiftUI
33
44struct ViewportPlayground : View {
55 @State var viewport : Viewport = . styleDefault
66 @State var mapStyle : MapStyle = . standard
77 @State var useSafeAreaAsPaddings : Bool = true
88 @State var additionalSafeArea : Bool = true
99 @State var settingsHeight = 0.0
10+ @State var collapsed = false
1011
1112 var body : some View {
12- Map ( viewport: $viewport) {
13- Puck2D ( bearing: . course)
14-
15- ForEvery ( parks. coordinates, id: \. latitude) { coord in
16- MapViewAnnotation ( coordinate: coord) {
17- Image ( systemName: " tree " )
18- . foregroundColor ( . white)
19- . padding ( . all, 5 )
20- . background (
21- Circle ( )
22- . strokeBorder ( . black, lineWidth: 0.5 )
23- . background ( Circle ( ) . fill ( Color ( . systemGreen) ) )
24- )
13+ ZStack {
14+ Map ( viewport: $viewport) {
15+ Puck2D ( bearing: . course)
16+
17+ ForEvery ( parks. coordinates, id: \. latitude) { coord in
18+ MapViewAnnotation ( coordinate: coord) {
19+ Image ( systemName: " tree " )
20+ . foregroundColor ( . white)
21+ . padding ( . all, 5 )
22+ . background (
23+ Circle ( )
24+ . strokeBorder ( . black, lineWidth: 0.5 )
25+ . background ( Circle ( ) . fill ( Color ( . systemGreen) ) )
26+ )
27+ }
28+ . allowOverlap ( true )
2529 }
26- . allowOverlap ( true )
27- }
2830
29- PolygonAnnotation ( id: " polygon " , polygon: maineBoundaries)
30- . fillColor ( StyleColor ( red: 0 , green: 128 , blue: 255 , alpha: 0.5 ) !)
31- . fillOutlineColor ( StyleColor ( . black) )
32- }
33- . mapStyle ( mapStyle)
34- . debugOptions ( [ . camera, . padding] )
35- . usesSafeAreaInsetsAsPadding ( useSafeAreaAsPaddings)
36- . additionalSafeAreaInsets ( . bottom, additionalBottomSafeArea)
37- . ignoresSafeArea ( )
38- . overlay ( alignment: . bottomLeading) {
39- VStack ( alignment: . leading, spacing: 0 ) {
40- Text ( " Viewport sate: \( viewportShortDescription) " )
41- MiniToggle ( title: " Use safe area as padding " , isOn: $useSafeAreaAsPaddings)
42- MiniToggle ( title: " Use additional safe area " , isOn: $additionalSafeArea)
31+ PolygonAnnotation ( id: " polygon " , polygon: maineBoundaries)
32+ . fillColor ( StyleColor ( red: 0 , green: 128 , blue: 255 , alpha: 0.5 ) !)
33+ . fillOutlineColor ( StyleColor ( . black) )
4334 }
44- . font ( . safeMonospaced)
45- . floating ( )
46- . onChangeOfSize { size in
47- settingsHeight = size. height
35+ . mapStyle ( mapStyle)
36+ . debugOptions ( [ . camera, . padding] )
37+ . usesSafeAreaInsetsAsPadding ( useSafeAreaAsPaddings)
38+ . additionalSafeAreaInsets ( . bottom, additionalBottomSafeArea)
39+ . frame ( width: collapsed ? 400 : nil , height: collapsed ? 200 : nil )
40+ . ignoresSafeArea ( )
41+ . overlay ( alignment: . trailing) {
42+ MapStyleSelectorButton ( mapStyle: $mapStyle)
43+ }
44+
45+ VStack ( alignment: . leading) {
46+ Spacer ( )
47+ VStack ( alignment: . leading, spacing: 0 ) {
48+ Text ( " Viewport sate: \( viewportShortDescription) " )
49+ MiniToggle ( title: " Use safe area as padding " , isOn: $useSafeAreaAsPaddings)
50+ MiniToggle ( title: " Use additional safe area " , isOn: $additionalSafeArea)
51+ MiniToggle ( title: " Collapsed " , isOn: $collapsed)
52+ }
53+ . font ( . safeMonospaced)
54+ . floating ( )
55+ . onChangeOfSize { size in
56+ settingsHeight = size. height
57+ }
4858 }
49- }
50- . overlay ( alignment: . trailing) {
51- MapStyleSelectorButton ( mapStyle: $mapStyle)
5259 }
5360 . toolbar {
5461 ToolbarItem {
@@ -58,7 +65,7 @@ struct ViewportPlayground: View {
5865 }
5966
6067 private var additionalBottomSafeArea : CGFloat {
61- additionalSafeArea ? settingsHeight : 0
68+ ( additionalSafeArea && !collapsed ) ? settingsHeight : 0
6269 }
6370
6471 var viewportShortDescription : String {
@@ -86,8 +93,8 @@ struct ViewportPlayground: View {
8693 case . geometryCollection:
8794 geometryType = " geometryCollection "
8895 #if USING_TURF_WITH_LIBRARY_EVOLUTION
89- @unknown default :
90- geometryType = " unknownType "
96+ @unknown default :
97+ geometryType = " unknownType "
9198 #else
9299 #endif
93100 }
@@ -126,7 +133,9 @@ private struct ViewportMenu: View {
126133 viewport = . styleDefault
127134 }
128135 Button ( " .camera() " ) {
129- viewport = . camera( center: CLLocationCoordinate2D ( latitude: 41.8915 , longitude: - 87.6087 ) , zoom: 16.52 , bearing: 290 , pitch: 68.5 )
136+ viewport = . camera(
137+ center: CLLocationCoordinate2D ( latitude: 41.8915 , longitude: - 87.6087 ) , zoom: 16.52 , bearing: 290 ,
138+ pitch: 68.5 )
130139 }
131140 Button ( " .overview(.multiPoint()) " ) {
132141 viewport = viewport ( for: parks, coordinatePadding: 20 )
@@ -152,7 +161,9 @@ private struct ViewportMenu: View {
152161 }
153162 Button ( " [easeIn] .camera() " ) {
154163 withViewportAnimation ( . easeIn( duration: 1 ) ) {
155- viewport = . camera( center: CLLocationCoordinate2D ( latitude: 41.8915 , longitude: - 87.6087 ) , zoom: 16.52 , bearing: 290 , pitch: 68.5 )
164+ viewport = . camera(
165+ center: CLLocationCoordinate2D ( latitude: 41.8915 , longitude: - 87.6087 ) , zoom: 16.52 ,
166+ bearing: 290 , pitch: 68.5 )
156167 }
157168 }
158169 Button ( " [fly] .overview(.multiPoint()) " ) {
@@ -206,28 +217,30 @@ private let parks = MultiPoint([
206217 CLLocationCoordinate2D ( latitude: 35.141689 , longitude: - 115.510399 ) ,
207218] )
208219
209- private let maineBoundaries = Polygon ( [ [
210- CLLocationCoordinate2D ( latitude: 45.13745 , longitude: - 67.13734 ) ,
211- CLLocationCoordinate2D ( latitude: 44.8097 , longitude: - 66.96466 ) ,
212- CLLocationCoordinate2D ( latitude: 44.3252 , longitude: - 68.03252 ) ,
213- CLLocationCoordinate2D ( latitude: 43.98 , longitude: - 69.06 ) ,
214- CLLocationCoordinate2D ( latitude: 43.68405 , longitude: - 70.11617 ) ,
215- CLLocationCoordinate2D ( latitude: 43.09008 , longitude: - 70.64573 ) ,
216- CLLocationCoordinate2D ( latitude: 43.08003 , longitude: - 70.75102 ) ,
217- CLLocationCoordinate2D ( latitude: 43.21973 , longitude: - 70.79761 ) ,
218- CLLocationCoordinate2D ( latitude: 43.36789 , longitude: - 70.98176 ) ,
219- CLLocationCoordinate2D ( latitude: 43.46633 , longitude: - 70.94416 ) ,
220- CLLocationCoordinate2D ( latitude: 45.30524 , longitude: - 71.08482 ) ,
221- CLLocationCoordinate2D ( latitude: 45.46022 , longitude: - 70.66002 ) ,
222- CLLocationCoordinate2D ( latitude: 45.91479 , longitude: - 70.30495 ) ,
223- CLLocationCoordinate2D ( latitude: 46.69317 , longitude: - 70.00014 ) ,
224- CLLocationCoordinate2D ( latitude: 47.44777 , longitude: - 69.23708 ) ,
225- CLLocationCoordinate2D ( latitude: 47.18479 , longitude: - 68.90478 ) ,
226- CLLocationCoordinate2D ( latitude: 47.35462 , longitude: - 68.2343 ) ,
227- CLLocationCoordinate2D ( latitude: 47.06624 , longitude: - 67.79035 ) ,
228- CLLocationCoordinate2D ( latitude: 45.70258 , longitude: - 67.79141 ) ,
229- CLLocationCoordinate2D ( latitude: 45.13745 , longitude: - 67.13734 )
230- ] ] )
220+ private let maineBoundaries = Polygon ( [
221+ [
222+ CLLocationCoordinate2D ( latitude: 45.13745 , longitude: - 67.13734 ) ,
223+ CLLocationCoordinate2D ( latitude: 44.8097 , longitude: - 66.96466 ) ,
224+ CLLocationCoordinate2D ( latitude: 44.3252 , longitude: - 68.03252 ) ,
225+ CLLocationCoordinate2D ( latitude: 43.98 , longitude: - 69.06 ) ,
226+ CLLocationCoordinate2D ( latitude: 43.68405 , longitude: - 70.11617 ) ,
227+ CLLocationCoordinate2D ( latitude: 43.09008 , longitude: - 70.64573 ) ,
228+ CLLocationCoordinate2D ( latitude: 43.08003 , longitude: - 70.75102 ) ,
229+ CLLocationCoordinate2D ( latitude: 43.21973 , longitude: - 70.79761 ) ,
230+ CLLocationCoordinate2D ( latitude: 43.36789 , longitude: - 70.98176 ) ,
231+ CLLocationCoordinate2D ( latitude: 43.46633 , longitude: - 70.94416 ) ,
232+ CLLocationCoordinate2D ( latitude: 45.30524 , longitude: - 71.08482 ) ,
233+ CLLocationCoordinate2D ( latitude: 45.46022 , longitude: - 70.66002 ) ,
234+ CLLocationCoordinate2D ( latitude: 45.91479 , longitude: - 70.30495 ) ,
235+ CLLocationCoordinate2D ( latitude: 46.69317 , longitude: - 70.00014 ) ,
236+ CLLocationCoordinate2D ( latitude: 47.44777 , longitude: - 69.23708 ) ,
237+ CLLocationCoordinate2D ( latitude: 47.18479 , longitude: - 68.90478 ) ,
238+ CLLocationCoordinate2D ( latitude: 47.35462 , longitude: - 68.2343 ) ,
239+ CLLocationCoordinate2D ( latitude: 47.06624 , longitude: - 67.79035 ) ,
240+ CLLocationCoordinate2D ( latitude: 45.70258 , longitude: - 67.79141 ) ,
241+ CLLocationCoordinate2D ( latitude: 45.13745 , longitude: - 67.13734 ) ,
242+ ]
243+ ] )
231244
232245struct MapViewportExample_Previews : PreviewProvider {
233246 static var previews : some View {
0 commit comments