mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
remove map tiler url from matrix wellknown
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user