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
@@ -144,7 +144,7 @@ final class AppSettings: @unchecked Sendable {
accountProvisioningHost: String,
bugReportApplicationID: String,
analyticsTermsURL: URL?,
mapTilerConfiguration: MapTilerConfiguration) {
mapTilerConfiguration: MapTilerSettings.Configuration) {
self.accountProviders = accountProviders
self.allowOtherAccountProviders = allowOtherAccountProviders
self.hideBrandChrome = hideBrandChrome
@@ -164,7 +164,7 @@ final class AppSettings: @unchecked Sendable {
self.accountProvisioningHost = accountProvisioningHost
self.bugReportApplicationID = bugReportApplicationID
self.analyticsTermsURL = analyticsTermsURL
self.mapTilerConfiguration = mapTilerConfiguration
mapTilerSettings = RemotePreference(.configuration(mapTilerConfiguration))
}
// MARK: - Application
@@ -399,11 +399,16 @@ final class AppSettings: @unchecked Sendable {
// MARK: - Maps
/// maptiler base url
private(set) var mapTilerConfiguration = MapTilerConfiguration(baseURL: "https://api.maptiler.com/maps",
apiKey: Secrets.mapLibreAPIKey,
lightStyleID: "9bc819c8-e627-474a-a348-ec144fe3d810",
darkStyleID: "dea61faf-292b-4774-9660-58fcef89a7f3")
/// The locally-bundled MapTiler configuration.
static let bundledMapTilerConfiguration = MapTilerSettings.Configuration(baseURL: "https://api.maptiler.com/maps",
apiKey: Secrets.mapLibreAPIKey,
lightStyleID: "9bc819c8-e627-474a-a348-ec144fe3d810",
darkStyleID: "dea61faf-292b-4774-9660-58fcef89a7f3")
/// The resolved map tile settings. Defaults to ``MapTilerSettings.configuration(_:)`` with the
/// bundled configuration and is remotely overridden with ``MapTilerSettings.url(_:)`` when
/// the homeserver advertises a `style.json` URL via the matrix client well-known.
private(set) var mapTilerSettings = RemotePreference<MapTilerSettings>(.configuration(AppSettings.bundledMapTilerConfiguration))
// MARK: - Presence
@@ -1,28 +0,0 @@
//
// Copyright 2025 Element Creations Ltd.
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
/// All of the configuration necessary to use MapTiler maps.
///
/// The style IDs need to be generated with the account that the API key belongs to. For more information read
/// [FORKING.md](https://github.com/element-hq/element-x-ios/blob/develop/docs/FORKING.md#setup-the-location-sharing)
struct MapTilerConfiguration {
let baseURL: URL
/// The API key for fetching map tiles. When not set, location sharing will be disabled and
/// any received locations will be shown in the timeline with a generic blurred map image.
let apiKey: String?
/// A MapLibre style ID for a light-mode map.
let lightStyleID: String
/// A MapLibre style ID for a dark-mode map.
let darkStyleID: String
var isEnabled: Bool {
apiKey != nil
}
}
@@ -0,0 +1,40 @@
//
// Copyright 2025 Element Creations Ltd.
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
/// The map tile settings used to build interactive and static map URLs.
///
/// Either resolves to a locally-bundled MapTiler configuration, or to a remote
/// `style.json` URL
enum MapTilerSettings: Equatable {
/// All of the configuration necessary to use MapTiler maps.
///
/// The style IDs need to be generated with the account that the API key belongs to. For more information read
/// [FORKING.md](https://github.com/element-hq/element-x-ios/blob/develop/docs/FORKING.md#setup-the-location-sharing)
struct Configuration: Equatable {
let baseURL: URL
/// The API key for fetching map tiles. When not set, location sharing will be disabled and
/// any received locations will be shown in the timeline with a generic blurred map image.
let apiKey: String?
/// A MapLibre style ID for a light-mode map.
let lightStyleID: String
/// A MapLibre style ID for a dark-mode map.
let darkStyleID: String
}
case configuration(Configuration)
case url(URL)
var isEnabled: Bool {
switch self {
case .configuration(let configuration): configuration.apiKey != nil
case .url: true
}
}
}