remove map tiler url from matrix wellknown

This commit is contained in:
Mauro Romito
2026-08-04 13:42:51 +02:00
committed by Mauro
parent 80530f0006
commit 748ec818ac
22 changed files with 120 additions and 280 deletions
+18 -40
View File
@@ -8,17 +8,12 @@
import CoreLocation
extension MapTilerSettings: MapTilerURLBuilderProtocol {
extension MapTilerConfiguration: MapTilerURLBuilderProtocol {
/// For interactive MGLMap components
func interactiveMapURL(for style: MapTilerStyle) -> 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
}
var url = styleURL(for: style)
url?.appendPathComponent("style.json", conformingTo: .json)
return url
}
/// Used in the timeline where a full MGLMapView loading is unwanted
@@ -27,47 +22,30 @@ extension MapTilerSettings: MapTilerURLBuilderProtocol {
zoomLevel: Double,
size: CGSize,
attribution: MapTilerAttributionPlacement) -> 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
}
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
}
}
// MARK: - Private
private extension MapTilerSettings.Configuration {
private extension MapTilerConfiguration {
func styleURL(for style: MapTilerStyle) -> URL? {
guard let apiKey else { return nil }
var url: URL = baseURL
url.appendPathComponent(styleID(for: style), conformingTo: .item)
url.append(queryItems: [URLQueryItem(name: "key", value: apiKey)])
if !apiKey.isEmpty {
url.append(queryItems: [URLQueryItem(name: "key", value: apiKey)])
}
return url
}