-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathGPXTileServer.swift
168 lines (151 loc) · 5.16 KB
/
GPXTileServer.swift
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// GPXTileServer.swift
// OpenGpxTracker
//
// Created by merlos on 25/01/15.
//
// Shared file: this file is also included in the OpenGpxTracker-Watch Extension target.
import Foundation
///
/// Configuration for supported tile servers.
///
/// Maps displayed in the application are sets of small square images caled tiles. There are different servers that
/// provide these tiles.
///
/// A tile server is defined by an internal id (for instance .openStreetMap), a name string for displaying
/// on the interface and a URL template.
///
enum GPXTileServer: Int {
/// Apple tile server
case apple
/// Apple satellite tile server
case appleSatellite
/// OpenStreetMap tile server
case openStreetMap
// case AnotherMap
/// CartoDB tile server
case cartoDB
/// CartoDB tile server (2x tiles)
case cartoDBRetina
/// OpenTopoMap tile server
case openTopoMap
/// OpenSeaMap tile server
case openSeaMap
/// String that describes the selected tile server.
var name: String {
switch self {
case .apple: return "Apple Mapkit (no offline cache)"
case .appleSatellite: return "Apple Satellite (no offline cache)"
case .openStreetMap: return "OpenStreetMap"
case .cartoDB: return "Carto DB"
case .cartoDBRetina: return "Carto DB (Retina resolution)"
case .openTopoMap: return "OpenTopoMap"
case .openSeaMap: return "OpenSeaMap"
}
}
/// URL template of current tile server (it is of the form http://{s}.map.tile.server/{z}/{x}/{y}.png
var templateUrl: String {
switch self {
case .apple: return ""
case .appleSatellite: return ""
case .openStreetMap: return "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
case .cartoDB: return "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png"
case .cartoDBRetina: return "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}@2x.png"
case .openTopoMap: return "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png"
case .openSeaMap: return "https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
}
}
/// In the `templateUrl` the {s} means subdomain, typically the subdomains available are a,b and c
/// Check the subdomains available for your server.
///
/// Set an empty array (`[]`) in case you don't use `{s}` in your `templateUrl`.
///
/// Subdomains is useful to distribute the tile request download among the diferent servers
/// and displaying them faster as result.
var subdomains: [String] {
switch self {
case .apple: return []
case .appleSatellite: return []
case .openStreetMap: return ["a", "b", "c"]
case .cartoDB, .cartoDBRetina: return ["a", "b", "c"]
case .openTopoMap: return ["a", "b", "c"]
case .openSeaMap: return []
// case .AnotherMap: return ["a","b"]
}
}
/// Maximum zoom level the tile server supports
/// Tile servers provide files till a certain level of zoom that ranges from 0 to maximumZ.
/// If map zooms more than the limit level, tiles won't be requested.
///
/// Typically the value is around 19,20 or 21.
///
/// Use negative to avoid setting a limit.
///
/// - see https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_servers
///
var maximumZ: Int {
switch self {
case .apple:
return -1
case .appleSatellite:
return -1
case .openStreetMap:
return 19
case .cartoDB, .cartoDBRetina:
return 21
case .openTopoMap:
return 17
// case .AnotherMap: return 10
case .openSeaMap:
return 16
}
}
///
/// Minimum zoom supported by the tile server
///
/// This limits the tiles requested based on current zoom level.
/// No tiles will be requested for zooms levels lower that this.
///
/// Needs to be 0 or larger.
///
var minimumZ: Int {
switch self {
case .apple:
return 0
case .appleSatellite:
return 0
case .openStreetMap:
return 0
case .cartoDB, .cartoDBRetina:
return 0
case .openTopoMap:
return 0
case .openSeaMap:
return 0
// case .AnotherMap: return 0
}
}
/// Does the tile overlay replace the map?
/// Generally all the tiles provided replace the AppleMaps. However there are some
var canReplaceMapContent: Bool {
switch self {
case .openSeaMap: return false
default: return true
}
}
/// tile size of the third-party tile.
///
/// 1x tiles are 256x256
/// 2x/retina tiles are 512x512
var tileSize: Int {
switch self {
case .cartoDBRetina: return 512
default: return 256
}
}
var needForceDarkMode: Bool {
return self == .appleSatellite
}
/// Returns the number of tile servers currently defined
static var count: Int { return GPXTileServer.openSeaMap.rawValue + 1}
}