mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
8753fe3980
Second step towards loading MapLibre on demand: everything that touches it now lives in one framework, so that framework can later be left unlinked. The interactive map view, its annotation view and the coordinate animator move into MapLibreShim, which reaches the app through MapLibreShimProtocol. The app side keeps its MapLibreMapView call site and becomes a thin wrapper that builds a MapViewConfiguration, passing the app-only pieces (map style URLs, marker views, tint colour) across as closures so the shim needs nothing from the app. LocationAnnotation loses its MapLibre conformance and becomes a plain struct, with the shim mapping it onto its own annotation type. MapLibre's log forwarding moves into the shim as well, since TargetConfiguration can no longer reach it.
61 lines
1.9 KiB
Swift
61 lines
1.9 KiB
Swift
//
|
|
// Copyright 2026 Element Creations Ltd.
|
|
// Copyright 2023-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 CoreLocation
|
|
import MapLibre
|
|
import MapLibreInterface
|
|
import SwiftUI
|
|
|
|
final class MapLibreAnnotation: NSObject, MLNAnnotation, Identifiable {
|
|
let id: String
|
|
// @objc dynamic is required to make animations work
|
|
@objc dynamic var coordinate: CLLocationCoordinate2D
|
|
|
|
// MARK: - Setup
|
|
|
|
init(_ annotation: MapAnnotation) {
|
|
id = annotation.id
|
|
coordinate = annotation.coordinate
|
|
super.init()
|
|
}
|
|
}
|
|
|
|
final class MapLibreAnnotationView: MLNUserLocationAnnotationView {
|
|
private var hostingController: UIHostingController<AnyView>?
|
|
|
|
// MARK: - Setup
|
|
|
|
override init(annotation: MLNAnnotation?, reuseIdentifier: String?) {
|
|
super.init(annotation: annotation, reuseIdentifier:
|
|
reuseIdentifier)
|
|
}
|
|
|
|
convenience init(annotation: MapLibreAnnotation, content: AnyView?) {
|
|
self.init(annotation: annotation, reuseIdentifier: "\(Self.self)")
|
|
let hostingController = UIHostingController(rootView: content ?? AnyView(EmptyView()))
|
|
self.hostingController = hostingController
|
|
let view: UIView = hostingController.view
|
|
view.backgroundColor = .clear
|
|
view.anchorPoint = .init(x: 0.5, y: 1.0)
|
|
addSubview(view)
|
|
view.bounds.size = view.intrinsicContentSize
|
|
}
|
|
|
|
func updateContent(_ content: AnyView?) {
|
|
hostingController?.rootView = content ?? AnyView(EmptyView())
|
|
if let hostedView = hostingController?.view {
|
|
hostedView.bounds.size = hostedView.intrinsicContentSize
|
|
}
|
|
}
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder: NSCoder) {
|
|
fatalError()
|
|
}
|
|
}
|