@@ -19,10 +19,13 @@ public final class MapInitOptions: NSObject {
1919 public let mapOptions : MapOptions
2020
2121 /// Style URI for initializing the map. Defaults to Mapbox Standard.
22- public let styleURI : StyleURI ?
22+ public var styleURI : StyleURI ? { mapStyle ? . data . asURI }
2323
2424 /// String representation of JSON style spec. Has precedence over ``styleURI``.
25- public let styleJSON : String ?
25+ public var styleJSON : String ? { mapStyle? . data. asJson }
26+
27+ /// Map style for map initialization.
28+ public let mapStyle : MapStyle ?
2629
2730 /// Camera options for initializing the map. CameraOptions default to 0.0 for each value.
2831 public let cameraOptions : CameraOptions ?
@@ -45,17 +48,42 @@ public final class MapInitOptions: NSObject {
4548 /// can be `nil`.
4649 /// - styleJSON: Style JSON in String representation. Has precedence over ``styleURI``.
4750 /// - antialiasingSampleCount: Sample count to control multisample anti-aliasing (MSAA) option for rendering.
48- public init (
51+ convenience public init (
4952 mapOptions: MapOptions = MapOptions ( ) ,
5053 cameraOptions: CameraOptions ? = nil ,
5154 styleURI: StyleURI ? = . standard,
5255 styleJSON: String ? = nil ,
5356 antialiasingSampleCount: Int = 1
5457 ) {
55- self . mapOptions = mapOptions
56- self . cameraOptions = cameraOptions
57- self . styleURI = styleURI
58- self . styleJSON = styleJSON
58+ let mapStyle : MapStyle ? = if let styleJSON {
59+ MapStyle ( json: styleJSON)
60+ } else if let styleURI {
61+ MapStyle ( uri: styleURI)
62+ } else {
63+ nil
64+ }
65+ self . init ( mapStyle: mapStyle,
66+ mapOptions: mapOptions,
67+ cameraOptions: cameraOptions,
68+ antialiasingSampleCount: antialiasingSampleCount)
69+ }
70+
71+ /// Creates new map init options.
72+ ///
73+ /// - Parameters:
74+ /// - mapStyle: Map style to load, defaults to Mapbox Standard style.
75+ /// - mapOptions: Map rendering options.
76+ /// - cameraOptions: Camera options overriding the default camera that has been specified in the style.
77+ /// - antialiasingSampleCount: Sample count to control multisample anti-aliasing (MSAA) option for rendering.
78+ public init (
79+ mapStyle: MapStyle ? ,
80+ mapOptions: MapOptions = MapOptions ( ) ,
81+ cameraOptions: CameraOptions ? = nil ,
82+ antialiasingSampleCount: Int = 1
83+ ) {
84+ self . mapOptions = mapOptions
85+ self . cameraOptions = cameraOptions
86+ self . mapStyle = mapStyle
5987 self . antialiasingSampleCount = antialiasingSampleCount
6088 }
6189
@@ -106,13 +134,17 @@ extension MapInitOptions {
106134 scaleFactor: mapOptions. __scaleFactor)
107135
108136 // Use the overriding style URI if provided (currently from IB)
109- let resolvedStyleURI = overridingStyleURI. map { StyleURI ( url: $0) } ?? styleURI
137+ let resolvedStyle = if let overridingStyleURI,
138+ let uri = StyleURI ( url: overridingStyleURI) {
139+ MapStyle ( uri: uri)
140+ } else {
141+ mapStyle
142+ }
110143
111144 return MapInitOptions (
145+ mapStyle: resolvedStyle,
112146 mapOptions: resolvedMapOptions,
113- cameraOptions: cameraOptions,
114- styleURI: resolvedStyleURI,
115- styleJSON: styleJSON)
147+ cameraOptions: cameraOptions)
116148 } else {
117149 return self
118150 }
0 commit comments