-
-
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.
Merge pull request #12 from Rallista/feat/map-camera-and-layer-mods
Feat/map camera and layer mods
- Loading branch information
Showing
12 changed files
with
208 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Foundation | ||
|
||
@resultBuilder | ||
public enum MapViewContentBuilder { | ||
|
||
public static func buildBlock(_ layers: [StyleLayerDefinition]...) -> [StyleLayerDefinition] { | ||
return layers.flatMap { $0 } | ||
} | ||
|
||
public static func buildOptional(_ layers: [StyleLayerDefinition]?) -> [StyleLayerDefinition] { | ||
return layers ?? [] | ||
} | ||
|
||
public static func buildExpression(_ layer: StyleLayerDefinition) -> [StyleLayerDefinition] { | ||
return [layer] | ||
} | ||
|
||
public static func buildExpression(_ expression: Void) -> [StyleLayerDefinition] { | ||
return [] | ||
} | ||
|
||
public static func buildExpression(_ styleCollection: StyleLayerCollection) -> [StyleLayerDefinition] { | ||
return styleCollection.layers | ||
} | ||
|
||
|
||
public static func buildEither(first layer: [StyleLayerDefinition]) -> [StyleLayerDefinition] { | ||
return layer | ||
} | ||
|
||
public static func buildEither(second layer: [StyleLayerDefinition]) -> [StyleLayerDefinition] { | ||
return layer | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Sources/MapLibreSwiftDSL/Style Layers/StyleLayerCollection.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,6 @@ | ||
import Foundation | ||
|
||
public protocol StyleLayerCollection { | ||
|
||
@MapViewContentBuilder var layers: [StyleLayerDefinition] { get } | ||
} |
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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
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 trackingUserLocation | ||
|
||
/// 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 (.trackingUserLocation, .trackingUserLocation): | ||
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 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 `default`() -> 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 trackUserLocation(_ location: CLLocation, | ||
zoom: Double, | ||
pitch: Double = 90.0) -> MapViewCamera { | ||
|
||
return MapViewCamera(state: .trackingUserLocation, | ||
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 | ||
} | ||
} |
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,6 @@ | ||
import Foundation | ||
|
||
// TODO: Support MLNStyle as well; having a DSL for that would be nice | ||
public enum MapStyleSource { | ||
case url(URL) | ||
} |