mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #338 from meshtastic/2.1.3_Working_Changes
Bug fix for weather
This commit is contained in:
commit
96da2f32f1
3 changed files with 56 additions and 24 deletions
|
|
@ -21,7 +21,8 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
let mapViewType: MKMapType
|
||||
let userTrackingMode: MKUserTrackingMode
|
||||
let centeringMode: CenteringMode
|
||||
let showBreadcrumbLines: Bool
|
||||
let showRouteLines: Bool
|
||||
let showNodeHistory: Bool
|
||||
let centerOnPositionsOnly: Bool
|
||||
@AppStorage("meshMapRecentering") private var recenter: Bool = false
|
||||
|
||||
|
|
@ -44,26 +45,28 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
let region = MKCoordinateRegion(center: center, span: span)
|
||||
mapView.setRegion(region, animated: true)
|
||||
// Set user (phone gps) tracking options
|
||||
let latest = positions.filter { $0.latest == true }
|
||||
mapView.setUserTrackingMode(userTrackingMode, animated: true)
|
||||
if userTrackingMode != MKUserTrackingMode.none {
|
||||
mapView.showsUserLocation = true
|
||||
} else {
|
||||
if userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.showsUserLocation = false
|
||||
}
|
||||
switch centeringMode {
|
||||
case .allAnnotations:
|
||||
mapView.addAnnotations(positions)
|
||||
if userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.fitAllAnnotations()
|
||||
}
|
||||
case .allPositions:
|
||||
if userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.fit(annotations: positions, andShow: true)
|
||||
} else {
|
||||
mapView.addAnnotations(positions)
|
||||
switch centeringMode {
|
||||
case .allAnnotations:
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
if userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.fitAllAnnotations()
|
||||
}
|
||||
case .allPositions:
|
||||
if userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
mapView.fit(annotations: positions, andShow: false)
|
||||
} else {
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
mapView.showsUserLocation = true
|
||||
}
|
||||
|
||||
// Other MKMapView Settings
|
||||
mapView.preferredConfiguration.elevationStyle = .realistic// .flat
|
||||
mapView.isPitchEnabled = true
|
||||
|
|
@ -121,7 +124,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
self.presentCustomMapOverlayHash = self.customMapOverlay
|
||||
self.loadedLastUpdatedLocalMapFile = self.lastUpdatedLocalMapFile
|
||||
|
||||
if showBreadcrumbLines {
|
||||
if showRouteLines {
|
||||
let nodePositions = positions.filter { $0.time! >= Calendar.current.startOfDay(for: Date()) }
|
||||
let lineCoords = nodePositions.map ({
|
||||
(position) -> CLLocationCoordinate2D in
|
||||
|
|
@ -146,20 +149,20 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
mapView.showsUserLocation = false
|
||||
switch centeringMode {
|
||||
case .allAnnotations:
|
||||
mapView.addAnnotations(positions)
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
if recenter && userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.fitAllAnnotations()
|
||||
}
|
||||
case .allPositions:
|
||||
if recenter && userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.fit(annotations: positions, andShow: true)
|
||||
mapView.fit(annotations: showNodeHistory ? positions : latest, andShow: true)
|
||||
} else {
|
||||
mapView.addAnnotations(positions)
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Centering Done by tracking mode
|
||||
mapView.addAnnotations(positions)
|
||||
mapView.addAnnotations(latest)
|
||||
mapView.showsUserLocation = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ struct NodeDetail: View {
|
|||
@State private var mapType: MKMapType = .standard
|
||||
@State var waypointCoordinate: CLLocationCoordinate2D?
|
||||
@State var editingWaypoint: Int = 0
|
||||
@State private var loadedWeather: Bool = false
|
||||
@State private var showingDetailsPopover = false
|
||||
@State private var showingForecast = false
|
||||
@State private var showingShutdownConfirm: Bool = false
|
||||
|
|
@ -71,7 +72,8 @@ struct NodeDetail: View {
|
|||
mapViewType: mapType,
|
||||
userTrackingMode: MKUserTrackingMode.none,
|
||||
centeringMode: .allPositions,
|
||||
showBreadcrumbLines: false,
|
||||
showRouteLines: false,
|
||||
showNodeHistory: true,
|
||||
centerOnPositionsOnly: true,
|
||||
customMapOverlay: self.customMapOverlay,
|
||||
overlays: self.overlays
|
||||
|
|
@ -486,6 +488,32 @@ struct NodeDetail: View {
|
|||
mapType = .hybridFlyover
|
||||
}
|
||||
}
|
||||
.task(id: node.num) {
|
||||
if !loadedWeather {
|
||||
do {
|
||||
|
||||
if node.positions?.count ?? 0 > 0 {
|
||||
|
||||
let mostRecent = node.positions?.lastObject as? PositionEntity
|
||||
|
||||
let weather = try await WeatherService.shared.weather(for: mostRecent?.nodeLocation ?? CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude))
|
||||
condition = weather.currentWeather.condition
|
||||
temperature = weather.currentWeather.temperature
|
||||
humidity = Int(weather.currentWeather.humidity * 100)
|
||||
symbolName = weather.currentWeather.symbolName
|
||||
|
||||
let attribution = try await WeatherService.shared.attribution
|
||||
attributionLink = attribution.legalPageURL
|
||||
attributionLogo = colorScheme == .light ? attribution.combinedMarkLightURL : attribution.combinedMarkDarkURL
|
||||
loadedWeather = true
|
||||
}
|
||||
} catch {
|
||||
print("Could not gather weather information...", error.localizedDescription)
|
||||
condition = .clear
|
||||
symbolName = "cloud.fill"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ struct NodeMap: View {
|
|||
mapViewType: mapType,
|
||||
userTrackingMode: userTrackingMode,
|
||||
centeringMode: mapCenteringMode,
|
||||
showBreadcrumbLines: false,
|
||||
showRouteLines: false,
|
||||
showNodeHistory: true,
|
||||
centerOnPositionsOnly: false,
|
||||
customMapOverlay: self.customMapOverlay,
|
||||
overlays: self.overlays
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue