-
-
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.
- Loading branch information
1 parent
3c084b3
commit 05c7af3
Showing
5 changed files
with
179 additions
and
29 deletions.
There are no files selected for viewing
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,137 @@ | ||
import Foundation | ||
import MapLibre | ||
|
||
public protocol MapControl { | ||
/// Overrides the position of the control. Default values are control-specfiic. | ||
var position: MLNOrnamentPosition? { get set } | ||
/// Overrides the offset of the control. | ||
var margins: CGPoint? { get set } | ||
/// Overrides whether the control is hidden. | ||
var isHidden: Bool { get set } | ||
|
||
@MainActor func configureMapView(_ mapView: MLNMapView) | ||
} | ||
|
||
public extension MapControl { | ||
/// Sets position of the control. | ||
func position(_ position: MLNOrnamentPosition) -> Self { | ||
var result = self | ||
|
||
result.position = position | ||
|
||
return result | ||
} | ||
|
||
/// Sets the position offset of the control. | ||
func margins(_ margins: CGPoint) -> Self { | ||
var result = self | ||
|
||
result.margins = margins | ||
|
||
return result | ||
} | ||
|
||
/// Hides the control. | ||
func hidden(_: Bool) -> Self { | ||
var result = self | ||
|
||
result.isHidden = true | ||
|
||
return result | ||
} | ||
} | ||
|
||
public struct CompassView: MapControl { | ||
public var position: MLNOrnamentPosition? | ||
public var margins: CGPoint? | ||
public var isHidden: Bool = false | ||
|
||
public func configureMapView(_ mapView: MLNMapView) { | ||
if let position { | ||
mapView.compassViewPosition = position | ||
} | ||
|
||
if let margins { | ||
mapView.compassViewMargins = margins | ||
} | ||
|
||
mapView.compassView.isHidden = isHidden | ||
} | ||
|
||
public init() {} | ||
} | ||
|
||
public struct LogoView: MapControl { | ||
public var position: MLNOrnamentPosition? | ||
public var margins: CGPoint? | ||
public var isHidden: Bool = false | ||
public var image: UIImage? | ||
|
||
public init() {} | ||
|
||
public func configureMapView(_ mapView: MLNMapView) { | ||
if let position { | ||
mapView.logoViewPosition = position | ||
} | ||
|
||
if let margins { | ||
mapView.logoViewMargins = margins | ||
} | ||
|
||
mapView.logoView.isHidden = isHidden | ||
|
||
if let image { | ||
mapView.logoView.image = image | ||
} | ||
} | ||
} | ||
|
||
public extension LogoView { | ||
/// Sets the logo image (defaults to the MapLibre logo). | ||
func image(_ image: UIImage?) -> Self { | ||
var result = self | ||
|
||
result.image = image | ||
|
||
return result | ||
} | ||
} | ||
|
||
@resultBuilder | ||
public enum MapControlsBuilder: DefaultResultBuilder { | ||
public static func buildExpression(_ expression: MapControl) -> [MapControl] { | ||
[expression] | ||
} | ||
|
||
public static func buildExpression(_ expression: [MapControl]) -> [MapControl] { | ||
expression | ||
} | ||
|
||
public static func buildExpression(_: Void) -> [MapControl] { | ||
[] | ||
} | ||
|
||
public static func buildBlock(_ components: [MapControl]...) -> [MapControl] { | ||
components.flatMap { $0 } | ||
} | ||
|
||
public static func buildArray(_ components: [MapControl]) -> [MapControl] { | ||
components | ||
} | ||
|
||
public static func buildArray(_ components: [[MapControl]]) -> [MapControl] { | ||
components.flatMap { $0 } | ||
} | ||
|
||
public static func buildEither(first components: [MapControl]) -> [MapControl] { | ||
components | ||
} | ||
|
||
public static func buildEither(second components: [MapControl]) -> [MapControl] { | ||
components | ||
} | ||
|
||
public static func buildOptional(_ components: [MapControl]?) -> [MapControl] { | ||
components ?? [] | ||
} | ||
} |
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,8 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Ian Wagner on 2024-03-18. | ||
// | ||
|
||
import Foundation |