Repository navigation
Expand file tree
/
Copy pathCoreSwiftExtensions.swift
More file actions
133 lines (116 loc) · 4.36 KB
/
Copy pathCoreSwiftExtensions.swift
File metadata and controls
133 lines (116 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// CoreSwiftExtensions.swift
// GLMap
//
// Created by Evgen Bodunov on 11/18/16.
// Copyright © 2016 Evgen Bodunov. All rights reserved.
//
import CoreLocation
import Foundation
import GLMapCore
public extension GLMapManager {
/**
Activates map manager with API key.
It can be obtained at https://user.globus.software/apps/
@param apiKey API key
@param resources Bundle containing SDK resources. If `nil`, uses the SwiftPM resource bundle
when built as a Swift package, or the main bundle otherwise.
@param storage Writable map storage directory. If `nil`, uses the application's Documents directory.
@return `false` if required resources are missing from the bundle or the storage path is not writable.
This result does not validate the API key.
*/
@discardableResult
static func activate(apiKey: String, resources: Bundle? = nil, storage: String? = nil) -> Bool {
#if SWIFT_PACKAGE
let res = resources ?? Bundle.module
#else
let res = resources
#endif
return activate(withApiKey: apiKey, resourcesBundle: res, andStoragePath: storage)
}
}
extension GLMapPoint: @retroactive Equatable {
/// Returns whether two projected points have identical coordinates.
public static func == (lhs: GLMapPoint, rhs: GLMapPoint) -> Bool {
return lhs.x == rhs.x && lhs.y == rhs.y
}
}
extension GLMapGeoPoint: @retroactive Equatable {
/// Returns whether two geographic points have identical coordinates.
public static func == (lhs: GLMapGeoPoint, rhs: GLMapGeoPoint) -> Bool {
return lhs.lat == rhs.lat && lhs.lon == rhs.lon
}
}
public extension GLMapGeoPoint {
/// Convenience initializer bridging from CoreLocation.
init(location: CLLocation) {
self.init(lat: location.coordinate.latitude, lon: location.coordinate.longitude)
}
}
extension GLMapBBox: @retroactive Equatable {
/// Returns whether two bounding boxes have identical origins and sizes.
public static func == (lhs: GLMapBBox, rhs: GLMapBBox) -> Bool {
return lhs.origin == rhs.origin && lhs.size == rhs.size
}
}
public extension GeometryBuilder {
/**
Adds a line to the geometry being built.
@param points Ordered array of points in internal map coordinates.
*/
func addLine(_ points: [GLMapPoint]) {
addLine(points, count: UInt(points.count))
}
}
public extension GLMapManager {
/// Notification is sent when GLMapInfo.state property is changed
static let mapListChanged = Notification.Name(kGLMapListChanged)
}
public extension GLMapInfo {
/// Notification is sent when GLMapInfo.state property is changed
static let stateChanged = Notification.Name(kGLMapInfoStateChanged)
}
public extension GLMapDownloadTask {
/// Notification is sent when GLMapInfo.downloadProgress or GLMapInfo.processedProgress property is changed
static let downloadProgress = Notification.Name(kGLMapDownloadTaskProgress)
/// Notification is sent when download task is started
static let downloadTaskStarted = Notification.Name(kGLMapDownloadTaskStarted)
/// Notification is sent when download task is finished
static let downloadFinished = Notification.Name(kGLMapDownloadTaskFinished)
}
public extension GLMapInfoState {
/// Compares two offline map states
static func > (lhs: GLMapInfoState, rhs: GLMapInfoState) -> Bool {
return lhs.rawValue > rhs.rawValue
}
/// Compares two offline map states
static func < (lhs: GLMapInfoState, rhs: GLMapInfoState) -> Bool {
return lhs.rawValue < rhs.rawValue
}
}
public extension GLMapBBox {
/// Returns true if bounding box is empty
var isEmpty: Bool {
return size.x < 0 || size.y < 0
}
/// Adds point into bounding box object
mutating func add(point: GLMapPoint) {
self = adding(point)
}
/// Adds one bounding box into another
mutating func add(bbox: GLMapBBox) {
if !bbox.isEmpty {
self = adding(bbox.origin)
self = adding(GLMapPoint(x: bbox.origin.x + bbox.size.x, y: bbox.origin.y + bbox.size.y))
}
}
}
public extension GLMapTrackData {
/**
Initalizes `GLMapTrackData` with array of points
@param points Track point array
*/
convenience init?(points: [GLTrackPoint]) {
self.init(points: points, count: UInt(points.count))
}
}