-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwiftExtensions.swift
More file actions
148 lines (127 loc) · 4.29 KB
/
SwiftExtensions.swift
File metadata and controls
148 lines (127 loc) · 4.29 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// SwiftExtensions.swift
// GLMap
//
// Created by Evgen Bodunov on 11/18/16.
// Copyright © 2016 Evgen Bodunov. All rights reserved.
//
import Foundation
import GLMapCore
public extension GLMapManager {
/**
Activates map manager with API key.
It could be obtained at https://user.getyourmap.com
@param apiKey API key
*/
static func activate(apiKey: String, resources: Bundle? = nil, storage: String? = nil) {
#if SWIFT_PACKAGE
let res = resources ?? Bundle.module
#else
let res = resources
#endif
activate(withApiKey: apiKey, resourcesBundle: res, andStoragePath: storage)
}
}
extension GLMapPoint: @retroactive Equatable {
public static func == (lhs: GLMapPoint, rhs: GLMapPoint) -> Bool {
return lhs.x == rhs.x && lhs.y == rhs.y
}
}
extension GLMapGeoPoint: @retroactive Equatable {
public static func == (lhs: GLMapGeoPoint, rhs: GLMapGeoPoint) -> Bool {
return lhs.lat == rhs.lat && lhs.lon == rhs.lon
}
}
extension GLMapBBox: @retroactive Equatable {
public static func == (lhs: GLMapBBox, rhs: GLMapBBox) -> Bool {
return lhs.origin == rhs.origin && lhs.size == rhs.size
}
}
public extension GLMapPointArray {
/**
Creates new GLMapPointArray and adds points to it
@param lat Latitude in degrees
@param lon Longitude in degrees
*/
convenience init(_ points: [GLMapPoint]) {
self.init()
addPoints(points)
}
/**
Adds points to array
@param line Array of map points
*/
func addPoints(_ points: [GLMapPoint]) {
addPoints(points, count: UInt(points.count))
}
}
public extension GLMapMarkerData {
/**
Sets style to the marker. Style indexes returned by `GLMapMarkerStyleCollection`, when new image is added
@param style Index of the style.
*/
func setStyle(_ style: UInt32) {
GLMapMarkerSetStyle(self, style)
}
/**
Sets text to the marker.
@param text Text displayed by marker
@param offset Offset of the text center relative to the marker center
@param style Text style
*/
func setText(_ text: String, alignment: GLMapTextAlignment = .undefined, offset: CGPoint = .zero, style: GLMapVectorStyle) {
GLMapMarkerSetText(self, alignment, text, offset, style)
}
}
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))
}
}