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
|
2021-12-25 23:48:12 -08:00
|
|
|
|
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 {
|
|
|
|
|
self.customMapOverlay = MapView.CustomMapOverlay(
|
|
|
|
|
mapName: customTileServer,
|
|
|
|
|
tileType: "png",
|
|
|
|
|
canReplaceMapContent: true
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 22:29:28 -08:00
|
|
|
@State private var showLabels: Bool = false
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2022-01-10 06:09:31 +13:00
|
|
|
//@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(
|
2022-01-17 14:03:48 +13:00
|
|
|
mapName: "offlinemap",
|
2022-01-10 06:09:31 +13:00
|
|
|
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
|
2022-01-10 19:23:30 +13:00
|
|
|
@State private var userLocation: CLLocationCoordinate2D? = LocationHelper.currentLocation
|
2022-01-10 06:09:31 +13:00
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
2021-08-20 07:56:05 -07:00
|
|
|
var body: some View {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2022-01-10 19:23:30 +13:00
|
|
|
//self.$userLocation = LocationHelper.currentLocation
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-12-25 23:48:12 -08:00
|
|
|
NavigationView {
|
2021-12-24 20:18:42 +13:00
|
|
|
|
2021-09-14 21:38:12 -07:00
|
|
|
ZStack {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2022-01-10 06:09:31 +13:00
|
|
|
//MapView(nodes: self.locationNodes)//.environmentObject(bleManager)
|
2021-12-25 23:48:12 -08:00
|
|
|
// }
|
2022-01-10 06:09:31 +13:00
|
|
|
MapView(
|
|
|
|
|
//region: self.$mapRegion,
|
|
|
|
|
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,
|
2022-01-16 05:48:02 +13:00
|
|
|
//locationNodes: self.locationNodes.map({ nodeinfo in return nodeinfo }),
|
2022-01-18 17:09:23 +13:00
|
|
|
overlays: self.overlays
|
|
|
|
|
//context: self.context
|
2022-01-10 06:09:31 +13:00
|
|
|
)
|
2022-01-16 16:58:23 -08:00
|
|
|
|
2021-12-17 00:46:23 -08:00
|
|
|
.frame(maxHeight: .infinity)
|
2021-12-20 22:29:28 -08:00
|
|
|
.ignoresSafeArea(.all, edges: [.leading, .trailing])
|
2021-09-14 21:38:12 -07:00
|
|
|
}
|
|
|
|
|
.navigationTitle("Mesh Map")
|
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2022-01-16 16:58:23 -08:00
|
|
|
|
2021-10-28 00:15:47 -07:00
|
|
|
.navigationBarItems(trailing:
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-12-16 22:45:18 -08:00
|
|
|
ZStack {
|
|
|
|
|
|
|
|
|
|
ConnectedDevice(
|
|
|
|
|
bluetoothOn: bleManager.isSwitchedOn,
|
|
|
|
|
deviceConnected: bleManager.connectedPeripheral != nil,
|
2022-06-17 18:20:30 -07:00
|
|
|
name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName :
|
2022-07-01 19:44:25 -07:00
|
|
|
"????")
|
2021-10-28 00:15:47 -07:00
|
|
|
})
|
2021-12-16 22:45:18 -08:00
|
|
|
.onAppear(perform: {
|
|
|
|
|
|
|
|
|
|
self.bleManager.context = context
|
2022-02-22 09:08:06 -10:00
|
|
|
self.bleManager.userSettings = userSettings
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-12-16 22:45:18 -08:00
|
|
|
})
|
2021-09-23 20:10:53 -07:00
|
|
|
}
|
|
|
|
|
.navigationViewStyle(StackNavigationViewStyle())
|
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
|
|
|
}
|
|
|
|
|
}
|