mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Switch mesh map to new control, comment out old map view
This commit is contained in:
parent
71aa8f93d8
commit
9157ca5d17
3 changed files with 553 additions and 841 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -72,12 +72,48 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
self.loadedLastUpdatedLocalMapFile = self.lastUpdatedLocalMapFile
|
||||
}
|
||||
}
|
||||
self.moveToMeshRegion(mapView)
|
||||
}
|
||||
|
||||
func makeCoordinator() -> MapCoordinator {
|
||||
return Coordinator(self)
|
||||
}
|
||||
|
||||
func moveToMeshRegion(_ mapView: MKMapView) {
|
||||
//go through the annotations and create a bounding box that encloses them
|
||||
var minLat: CLLocationDegrees = 90.0
|
||||
var maxLat: CLLocationDegrees = -90.0
|
||||
var minLon: CLLocationDegrees = 180.0
|
||||
var maxLon: CLLocationDegrees = -180.0
|
||||
|
||||
for annotation in mapView.annotations {
|
||||
if annotation.isKind(of: MKAnnotation.self) {
|
||||
minLat = min(minLat, annotation.coordinate.latitude)
|
||||
maxLat = max(maxLat, annotation.coordinate.latitude)
|
||||
minLon = min(minLon, annotation.coordinate.longitude)
|
||||
maxLon = max(maxLon, annotation.coordinate.longitude)
|
||||
}
|
||||
}
|
||||
|
||||
//check if the mesh region looks sensible before we move to it. Otherwise we won't move the map (leave it at the current location)
|
||||
if maxLat < minLat || (maxLat-minLat) > 5 || maxLon < minLon || (maxLon-minLon) > 5 {
|
||||
return
|
||||
} else if minLat == maxLat && minLon == maxLon {
|
||||
//then we are focussed on a single point (probably because there is only one node with a position)
|
||||
//widen that out a little (don't zoom way in to that point)
|
||||
|
||||
//0.001 degrees latitude is about 100m
|
||||
//the mapView.regionThatFits call below will expand this out to a rectangle
|
||||
minLat = minLat - 0.001
|
||||
maxLat = maxLat + 0.001
|
||||
}
|
||||
|
||||
let centerCoord = CLLocationCoordinate2D(latitude: (minLat+maxLat)/2, longitude: (minLon+maxLon)/2)
|
||||
let span = MKCoordinateSpan(latitudeDelta: (maxLat-minLat)*1.5, longitudeDelta: (maxLon-minLon)*1.5)
|
||||
let region = mapView.regionThatFits(MKCoordinateRegion(center: centerCoord, span: span))
|
||||
mapView.setRegion(region, animated: true)
|
||||
}
|
||||
|
||||
final class MapCoordinator: NSObject, MKMapViewDelegate, UIGestureRecognizerDelegate {
|
||||
|
||||
var parent: MapViewSwiftUI
|
||||
|
|
@ -240,13 +276,13 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
public class CustomMapOverlaySource: MKTileOverlay {
|
||||
|
||||
// requires folder: tiles/{mapName}/z/y/y,{tileType}
|
||||
private var parent: MapView
|
||||
private var parent: MapViewSwiftUI
|
||||
private let mapName: String
|
||||
private let tileType: String
|
||||
private let defaultTile: DefaultTile?
|
||||
|
||||
public init(
|
||||
parent: MapView,
|
||||
parent: MapViewSwiftUI,
|
||||
mapName: String,
|
||||
tileType: String,
|
||||
defaultTile: DefaultTile?
|
||||
|
|
|
|||
|
|
@ -15,14 +15,13 @@ struct NodeMap: View {
|
|||
@Environment(\.managedObjectContext) var context
|
||||
@EnvironmentObject var bleManager: BLEManager
|
||||
@EnvironmentObject var userSettings: UserSettings
|
||||
|
||||
@AppStorage("meshMapType") var type: String = "hybrid"
|
||||
@AppStorage("meshMapCustomTileServer") var customTileServer: String = "" {
|
||||
didSet {
|
||||
if customTileServer == "" {
|
||||
self.customMapOverlay = nil
|
||||
} else {
|
||||
self.customMapOverlay = MapView.CustomMapOverlay(
|
||||
self.customMapOverlay = MapViewSwiftUI.CustomMapOverlay(
|
||||
mapName: customTileServer,
|
||||
tileType: "png",
|
||||
canReplaceMapContent: true
|
||||
|
|
@ -30,94 +29,71 @@ struct NodeMap: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "time", ascending: false)], animation: .default)
|
||||
private var positions: FetchedResults<PositionEntity>
|
||||
|
||||
@State private var showLabels: Bool = false
|
||||
|
||||
//@State private var annotationItems: [MapLocation] = []
|
||||
//@FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \NodeInfoEntity.lastHeard, ascending: false)], animation: .default)
|
||||
//private var locationNodes: FetchedResults<NodeInfoEntity>
|
||||
|
||||
/*@State private var mapRegion: MKCoordinateRegion = MKCoordinateRegion(
|
||||
center: CLLocationCoordinate2D(
|
||||
latitude: -38.758247,
|
||||
longitude: 175.360208
|
||||
),
|
||||
span: MKCoordinateSpan(
|
||||
latitudeDelta: 0.01,
|
||||
longitudeDelta: 0.01
|
||||
)
|
||||
)*/
|
||||
|
||||
@State private var customMapOverlay: MapView.CustomMapOverlay? = MapView.CustomMapOverlay(
|
||||
@State private var mapType: MKMapType = .standard
|
||||
@State var waypointCoordinate: CLLocationCoordinate2D?
|
||||
@State private var presentingWaypointForm = false
|
||||
@State private var customMapOverlay: MapViewSwiftUI.CustomMapOverlay? = MapViewSwiftUI.CustomMapOverlay(
|
||||
mapName: "offlinemap",
|
||||
tileType: "png",
|
||||
canReplaceMapContent: true
|
||||
)
|
||||
|
||||
//@State private var mapType: MKMapType = MKMapType.standard
|
||||
|
||||
@State private var zoomEnabled: Bool = true
|
||||
@State private var showZoomScale: Bool = true
|
||||
@State private var useMinZoomBoundary: Bool = false
|
||||
@State private var minZoom: Double = 0
|
||||
@State private var useMaxZoomBoundary: Bool = false
|
||||
@State private var maxZoom: Double = 3000000
|
||||
|
||||
@State private var scrollEnabled: Bool = true
|
||||
@State private var useScrollBoundaries: Bool = false
|
||||
@State private var scrollBoundaries: MKCoordinateRegion = MKCoordinateRegion()
|
||||
|
||||
@State private var rotationEnabled: Bool = true
|
||||
@State private var showCompassWhenRotated: Bool = true
|
||||
|
||||
@State private var showUserLocation: Bool = true
|
||||
@State private var userTrackingMode: MKUserTrackingMode = MKUserTrackingMode.none
|
||||
@State private var userLocation: CLLocationCoordinate2D? = LocationHelper.currentLocation
|
||||
|
||||
@State private var showAnnotations: Bool = true
|
||||
@State private var annotations: [MKPointAnnotation] = []
|
||||
|
||||
@State private var showOverlays: Bool = true
|
||||
@State private var overlays: [MapView.Overlay] = []
|
||||
|
||||
@State private var showMapCenter: Bool = false
|
||||
@State private var overlays: [MapViewSwiftUI.Overlay] = []
|
||||
|
||||
//@State private var showLabels: Bool = false
|
||||
//@State private var zoomEnabled: Bool = true
|
||||
//@State private var showZoomScale: Bool = true
|
||||
//@State private var useMinZoomBoundary: Bool = false
|
||||
//@State private var minZoom: Double = 0
|
||||
//@State private var useMaxZoomBoundary: Bool = false
|
||||
//@State private var maxZoom: Double = 3000000
|
||||
//@State private var scrollEnabled: Bool = true
|
||||
//@State private var useScrollBoundaries: Bool = false
|
||||
//@State private var scrollBoundaries: MKCoordinateRegion = MKCoordinateRegion()
|
||||
//@State private var rotationEnabled: Bool = true
|
||||
//@State private var showCompassWhenRotated: Bool = true
|
||||
//@State private var showUserLocation: Bool = true
|
||||
//@State private var userTrackingMode: MKUserTrackingMode = MKUserTrackingMode.none
|
||||
//@State private var userLocation: CLLocationCoordinate2D? = LocationHelper.currentLocation
|
||||
//@State private var showAnnotations: Bool = true
|
||||
//@State private var annotations: [MKPointAnnotation] = []
|
||||
//@State private var showOverlays: Bool = true
|
||||
//@State private var showMapCenter: Bool = false
|
||||
|
||||
var body: some View {
|
||||
|
||||
NavigationStack {
|
||||
ZStack {
|
||||
|
||||
//MapView(nodes: self.locationNodes)//.environmentObject(bleManager)
|
||||
// }
|
||||
MapView(
|
||||
//region: self.$mapRegion,
|
||||
ZStack {
|
||||
MapViewSwiftUI(onMarkerTap: { coord in
|
||||
presentingWaypointForm = true
|
||||
waypointCoordinate = coord
|
||||
}, positions: Array(positions), region: MKCoordinateRegion(center: LocationHelper.currentLocation, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)), mapViewType: mapType,
|
||||
customMapOverlay: self.customMapOverlay,
|
||||
mapType: self.type,
|
||||
zoomEnabled: self.zoomEnabled,
|
||||
showZoomScale: self.showZoomScale,
|
||||
zoomRange: (minHeight: self.useMinZoomBoundary ? self.minZoom : 0, maxHeight: self.useMaxZoomBoundary ? self.maxZoom : .infinity),
|
||||
scrollEnabled: self.scrollEnabled,
|
||||
scrollBoundaries: self.useScrollBoundaries ? self.scrollBoundaries : nil,
|
||||
rotationEnabled: self.rotationEnabled,
|
||||
showCompassWhenRotated: self.showCompassWhenRotated,
|
||||
showUserLocation: self.showUserLocation,
|
||||
userTrackingMode: self.userTrackingMode,
|
||||
userLocation: self.$userLocation,
|
||||
//annotations: self.annotations,
|
||||
//locationNodes: self.locationNodes.map({ nodeinfo in return nodeinfo }),
|
||||
overlays: self.overlays
|
||||
//context: self.context
|
||||
)
|
||||
|
||||
.frame(maxHeight: .infinity)
|
||||
.ignoresSafeArea(.all, edges: [.top, .leading, .trailing])
|
||||
VStack {
|
||||
Spacer()
|
||||
|
||||
Picker("", selection: $mapType) {
|
||||
Text("Standard").tag(MKMapType.standard)
|
||||
Text("Muted").tag(MKMapType.mutedStandard)
|
||||
Text("Hybrid").tag(MKMapType.hybrid)
|
||||
Text("Hybrid Flyover").tag(MKMapType.hybridFlyover)
|
||||
Text("Satellite").tag(MKMapType.satellite)
|
||||
Text("Sat Flyover").tag(MKMapType.satelliteFlyover)
|
||||
}
|
||||
.pickerStyle(SegmentedPickerStyle())
|
||||
.padding(.bottom, 30)
|
||||
}
|
||||
}
|
||||
.ignoresSafeArea(.all, edges: [.top, .leading, .trailing])
|
||||
.frame(maxHeight: .infinity)
|
||||
}
|
||||
|
||||
.navigationBarItems(leading:
|
||||
MeshtasticLogo(), trailing:
|
||||
ZStack {
|
||||
|
||||
ConnectedDevice(
|
||||
bluetoothOn: bleManager.isSwitchedOn,
|
||||
deviceConnected: bleManager.connectedPeripheral != nil,
|
||||
|
|
@ -125,10 +101,8 @@ struct NodeMap: View {
|
|||
"????")
|
||||
})
|
||||
.onAppear(perform: {
|
||||
|
||||
self.bleManager.context = context
|
||||
self.bleManager.userSettings = userSettings
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue