diff --git a/Sources/MapLibreSwiftUI/MapView.swift b/Sources/MapLibreSwiftUI/MapView.swift index c85442e..7e9394a 100644 --- a/Sources/MapLibreSwiftUI/MapView.swift +++ b/Sources/MapLibreSwiftUI/MapView.swift @@ -9,7 +9,7 @@ public struct MapView: UIViewControllerRepresentable { @Binding var camera: MapViewCamera - let makeViewController: (() -> T)? + let makeViewController: (() -> T)? let styleSource: MapStyleSource let userLayers: [StyleLayerDefinition] @@ -37,31 +37,31 @@ public struct MapView: UIViewControllerRepresentable { var clusteredLayers: [ClusterLayer]? public init( - makeViewController: @autoclosure @escaping () -> T, + makeViewController: @autoclosure @escaping () -> T, styleURL: URL, camera: Binding = .constant(.default()), locationManager: MLNLocationManager? = nil, @MapViewContentBuilder _ makeMapContent: () -> [StyleLayerDefinition] = { [] } ) { - self.makeViewController = makeViewController + self.makeViewController = makeViewController + styleSource = .url(styleURL) + _camera = camera + userLayers = makeMapContent() + self.locationManager = locationManager + } + + public init( + styleURL: URL, + camera: Binding = .constant(.default()), + locationManager: MLNLocationManager? = nil, + @MapViewContentBuilder _ makeMapContent: () -> [StyleLayerDefinition] = { [] } + ) { + makeViewController = nil styleSource = .url(styleURL) _camera = camera userLayers = makeMapContent() self.locationManager = locationManager } - - public init( - styleURL: URL, - camera: Binding = .constant(.default()), - locationManager: MLNLocationManager? = nil, - @MapViewContentBuilder _ makeMapContent: () -> [StyleLayerDefinition] = { [] } - ) { - self.makeViewController = nil - styleSource = .url(styleURL) - _camera = camera - userLayers = makeMapContent() - self.locationManager = locationManager - } public func makeCoordinator() -> MapViewCoordinator { MapViewCoordinator( @@ -73,7 +73,7 @@ public struct MapView: UIViewControllerRepresentable { public func makeUIViewController(context: Context) -> T { // Create the map view - let controller = self.makeViewController?() ?? T() + let controller = makeViewController?() ?? T() controller.mapView.delegate = context.coordinator context.coordinator.mapView = controller.mapView @@ -145,7 +145,7 @@ public struct MapView: UIViewControllerRepresentable { } #Preview { - MapView(styleURL: demoTilesURL) + MapView(styleURL: demoTilesURL) .ignoresSafeArea(.all) .previewDisplayName("Vanilla Map")