@@ -4,32 +4,94 @@ import UIKit
44// EXPERIMENTAL: Not intended for usage in current stata. Subject to change or deletion.
55final class IndoorExample : UIViewController , ExampleProtocol {
66 private var mapView : MapView !
7- // Set indoor style. Do not commit staging style URIs.
87 private var styleURI : String ?
98 private var cancellables = Set < AnyCancelable > ( )
9+ private let styleTextField = UITextField ( )
10+ private let loadStyleButton = UIButton ( type: . system)
1011
1112 override func viewDidLoad( ) {
1213 super. viewDidLoad ( )
1314
1415 let cameraOptions = CameraOptions (
15- center: CLLocationCoordinate2D ( latitude: 40.6441 , longitude: - 73.7824 ) ,
16+ center: CLLocationCoordinate2D ( latitude: 35.5483 , longitude: 139.7780 ) ,
1617 zoom: 16 ,
1718 bearing: 12 ,
1819 pitch: 60 )
19- let options = MapInitOptions ( cameraOptions: cameraOptions)
2020
21+ let options = MapInitOptions ( cameraOptions: cameraOptions)
2122 mapView = MapView ( frame: view. bounds, mapInitOptions: options)
22- mapView. mapboxMap. styleURI = StyleURI ( rawValue: styleURI!) !
2323
24- mapView. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
2524 mapView. ornaments. options. scaleBar. visibility = . visible
26- // EXPERIMENTAL: Not intended for usage in current stata. Subject to change or deletion.
27- mapView. mapboxMap. indoor. selectFloor ( selectedFloorId: " b937e2aa3423453ab0552d9f " )
28- mapView. mapboxMap. indoor. onIndoorUpdated. sink { indoorState in
29- print ( indoorState)
25+ mapView. ornaments. options. indoorSelector. visibility = . visible
26+
27+ var puckConfiguration = Puck2DConfiguration . makeDefault ( showBearing: true )
28+ puckConfiguration. pulsing = nil
29+ mapView. location. options. puckType = . puck2D( puckConfiguration)
30+
31+ mapView. location. onLocationChange. observeNext { [ weak mapView] newLocation in
32+ guard let mapView, let location = newLocation. last else { return }
33+ mapView. mapboxMap. setCamera ( to: . init( center: location. coordinate, zoom: 18 ) )
3034 } . store ( in: & cancellables)
3135
36+ mapView. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
37+
38+ mapView. mapboxMap. indoor. onIndoorUpdated. sink { indoorState in
39+ print ( " Selected floor id: \( indoorState. selectedFloorId) " )
40+ } . store ( in: & cancellables)
3241 view. addSubview ( mapView)
42+
43+ setupStyleInputUI ( )
44+ }
45+
46+ private func setupStyleInputUI( ) {
47+ styleTextField. borderStyle = . roundedRect
48+ styleTextField. backgroundColor = . white
49+ styleTextField. autocapitalizationType = . none
50+ styleTextField. autocorrectionType = . no
51+ styleTextField. text = " mapbox://styles/mapbox/standard "
52+ styleTextField. placeholder = " Enter Style URI or JSON "
53+ styleTextField. translatesAutoresizingMaskIntoConstraints = false
54+
55+ loadStyleButton. setTitle ( " Load Style " , for: . normal)
56+ loadStyleButton. backgroundColor = . systemBlue
57+ loadStyleButton. setTitleColor ( . white, for: . normal)
58+ loadStyleButton. layer. cornerRadius = 5
59+ loadStyleButton. addTarget ( self , action: #selector( loadStyleTapped) , for: . touchUpInside)
60+ loadStyleButton. translatesAutoresizingMaskIntoConstraints = false
61+
62+ let stackView = UIStackView ( arrangedSubviews: [ styleTextField, loadStyleButton] )
63+ stackView. axis = . horizontal
64+ stackView. spacing = 8
65+ stackView. translatesAutoresizingMaskIntoConstraints = false
66+ stackView. layoutMargins = UIEdgeInsets ( top: 8 , left: 8 , bottom: 8 , right: 8 )
67+ stackView. isLayoutMarginsRelativeArrangement = true
68+ stackView. backgroundColor = UIColor . white. withAlphaComponent ( 0.8 )
69+
70+ view. addSubview ( stackView)
71+
72+ NSLayoutConstraint . activate ( [
73+ stackView. leadingAnchor. constraint ( equalTo: view. leadingAnchor) ,
74+ stackView. trailingAnchor. constraint ( equalTo: view. trailingAnchor) ,
75+ stackView. bottomAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. bottomAnchor) ,
76+ loadStyleButton. widthAnchor. constraint ( equalToConstant: 100 )
77+ ] )
78+ }
79+
80+ @objc private func loadStyleTapped( ) {
81+ guard let text = styleTextField. text, !text. isEmpty else { return }
82+ loadStyle ( from: text)
83+ styleTextField. resignFirstResponder ( )
84+ }
85+
86+ private func loadStyle( from text: String ) {
87+ let trimmed = text. trimmingCharacters ( in: . whitespacesAndNewlines)
88+ if let url = URL ( string: trimmed) , url. scheme != nil {
89+ if let styleURI = StyleURI ( rawValue: trimmed) {
90+ mapView. mapboxMap. styleURI = styleURI
91+ }
92+ } else {
93+ mapView. mapboxMap. styleJSON = trimmed
94+ }
3395 }
3496
3597 override func viewDidAppear( _ animated: Bool ) {
0 commit comments