mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
Fix MapLibreStaticMapView referesh (#1481)
This commit is contained in:
@@ -22,7 +22,9 @@ struct MapLibreStaticMapView<PinAnnotation: View>: View {
|
|||||||
private let zoomLevel: Double
|
private let zoomLevel: Double
|
||||||
private let mapTilerStatic: MapTilerStaticMapProtocol
|
private let mapTilerStatic: MapTilerStaticMapProtocol
|
||||||
private let mapTilerAttributionPlacement: MapTilerAttributionPlacement
|
private let mapTilerAttributionPlacement: MapTilerAttributionPlacement
|
||||||
|
private let mapSize: CGSize
|
||||||
private let pinAnnotationView: PinAnnotation
|
private let pinAnnotationView: PinAnnotation
|
||||||
|
|
||||||
@Environment(\.colorScheme) private var colorScheme
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
@State private var fetchAttempt = 0
|
@State private var fetchAttempt = 0
|
||||||
|
|
||||||
@@ -30,11 +32,13 @@ struct MapLibreStaticMapView<PinAnnotation: View>: View {
|
|||||||
zoomLevel: Double,
|
zoomLevel: Double,
|
||||||
attributionPlacement: MapTilerAttributionPlacement,
|
attributionPlacement: MapTilerAttributionPlacement,
|
||||||
mapTilerStatic: MapTilerStaticMapProtocol,
|
mapTilerStatic: MapTilerStaticMapProtocol,
|
||||||
|
mapSize: CGSize,
|
||||||
@ViewBuilder pinAnnotationView: () -> PinAnnotation) {
|
@ViewBuilder pinAnnotationView: () -> PinAnnotation) {
|
||||||
self.coordinates = coordinates
|
self.coordinates = coordinates
|
||||||
self.zoomLevel = zoomLevel
|
self.zoomLevel = zoomLevel
|
||||||
self.mapTilerStatic = mapTilerStatic
|
self.mapTilerStatic = mapTilerStatic
|
||||||
mapTilerAttributionPlacement = attributionPlacement
|
mapTilerAttributionPlacement = attributionPlacement
|
||||||
|
self.mapSize = mapSize
|
||||||
self.pinAnnotationView = pinAnnotationView()
|
self.pinAnnotationView = pinAnnotationView()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +47,7 @@ struct MapLibreStaticMapView<PinAnnotation: View>: View {
|
|||||||
if let url = mapTilerStatic.staticMapURL(for: colorScheme.mapStyle,
|
if let url = mapTilerStatic.staticMapURL(for: colorScheme.mapStyle,
|
||||||
coordinates: coordinates,
|
coordinates: coordinates,
|
||||||
zoomLevel: zoomLevel,
|
zoomLevel: zoomLevel,
|
||||||
size: geometry.size,
|
size: mapSize, // temporary using a fixed size since the refresh doesn't work properly on the UITableView based timeline
|
||||||
attribution: mapTilerAttributionPlacement) {
|
attribution: mapTilerAttributionPlacement) {
|
||||||
AsyncImage(url: url) { phase in
|
AsyncImage(url: url) { phase in
|
||||||
switch phase {
|
switch phase {
|
||||||
@@ -109,7 +113,7 @@ struct MapLibreStaticMapView_Previews: PreviewProvider {
|
|||||||
MapLibreStaticMapView(coordinates: CLLocationCoordinate2D(),
|
MapLibreStaticMapView(coordinates: CLLocationCoordinate2D(),
|
||||||
zoomLevel: 15,
|
zoomLevel: 15,
|
||||||
attributionPlacement: .bottomLeft,
|
attributionPlacement: .bottomLeft,
|
||||||
mapTilerStatic: MapTilerStaticMapMock()) {
|
mapTilerStatic: MapTilerStaticMapMock(), mapSize: .init(width: 300, height: 200)) {
|
||||||
Image(systemName: "mappin.circle.fill")
|
Image(systemName: "mappin.circle.fill")
|
||||||
.padding(.bottom, 35)
|
.padding(.bottom, 35)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ struct LocationRoomTimelineView: View {
|
|||||||
descriptionView
|
descriptionView
|
||||||
.frame(maxWidth: mapAspectRatio * mapMaxHeight, alignment: .leading)
|
.frame(maxWidth: mapAspectRatio * mapMaxHeight, alignment: .leading)
|
||||||
|
|
||||||
MapLibreStaticMapView(geoURI: geoURI) {
|
MapLibreStaticMapView(geoURI: geoURI, mapSize: .init(width: mapAspectRatio * mapMaxHeight, height: mapMaxHeight)) {
|
||||||
LocationMarkerView()
|
LocationMarkerView()
|
||||||
}
|
}
|
||||||
.frame(maxHeight: mapMaxHeight)
|
.frame(maxHeight: mapMaxHeight)
|
||||||
@@ -56,12 +56,13 @@ struct LocationRoomTimelineView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private extension MapLibreStaticMapView {
|
private extension MapLibreStaticMapView {
|
||||||
init(geoURI: GeoURI, @ViewBuilder pinAnnotationView: () -> PinAnnotation) {
|
init(geoURI: GeoURI, mapSize: CGSize, @ViewBuilder pinAnnotationView: () -> PinAnnotation) {
|
||||||
self.init(coordinates: .init(latitude: geoURI.latitude, longitude: geoURI.longitude),
|
self.init(coordinates: .init(latitude: geoURI.latitude, longitude: geoURI.longitude),
|
||||||
zoomLevel: 15,
|
zoomLevel: 15,
|
||||||
attributionPlacement: .bottomLeft,
|
attributionPlacement: .bottomLeft,
|
||||||
mapTilerStatic: MapTilerStaticMap(baseURL: ServiceLocator.shared.settings.mapTilerBaseURL,
|
mapTilerStatic: MapTilerStaticMap(baseURL: ServiceLocator.shared.settings.mapTilerBaseURL,
|
||||||
key: ServiceLocator.shared.settings.mapTilerApiKey),
|
key: ServiceLocator.shared.settings.mapTilerApiKey),
|
||||||
|
mapSize: mapSize,
|
||||||
pinAnnotationView: pinAnnotationView)
|
pinAnnotationView: pinAnnotationView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user