Skip to content

Commit bfbd5d7

Browse files
author
fonok3
committed
🔖 1.2.0 [ci skip]
1 parent b93f396 commit bfbd5d7

12 files changed

+184
-86
lines changed
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import Foundation
22

33
public struct CameraConfiguration {
4+
// MARK: Nested Types
5+
46
public enum Perspective: Int, CaseIterable, Codable {
57
case threeDimensional
68
case twoDimensional
79
case twoDimensionalNorth
810
}
911

12+
// MARK: Properties
13+
14+
public let zoomLevelOffset: Double
15+
public let perspective: Perspective
16+
1017
// MARK: Lifecycle
1118

1219
public init(zoomLevelOffset: Double = 0, perspective: Perspective = .threeDimensional) {
1320
self.zoomLevelOffset = zoomLevelOffset
1421
self.perspective = perspective
1522
}
16-
17-
// MARK: Public
18-
19-
public let zoomLevelOffset: Double
20-
public let perspective: Perspective
2123
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import Foundation
22

33
public final class StaticCameraConfigurationProvider: CameraConfigurationProvider {
4+
// MARK: Properties
5+
6+
public let cameraConfiguration: CameraConfiguration
7+
48
// MARK: Lifecycle
59

610
public init(cameraConfiguration: CameraConfiguration = CameraConfiguration()) {
711
self.cameraConfiguration = cameraConfiguration
812
}
9-
10-
// MARK: Public
11-
12-
public let cameraConfiguration: CameraConfiguration
1313
}

Sources/GMMapUtility/Layers/Handler/AggregatingMGLStyleLayersHandler.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import Foundation
22
import Mapbox
33

44
open class AggregatingMGLStyleLayersHandler: MGLStyleLayersHandler {
5+
// MARK: Properties
6+
57
public var layerHandlers: [MGLStyleLayersHandler]
68

7-
public init(
8-
mapLayerManager: MapboxMapLayerManager?,
9-
mapTheme: MapTheme,
10-
layerHandlers: [MGLStyleLayersHandler]
11-
) {
12-
self.layerHandlers = layerHandlers
13-
super.init(mapLayerManager: mapLayerManager, mapTheme: mapTheme)
14-
}
9+
// MARK: Lifecycle
1510

1611
override open func setup() {
1712
layerHandlers.forEach { $0.setup() }
@@ -25,6 +20,17 @@ open class AggregatingMGLStyleLayersHandler: MGLStyleLayersHandler {
2520
layerHandlers.forEach { $0.stopLayerUpdates() }
2621
}
2722

23+
public init(
24+
mapLayerManager: MapboxMapLayerManager?,
25+
mapTheme: MapTheme,
26+
layerHandlers: [MGLStyleLayersHandler]
27+
) {
28+
self.layerHandlers = layerHandlers
29+
super.init(mapLayerManager: mapLayerManager, mapTheme: mapTheme)
30+
}
31+
32+
// MARK: Overridden Functions
33+
2834
override public func updateVisibility(_ visible: Bool) {
2935
layerHandlers.forEach { $0.updateVisibility(visible) }
3036
}

Sources/GMMapUtility/Layers/Handler/MapLayerHandler.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
/// Handles the updates and styling of objects shown on a map which belong together.
44
///
5-
/// - note: A `MapLayerHandler` may be self updating to model changes or receive udpates from outside.
5+
/// - note: A `MapLayerHandler` may be self updating to model changes or receive udpates from outside.
66
/// Often these two purposes are split up.
77
public protocol MapLayerHandler {
88
var mapTheme: MapTheme { get }
@@ -18,23 +18,28 @@ public protocol MapLayerHandler {
1818

1919
/// Handles Layer visibility.
2020
///
21-
/// - warning: This controls the visibility from outside, but it is not guranteed that the layer is displayed if `isVisible` is set tu `true`.
21+
/// - warning: This controls the visibility from outside, but it is not guaranteed that the layer is displayed if `isVisible` is set tu `true`.
2222
/// The `MapLayerHandler` may have inner logic whether the layer should be shown.
2323
func updateVisibility(_ visible: Bool)
2424

2525
/// This method should be called if the camera tilt of the `MapView` changes in order to update the layer.
2626
func updateTilt(tilt: Float)
2727

28+
/// This method is called when a feature on the map is tapped.
2829
func didTapFeature(identifier: Any?, attributes: [String: Any])
2930
}
3031

3132
extension MapLayerHandler {
33+
// MARK: Lifecycle
34+
3235
public func setup() {}
3336

3437
public func startLayerUpdates() {}
3538

3639
public func stopLayerUpdates() {}
3740

41+
// MARK: Functions
42+
3843
public func updateVisibility(_: Bool) {}
3944

4045
public func updateTilt(tilt _: Float) {}

Sources/GMMapUtility/MapLibre/Extensions/MGLPolylineFeature+Geodesic.swift

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import Foundation
22
import Mapbox
33

44
extension MGLPolylineFeature {
5+
// MARK: Static Properties
6+
7+
private static let earthRadiusMeter = 6_371_008.8
8+
// swiftlint:disable:next no_magic_numbers
9+
private static let metersNorthToLatitude = 180.0 / Double.pi / earthRadiusMeter
10+
11+
// MARK: Static Functions
12+
513
public static func geodesicPolyline(
614
fromCoordinate src: CLLocationCoordinate2D,
715
toCoordinate dst: CLLocationCoordinate2D
@@ -11,9 +19,6 @@ extension MGLPolylineFeature {
1119
return MGLPolylineFeature(coordinates: coordinates, count: UInt(coordinates.count))
1220
}
1321

14-
private static let earthRadiusMeter = 6_371_008.8
15-
// swiftlint:disable:next no_magic_numbers
16-
private static let metersNorthToLatitude = 180.0 / Double.pi / earthRadiusMeter
1722
// swiftlint:disable:next no_magic_numbers
1823
private static func deg2rad(_ number: Double) -> Double { number * .pi / 180 }
1924

@@ -23,20 +28,20 @@ extension MGLPolylineFeature {
2328

2429
private static func shiftByCartesian(latitude: Double, longitude: Double, metersNorth: Double, metersEast: Double)
2530
-> CLLocationCoordinate2D {
26-
CLLocationCoordinate2D(
27-
latitude: latitude + metersNorth * metersNorthToLatitude,
28-
longitude: longitude + metersEast * metersEastToLongitude(latitude: latitude)
29-
)
31+
CLLocationCoordinate2D(
32+
latitude: latitude + metersNorth * metersNorthToLatitude,
33+
longitude: longitude + metersEast * metersEastToLongitude(latitude: latitude)
34+
)
3035
}
3136

3237
private static func shiftByCartesian(src: CLLocationCoordinate2D, metersNorth: Double, metersEast: Double)
3338
-> CLLocationCoordinate2D {
34-
shiftByCartesian(
35-
latitude: src.latitude,
36-
longitude: src.longitude,
37-
metersNorth: metersNorth,
38-
metersEast: metersEast
39-
)
39+
shiftByCartesian(
40+
latitude: src.latitude,
41+
longitude: src.longitude,
42+
metersNorth: metersNorth,
43+
metersEast: metersEast
44+
)
4045
}
4146

4247
private static func distanceMetersNorth(src: CLLocationCoordinate2D, dst: CLLocationCoordinate2D) -> Double {
@@ -59,7 +64,7 @@ extension MGLPolylineFeature {
5964
}
6065

6166
let northMid = 0.5 * northEnd + eastEnd * normalisation // swiftlint:disable:this no_magic_numbers
62-
let eastMid = 0.5 * eastEnd - northEnd * normalisation // swiftlint:disable:this no_magic_numbers
67+
let eastMid = 0.5 * eastEnd - northEnd * normalisation // swiftlint:disable:this no_magic_numbers
6368

6469
var positions = [CLLocationCoordinate2D]()
6570

Sources/GMMapUtility/MapLibre/Layers/MGLMapViewLifeCycleHandler.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ import Mapbox
33
import UIKit
44

55
public final class MGLMapViewLifeCycleHandler: NSObject {
6+
// MARK: Properties
7+
8+
public weak var mapView: MGLMapView?
9+
610
private var mapThemeRepository: MapThemeRepository
711
private let mapStyleUrlProvider: MGLMapStyleUrlProvider
812
private let mapStyleLocalizer: MGLMapStyleLocalizer
913
private let mapLayerHandlerBuilder: MapLayerHandlerBuilder
1014

11-
public weak var mapView: MGLMapView?
12-
1315
private var currentLayersController: MGLStyleLayersHandler?
16+
private lazy var mapTapGestureRecognizer: UITapGestureRecognizer = {
17+
let recognizer = UITapGestureRecognizer(target: self, action: #selector(didTapMapView(sender:)))
18+
recognizer.delegate = self
19+
return recognizer
20+
}()
21+
22+
// MARK: Computed Properties
23+
1424
private var layerUpdatesPaused = true {
1525
didSet {
1626
if layerUpdatesPaused {
@@ -21,11 +31,7 @@ public final class MGLMapViewLifeCycleHandler: NSObject {
2131
}
2232
}
2333

24-
private lazy var mapTapGestureRecognizer: UITapGestureRecognizer = {
25-
let recognizer = UITapGestureRecognizer(target: self, action: #selector(didTapMapView(sender:)))
26-
recognizer.delegate = self
27-
return recognizer
28-
}()
34+
// MARK: Lifecycle
2935

3036
public init(
3137
mapThemeRepository: MapThemeRepository,

Sources/GMMapUtility/MapLibre/Layers/MGLStyleLayersHandler.swift

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,78 @@ import Foundation
22
import Mapbox
33

44
open class MGLStyleLayersHandler: MapLayerHandler {
5+
// MARK: Properties
6+
57
public private(set) var mapTheme: MapTheme
68

79
public private(set) var mapLayerManager: MapboxMapLayerManager?
810

11+
// MARK: Computed Properties
12+
913
open var interactionLayerIdentifiers: Set<String> { Set<String>([]) }
1014

15+
private var isVisible = true {
16+
didSet {
17+
guard isVisible != oldValue else {
18+
return
19+
}
20+
refreshLayerVisibility(isVisible: isVisible)
21+
}
22+
}
23+
24+
private var tilt: Float = 0 {
25+
didSet {
26+
guard tilt != oldValue else {
27+
return
28+
}
29+
updateTilt(tilt: tilt)
30+
}
31+
}
32+
33+
// MARK: Lifecycle
34+
35+
open func setup() {}
36+
37+
open func startLayerUpdates() {
38+
updateTilt(tilt: tilt)
39+
updateVisibility(isVisible: isVisible)
40+
}
41+
42+
open func stopLayerUpdates() {}
43+
1144
public init(mapLayerManager: MapboxMapLayerManager?, mapTheme: MapTheme) {
1245
self.mapLayerManager = mapLayerManager
1346
self.mapTheme = mapTheme
1447
}
1548

49+
// MARK: Functions
50+
51+
/// This method is called when layer should be updated due to visibility change.
52+
///
53+
/// This method should be overwritten by subclasses.
54+
open func refreshLayerVisibility(isVisible _: Bool) {}
55+
56+
/// This method is called when layer should be updated due to camera tilt change.
57+
///
58+
/// This method should be overwritten by subclasses.
59+
open func refreshLayerTilt(tilt _: Float) {}
60+
61+
open func didTapFeature(identifier _: Any?, attributes _: [String: Any]) {}
62+
63+
/// This method should be called from outside to update the visibility of the layer.
64+
///
65+
/// If the handler is currently inactive the value will be stored and applied when the handler is started.
66+
public func updateVisibility(isVisible: Bool) {
67+
self.isVisible = isVisible
68+
}
69+
70+
/// This method should be called from outside to update the camera tilt of the layer.
71+
///
72+
/// If the handler is currently inactive the value will be stored and applied when the handler is started.
73+
public func updateTilt(tilt: Float) {
74+
self.tilt = tilt
75+
}
76+
1677
// MARK: - User Interaction
1778

1879
func didTapLayer(at location: CGPoint, in mapView: MGLMapView) {
@@ -22,16 +83,4 @@ open class MGLStyleLayersHandler: MapLayerHandler {
2283
)
2384
features.first.map { didTapFeature(identifier: $0.identifier, attributes: $0.attributes) }
2485
}
25-
26-
open func setup() {}
27-
28-
open func startLayerUpdates() {}
29-
30-
open func stopLayerUpdates() {}
31-
32-
open func updateVisibility(_: Bool) {}
33-
34-
open func updateTilt(tilt _: Float) {}
35-
36-
open func didTapFeature(identifier _: Any?, attributes _: [String: Any]) {}
3786
}

0 commit comments

Comments
 (0)