mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Render location events in the timeline (#1136)
* Start location integration in the timeline * Add warning * Add LocationRoomTimelineView * Add GeoURI * Refine LocationRoomTimelineView * Refine LocationRoomTimelineView * Add LocationRoomTimelineView previews * Cleanup code * Mock reply * Add FF for location events * Update project file * Fix MapLibreStaticMapView placeholder * Add MapTilerAttribution * Add LocationPinView * Fix layout * Start reply rendering * Refactor ReplyView.Icon * Add localisations * Fix reactions * Amend GeoURI regex * Add log * Fix tests * Attribution placement refactor * Cleanup * Replace NSRegularExpression with a regex * Cleanup * Update unit tests * isMediaType -> shouldFillBubble
This commit is contained in:
@@ -38,3 +38,11 @@ enum MapLibreError: Error {
|
||||
case failedLocatingUser
|
||||
case invalidLocationAuthorization
|
||||
}
|
||||
|
||||
enum MapTilerAttributionPlacement: String {
|
||||
case bottomRight = "bottomright"
|
||||
case bottomLeft = "bottomleft"
|
||||
case topLeft = "topleft"
|
||||
case topRight = "topright"
|
||||
case hidden = "false"
|
||||
}
|
||||
|
||||
@@ -21,27 +21,34 @@ struct MapLibreStaticMapView<PinAnnotation: View>: View {
|
||||
private let coordinates: CLLocationCoordinate2D
|
||||
private let zoomLevel: Double
|
||||
private let mapTilerStatic: MapTilerStaticMapProtocol
|
||||
private let mapTilerAttributionPlacement: MapTilerAttributionPlacement
|
||||
private let pinAnnotationView: PinAnnotation
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@ScaledMetric private var height: CGFloat
|
||||
@ScaledMetric private var width: CGFloat
|
||||
@State private var attempt = 0
|
||||
private let imageSize: CGSize
|
||||
@State private var fetchAttempt = 0
|
||||
|
||||
init(coordinates: CLLocationCoordinate2D, zoomLevel: Double, mapTilerStatic: MapTilerStaticMapProtocol, height: CGFloat, width: CGFloat, @ViewBuilder pinAnnotationView: () -> PinAnnotation) {
|
||||
init(coordinates: CLLocationCoordinate2D,
|
||||
zoomLevel: Double,
|
||||
imageSize: CGSize,
|
||||
attributionPlacement: MapTilerAttributionPlacement,
|
||||
mapTilerStatic: MapTilerStaticMapProtocol,
|
||||
@ViewBuilder pinAnnotationView: () -> PinAnnotation) {
|
||||
self.coordinates = coordinates
|
||||
self.zoomLevel = zoomLevel
|
||||
self.mapTilerStatic = mapTilerStatic
|
||||
_height = .init(wrappedValue: height)
|
||||
_width = .init(wrappedValue: width)
|
||||
self.imageSize = imageSize
|
||||
mapTilerAttributionPlacement = attributionPlacement
|
||||
self.pinAnnotationView = pinAnnotationView()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if let url = mapTilerStatic.staticMapURL(for: colorScheme.mapStyle, coordinates: coordinates, zoomLevel: zoomLevel, size: .init(width: width, height: height)) {
|
||||
if let url = mapTilerStatic.staticMapURL(for: colorScheme.mapStyle, coordinates: coordinates, zoomLevel: zoomLevel, size: imageSize, attribution: mapTilerAttributionPlacement) {
|
||||
AsyncImage(url: url) { phase in
|
||||
switch phase {
|
||||
case .empty:
|
||||
Image("mapBlurred")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
case .success(let image):
|
||||
ZStack {
|
||||
image
|
||||
@@ -55,17 +62,16 @@ struct MapLibreStaticMapView<PinAnnotation: View>: View {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
.id(attempt)
|
||||
.frame(width: width, height: height)
|
||||
.id(fetchAttempt)
|
||||
.clipped()
|
||||
} else {
|
||||
Image("mapBlurred")
|
||||
}
|
||||
}
|
||||
|
||||
var errorView: some View {
|
||||
private var errorView: some View {
|
||||
Button {
|
||||
attempt += 1
|
||||
fetchAttempt += 1
|
||||
} label: {
|
||||
ZStack {
|
||||
Image("mapBlurred")
|
||||
@@ -95,8 +101,9 @@ struct MapLibreStaticMapView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MapLibreStaticMapView(coordinates: CLLocationCoordinate2D(),
|
||||
zoomLevel: 15,
|
||||
mapTilerStatic: MapTilerStaticMapMock(),
|
||||
height: 150, width: 300) {
|
||||
imageSize: .init(width: 300, height: 200),
|
||||
attributionPlacement: .bottomLeft,
|
||||
mapTilerStatic: MapTilerStaticMapMock()) {
|
||||
Image(systemName: "mappin.circle.fill")
|
||||
.padding(.bottom, 35)
|
||||
}
|
||||
@@ -104,7 +111,7 @@ struct MapLibreStaticMapView_Previews: PreviewProvider {
|
||||
}
|
||||
|
||||
private struct MapTilerStaticMapMock: MapTilerStaticMapProtocol {
|
||||
func staticMapURL(for style: MapTilerStyle, coordinates: CLLocationCoordinate2D, zoomLevel: Double, size: CGSize) -> URL? {
|
||||
func staticMapURL(for style: MapTilerStyle, coordinates: CLLocationCoordinate2D, zoomLevel: Double, size: CGSize, attribution: MapTilerAttributionPlacement) -> URL? {
|
||||
switch style {
|
||||
case .light:
|
||||
return URL(string: "https://www.maptiler.com/img/cloud/home/map5.webp")
|
||||
|
||||
@@ -27,7 +27,7 @@ struct MapTilerStaticMap: MapTilerStaticMapProtocol {
|
||||
self.key = key
|
||||
}
|
||||
|
||||
func staticMapURL(for style: MapTilerStyle, coordinates: CLLocationCoordinate2D, zoomLevel: Double, size: CGSize) -> URL? {
|
||||
func staticMapURL(for style: MapTilerStyle, coordinates: CLLocationCoordinate2D, zoomLevel: Double, size: CGSize, attribution: MapTilerAttributionPlacement) -> URL? {
|
||||
var path: String
|
||||
switch style {
|
||||
case .light:
|
||||
@@ -38,7 +38,8 @@ struct MapTilerStaticMap: MapTilerStaticMapProtocol {
|
||||
|
||||
path.append(String(format: "/static/%f,%f,%f/%dx%d@2x.png", coordinates.longitude, coordinates.latitude, zoomLevel, Int(size.width), Int(size.height)))
|
||||
|
||||
guard let url = URL(string: path) else { return nil }
|
||||
guard var url = URL(string: path) else { return nil }
|
||||
url.append(queryItems: [.init(name: "attribution", value: attribution.rawValue)])
|
||||
let authorization = MapTilerAuthorization(key: key)
|
||||
return authorization.authorizeURL(url)
|
||||
}
|
||||
|
||||
@@ -17,5 +17,9 @@
|
||||
import CoreLocation
|
||||
|
||||
protocol MapTilerStaticMapProtocol {
|
||||
func staticMapURL(for style: MapTilerStyle, coordinates: CLLocationCoordinate2D, zoomLevel: Double, size: CGSize) -> URL?
|
||||
func staticMapURL(for style: MapTilerStyle,
|
||||
coordinates: CLLocationCoordinate2D,
|
||||
zoomLevel: Double,
|
||||
size: CGSize,
|
||||
attribution: MapTilerAttributionPlacement) -> URL?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user