2021-08-20 07:56:05 -07:00
|
|
|
//
|
2021-11-29 21:35:23 -08:00
|
|
|
// NodeMap.swift
|
2022-06-09 22:11:54 -07:00
|
|
|
// MeshtasticApple
|
2021-08-20 07:56:05 -07:00
|
|
|
//
|
|
|
|
|
// Created by Garth Vander Houwen on 8/7/21.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import MapKit
|
|
|
|
|
import CoreLocation
|
2021-12-20 22:29:28 -08:00
|
|
|
import CoreData
|
2021-08-20 07:56:05 -07:00
|
|
|
|
2021-09-18 15:33:35 -07:00
|
|
|
struct NodeMap: View {
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-12-15 23:53:45 -08:00
|
|
|
@Environment(\.managedObjectContext) var context
|
2021-11-29 15:59:06 -08:00
|
|
|
@EnvironmentObject var bleManager: BLEManager
|
2022-02-22 09:08:06 -10:00
|
|
|
@EnvironmentObject var userSettings: UserSettings
|
2022-01-10 06:09:31 +13:00
|
|
|
@AppStorage("meshMapType") var type: String = "hybrid"
|
|
|
|
|
@AppStorage("meshMapCustomTileServer") var customTileServer: String = "" {
|
|
|
|
|
didSet {
|
|
|
|
|
if customTileServer == "" {
|
|
|
|
|
self.customMapOverlay = nil
|
|
|
|
|
} else {
|
2023-01-13 15:49:25 -08:00
|
|
|
self.customMapOverlay = MapViewSwiftUI.CustomMapOverlay(
|
2022-01-10 06:09:31 +13:00
|
|
|
mapName: customTileServer,
|
|
|
|
|
tileType: "png",
|
|
|
|
|
canReplaceMapContent: true
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-13 15:49:25 -08:00
|
|
|
@FetchRequest(sortDescriptors: [NSSortDescriptor(key: "time", ascending: false)], animation: .default)
|
|
|
|
|
private var positions: FetchedResults<PositionEntity>
|
2022-01-10 06:09:31 +13:00
|
|
|
|
2023-01-13 15:49:25 -08:00
|
|
|
@State private var mapType: MKMapType = .standard
|
|
|
|
|
@State var waypointCoordinate: CLLocationCoordinate2D?
|
|
|
|
|
@State private var presentingWaypointForm = false
|
|
|
|
|
@State private var customMapOverlay: MapViewSwiftUI.CustomMapOverlay? = MapViewSwiftUI.CustomMapOverlay(
|
2022-01-17 14:03:48 +13:00
|
|
|
mapName: "offlinemap",
|
2022-01-10 06:09:31 +13:00
|
|
|
tileType: "png",
|
|
|
|
|
canReplaceMapContent: true
|
|
|
|
|
)
|
2023-01-13 15:49:25 -08:00
|
|
|
@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
|
2022-01-10 06:09:31 +13:00
|
|
|
|
2021-08-20 07:56:05 -07:00
|
|
|
var body: some View {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2022-10-17 21:18:57 -07:00
|
|
|
NavigationStack {
|
2023-01-13 15:49:25 -08:00
|
|
|
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,
|
2022-01-10 06:09:31 +13:00
|
|
|
customMapOverlay: self.customMapOverlay,
|
2022-01-18 17:09:23 +13:00
|
|
|
overlays: self.overlays
|
2022-01-10 06:09:31 +13:00
|
|
|
)
|
2023-01-13 15:49:25 -08:00
|
|
|
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)
|
|
|
|
|
}
|
2022-12-30 13:18:02 -08:00
|
|
|
}
|
2023-01-13 15:49:25 -08:00
|
|
|
.ignoresSafeArea(.all, edges: [.top, .leading, .trailing])
|
|
|
|
|
.frame(maxHeight: .infinity)
|
2021-09-23 20:10:53 -07:00
|
|
|
}
|
2022-10-17 21:18:57 -07:00
|
|
|
.navigationBarItems(leading:
|
|
|
|
|
MeshtasticLogo(), trailing:
|
|
|
|
|
ZStack {
|
|
|
|
|
ConnectedDevice(
|
|
|
|
|
bluetoothOn: bleManager.isSwitchedOn,
|
|
|
|
|
deviceConnected: bleManager.connectedPeripheral != nil,
|
|
|
|
|
name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName :
|
|
|
|
|
"????")
|
|
|
|
|
})
|
|
|
|
|
.onAppear(perform: {
|
|
|
|
|
self.bleManager.context = context
|
|
|
|
|
self.bleManager.userSettings = userSettings
|
|
|
|
|
})
|
2021-08-20 07:56:05 -07:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-18 21:11:54 -07:00
|
|
|
|
|
|
|
|
struct NodeMap_Previews: PreviewProvider {
|
2021-09-22 13:00:46 -07:00
|
|
|
static let bleManager = BLEManager()
|
2021-09-18 21:11:54 -07:00
|
|
|
|
|
|
|
|
static var previews: some View {
|
2021-10-27 21:15:36 -07:00
|
|
|
NodeMap()
|
2021-09-18 21:11:54 -07:00
|
|
|
}
|
|
|
|
|
}
|