@@ -71,12 +71,12 @@ final class DebugMapExample: UIViewController, ExampleProtocol {
7171 style: . plain,
7272 target: self ,
7373 action: #selector( openDebugOptionsMenu ( _: ) ) )
74- let tileCover = UIBarButtonItem (
75- title: " Tiles " ,
74+ let infoBarItem = UIBarButtonItem (
75+ title: " Info " ,
7676 style: . plain,
7777 target: self ,
78- action: #selector( tileCover ) )
79- navigationItem. rightBarButtonItems = [ debugOptionsBarItem, tileCover ]
78+ action: #selector( showInfo ) )
79+ navigationItem. rightBarButtonItems = [ debugOptionsBarItem, infoBarItem ]
8080 }
8181
8282 override func viewDidAppear( _ animated: Bool ) {
@@ -96,10 +96,66 @@ final class DebugMapExample: UIViewController, ExampleProtocol {
9696 present ( navigationController, animated: true , completion: nil )
9797 }
9898
99- @objc private func tileCover( ) {
99+ private func extractStyleInfo( ) -> StyleInfo {
100+ let styleJSON = mapView. mapboxMap. styleJSON
101+
102+ guard let data = styleJSON. data ( using: . utf8) ,
103+ let parsedStyle = try ? JSONDecoder ( ) . decode ( StyleJson . self, from: data) else {
104+ return StyleInfo ( modifiedDate: " Unknown " , sdkCompatibility: " Unknown " , styleURL: " Unknown " )
105+ }
106+
107+ let modifiedDate = parsedStyle. modified ?? " Unknown "
108+
109+ let sdkCompatibility : String
110+ if let compatibility = parsedStyle. metadata? . compatibility {
111+ var compatibilityParts : [ String ] = [ ]
112+ if let ios = compatibility. ios {
113+ compatibilityParts. append ( " iOS: \( ios) " )
114+ }
115+ if let android = compatibility. android {
116+ compatibilityParts. append ( " Android: \( android) " )
117+ }
118+ if let js = compatibility. js {
119+ compatibilityParts. append ( " JS: \( js) " )
120+ }
121+ sdkCompatibility = compatibilityParts. isEmpty ? " Unknown " : compatibilityParts. joined ( separator: " \n " )
122+ } else {
123+ sdkCompatibility = " Unknown "
124+ }
125+
126+ let styleURL : String
127+ if let origin = parsedStyle. metadata? . origin, !origin. isEmpty {
128+ styleURL = origin
129+ } else {
130+ styleURL = mapView. mapboxMap. styleURI? . rawValue ?? " Unknown "
131+ }
132+
133+ return StyleInfo ( modifiedDate: modifiedDate, sdkCompatibility: sdkCompatibility, styleURL: styleURL)
134+ }
135+
136+ @objc private func showInfo( ) {
137+ // Get tiles information
100138 let tileIds = mapView. mapboxMap. tileCover ( for: TileCoverOptions ( tileSize: 512 , minZoom: 0 , maxZoom: 22 , roundZoom: false ) )
101- let message = tileIds. map { " \( $0. z) / \( $0. x) / \( $0. y) " } . joined ( separator: " \n " )
102- showAlert ( withTitle: " Displayed tiles " , and: message)
139+ let tilesMessage = tileIds. map { " \( $0. z) / \( $0. x) / \( $0. y) " } . joined ( separator: " \n " )
140+
141+ // Get style information
142+ let styleInfo = extractStyleInfo ( )
143+ let styleMessage = """
144+ Style URL: \( styleInfo. styleURL)
145+ Modified: \( styleInfo. modifiedDate)
146+ SDK Compatibility:
147+ \( styleInfo. sdkCompatibility)
148+ """
149+
150+ // Combine both
151+ let combinedMessage = """
152+ TILES:
153+ \( tilesMessage)
154+
155+ STYLE INFO:
156+ \( styleMessage)
157+ """
158+ showAlert ( withTitle: " Map Info " , and: combinedMessage)
103159 }
104160
105161 private func handle( statistics: PerformanceStatistics ) {
@@ -341,3 +397,31 @@ extension PerformanceStatistics {
341397 """
342398 }
343399}
400+
401+ struct StyleInfo {
402+ let modifiedDate : String
403+ let sdkCompatibility : String
404+ let styleURL : String
405+ }
406+
407+ struct StyleJson : Codable {
408+ let modified : String ?
409+ let metadata : Metadata ?
410+ }
411+
412+ struct Metadata : Codable {
413+ let origin : String ?
414+ let compatibility : Compatibility ?
415+
416+ enum CodingKeys : String , CodingKey {
417+ case origin = " mapbox:origin "
418+ case compatibility = " mapbox:compatibility "
419+ }
420+ }
421+
422+ struct Compatibility : Codable {
423+ let ios : String ?
424+ let android : String ?
425+ let js : String ?
426+ }
427+
0 commit comments