Set map tiler URL from well known if available (#5633)

This commit is contained in:
Mauro
2026-05-28 15:24:58 +02:00
committed by GitHub
parent 594d041128
commit 7093d966b4
25 changed files with 291 additions and 88 deletions
+45 -19
View File
@@ -8,12 +8,17 @@
import CoreLocation
extension MapTilerConfiguration: MapTilerURLBuilderProtocol {
extension MapTilerSettings: MapTilerURLBuilderProtocol {
/// For interactive MGLMap components
func interactiveMapURL(for style: MapTilerStyle) -> URL? {
var url = styleURL(for: style)
url?.appendPathComponent("style.json", conformingTo: .json)
return url
switch self {
case .configuration(let configuration):
var url = configuration.styleURL(for: style)
url?.appendPathComponent("style.json", conformingTo: .json)
return url
case .url(let url):
return url
}
}
/// Used in the timeline where a full MGLMapView loading is unwanted
@@ -22,21 +27,42 @@ extension MapTilerConfiguration: MapTilerURLBuilderProtocol {
zoomLevel: Double,
size: CGSize,
attribution: MapTilerAttributionPlacement) -> URL? {
var url = styleURL(for: style)
url?.appendPathComponent(String(format: "static/%f,%f,%f/%dx%d@2x.png",
coordinates.longitude,
coordinates.latitude,
zoomLevel,
Int(size.width),
Int(size.height)),
conformingTo: .png)
url?.append(queryItems: [.init(name: "attribution", value: attribution.rawValue)])
return url
let staticComponent = String(format: "static/%f,%f,%f/%dx%d@2x.png",
coordinates.longitude,
coordinates.latitude,
zoomLevel,
Int(size.width),
Int(size.height))
switch self {
case .configuration(let configuration):
var url = configuration.styleURL(for: style)
url?.appendPathComponent(staticComponent, conformingTo: .png)
url?.append(queryItems: [.init(name: "attribution", value: attribution.rawValue)])
return url
case .url(let url):
// The override is a full URL to a `style.json` (with any necessary query items,
// such as an embedded API key). Derive the static URL by replacing the trailing
// `style.json` component while preserving existing query items.
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return nil }
var pathComponents = components.path.split(separator: "/", omittingEmptySubsequences: false).map(String.init)
guard pathComponents.last == "style.json" else { return nil }
pathComponents.removeLast()
pathComponents.append(staticComponent)
components.path = pathComponents.joined(separator: "/")
var queryItems = components.queryItems ?? []
queryItems.append(.init(name: "attribution", value: attribution.rawValue))
components.queryItems = queryItems
return components.url
}
}
// MARK: Private
private func styleURL(for style: MapTilerStyle) -> URL? {
}
// MARK: - Private
private extension MapTilerSettings.Configuration {
func styleURL(for style: MapTilerStyle) -> URL? {
guard let apiKey else { return nil }
var url: URL = baseURL
@@ -45,7 +71,7 @@ extension MapTilerConfiguration: MapTilerURLBuilderProtocol {
return url
}
private func styleID(for style: MapTilerStyle) -> String {
func styleID(for style: MapTilerStyle) -> String {
switch style {
case .light: lightStyleID
case .dark: darkStyleID