2021-08-20 07:56:05 -07:00
|
|
|
//
|
2021-11-29 21:35:23 -08:00
|
|
|
// NodeMap.swift
|
2021-09-12 11:37:19 -07:00
|
|
|
// MeshtasticClient
|
2021-08-20 07:56:05 -07:00
|
|
|
//
|
|
|
|
|
// Created by Garth Vander Houwen on 8/7/21.
|
|
|
|
|
// Copyright © 2021 Apple. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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
|
2021-12-25 23:48:12 -08:00
|
|
|
|
|
|
|
|
// @AppStorage("meshMapType") var meshMapType: String = "hybrid"
|
|
|
|
|
|
2021-12-20 22:29:28 -08:00
|
|
|
@State private var showLabels: Bool = false
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2021-12-20 22:29:28 -08:00
|
|
|
@State private var annotationItems: [MapLocation] = []
|
|
|
|
|
@FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \NodeInfoEntity.lastHeard, ascending: false)], animation: .default)
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2021-12-15 23:53:45 -08:00
|
|
|
private var locationNodes: FetchedResults<NodeInfoEntity>
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2021-08-20 07:56:05 -07:00
|
|
|
var body: some View {
|
2021-12-25 23:48:12 -08:00
|
|
|
|
2021-12-17 00:46:23 -08:00
|
|
|
let location = 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
|
|
|
|
2021-12-31 09:43:37 -08:00
|
|
|
MapView(nodes: self.locationNodes)//.environmentObject(bleManager)
|
2021-12-25 23:48:12 -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)
|
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,
|
|
|
|
|
name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName :
|
|
|
|
|
"???")
|
2021-10-28 00:15:47 -07:00
|
|
|
})
|
2021-12-16 22:45:18 -08:00
|
|
|
.onAppear(perform: {
|
|
|
|
|
|
|
|
|
|
self.bleManager.context = context
|
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
|
|
|
}
|
|
|
|
|
}
|