-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added map camera, layer mods, and more
- Loading branch information
Showing
11 changed files
with
195 additions
and
47 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.swiftpm/xcode/xcshareddata/xcschemes/MapLibreSwiftDSL.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.swiftpm/xcode/xcshareddata/xcschemes/MapLibreSwiftUI-Package.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Sources/MapLibreSwiftUI/Models/MapCamera/CameraState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Jacob Fielding on 12/16/23. | ||
// | ||
|
||
import Foundation | ||
import MapLibre | ||
|
||
/// The CameraState is used to understand the current context of the MapView's camera. | ||
public enum CameraState { | ||
|
||
/// Centered on a coordinate | ||
case centered | ||
|
||
/// The camera is currently following a location provider. | ||
case userLocation | ||
|
||
/// Centered on a bounding box/rectangle. | ||
case rect | ||
|
||
/// Showcasing a GeoJSON/Polygon | ||
case showcase | ||
} | ||
|
||
extension CameraState: Equatable { | ||
|
||
public static func ==(lhs: CameraState, rhs: CameraState) -> Bool { | ||
switch (lhs, rhs) { | ||
|
||
case (.centered, .centered): | ||
return true | ||
case (.userLocation, .userLocation): | ||
return true | ||
case (.rect, .rect): | ||
return true | ||
case (.showcase, .showcase): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Foundation | ||
import CoreLocation | ||
|
||
public struct MapViewCamera { | ||
|
||
public var state: CameraState | ||
public var coordinate: CLLocationCoordinate2D | ||
public var zoom: Double | ||
public var pitch: Double | ||
public var course: CLLocationDirection | ||
|
||
/// A backup camera centered at 0.0, 0.0. This is typically used as a backup, | ||
/// pre-load for an expected camera update (e.g. before a location provider produces | ||
/// it's first location). | ||
/// | ||
/// - Returns: The constructed MapViewCamera. | ||
public static func backup() -> MapViewCamera { | ||
return MapViewCamera(state: .centered, | ||
coordinate: CLLocationCoordinate2D(latitude: 0, longitude: 0), | ||
zoom: 10, | ||
pitch: 90, | ||
course: 0) | ||
} | ||
|
||
/// Center the map on a specific location. | ||
/// | ||
/// - Parameters: | ||
/// - coordinate: The coordinate to center the map on. | ||
/// - zoom: The zoom level. | ||
/// - pitch: The camera pitch. Default is 90 (straight down). | ||
/// - course: The course. Default is 0 (North). | ||
/// - Returns: The constructed MapViewCamera. | ||
public static func center(_ coordinate: CLLocationCoordinate2D, | ||
zoom: Double, | ||
pitch: Double = 90.0, | ||
course: Double = 0) -> MapViewCamera { | ||
|
||
return MapViewCamera(state: .centered, | ||
coordinate: coordinate, | ||
zoom: zoom, | ||
pitch: pitch, | ||
course: course) | ||
} | ||
|
||
public static func userLocation(_ location: CLLocation, | ||
zoom: Double, | ||
pitch: Double = 90.0) -> MapViewCamera { | ||
|
||
return MapViewCamera(state: .userLocation, | ||
coordinate: location.coordinate, | ||
zoom: zoom, | ||
pitch: pitch, | ||
course: location.course) | ||
} | ||
|
||
// TODO: Create init methods for other camera states once supporting materials are understood (e.g. BoundingBox) | ||
} | ||
|
||
extension MapViewCamera: Equatable { | ||
|
||
public static func ==(lhs: MapViewCamera, rhs: MapViewCamera) -> Bool { | ||
return lhs.state == rhs.state | ||
&& lhs.coordinate.latitude == rhs.coordinate.latitude | ||
&& lhs.coordinate.longitude == rhs.coordinate.longitude | ||
&& lhs.zoom == rhs.zoom | ||
&& lhs.pitch == rhs.pitch | ||
&& lhs.course == rhs.course | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Sources/MapLibreSwiftUI/Models/MapStyleSource/MapStyleSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Jacob Fielding on 12/16/23. | ||
// | ||
|
||
import Foundation | ||
|
||
// TODO: Support MLNStyle as well; having a DSL for that would be nice | ||
public enum MapStyleSource { | ||
case url(URL) | ||
} |
22 changes: 22 additions & 0 deletions
22
Sources/MapLibreSwiftUI/ViewModifiers/MapViewContentViewModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Jacob Fielding on 12/16/23. | ||
// | ||
|
||
import SwiftUI | ||
import MapLibreSwiftDSL | ||
|
||
extension MapView { | ||
|
||
public func mapContent(@MapViewContentBuilder _ makeMapContent: () -> [StyleLayerDefinition]) -> MapView { | ||
switch self.styleSource { | ||
|
||
case .url(let styleUrl): | ||
return MapView(styleURL: styleUrl, | ||
camera: self.camera, | ||
makeMapContent) | ||
} | ||
} | ||
} |