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-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
|
|
|
// CoreData
|
|
|
|
|
@Environment(\.managedObjectContext) var context
|
2021-11-29 15:59:06 -08:00
|
|
|
@EnvironmentObject var bleManager: BLEManager
|
2021-12-15 23:53:45 -08:00
|
|
|
|
|
|
|
|
@FetchRequest(
|
|
|
|
|
sortDescriptors: [NSSortDescriptor(keyPath: \NodeInfoEntity.lastHeard, ascending: false)],
|
|
|
|
|
animation: .default)
|
|
|
|
|
|
|
|
|
|
private var locationNodes: FetchedResults<NodeInfoEntity>
|
|
|
|
|
|
2021-08-20 07:56:05 -07:00
|
|
|
struct MapLocation: Identifiable {
|
|
|
|
|
let id = UUID()
|
|
|
|
|
let name: String
|
|
|
|
|
let coordinate: CLLocationCoordinate2D
|
|
|
|
|
}
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-08-20 07:56:05 -07:00
|
|
|
var body: some View {
|
2021-10-03 10:20:14 -07:00
|
|
|
let location = LocationHelper.currentLocation
|
2021-10-11 07:28:28 -07:00
|
|
|
|
2021-12-16 14:13:54 -08:00
|
|
|
|
2021-10-11 07:28:28 -07:00
|
|
|
let currentCoordinatePosition = CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
|
2021-08-20 07:56:05 -07:00
|
|
|
let regionBinding = Binding<MKCoordinateRegion>(
|
|
|
|
|
get: {
|
2021-09-23 20:10:53 -07:00
|
|
|
MKCoordinateRegion(center: currentCoordinatePosition, span: MKCoordinateSpan(latitudeDelta: 0.0359, longitudeDelta: 0.0359))
|
2021-08-20 07:56:05 -07:00
|
|
|
},
|
|
|
|
|
set: { _ in }
|
|
|
|
|
)
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-09-14 21:38:12 -07:00
|
|
|
NavigationView {
|
2021-11-29 15:59:06 -08:00
|
|
|
|
2021-09-14 21:38:12 -07:00
|
|
|
ZStack {
|
2021-12-16 14:13:54 -08:00
|
|
|
|
|
|
|
|
Map(coordinateRegion: regionBinding, showsUserLocation: true, userTrackingMode: .none)
|
|
|
|
|
.frame(maxHeight: .infinity)
|
|
|
|
|
//, annotationItems: locationNodes[0].positions?) { location in
|
|
|
|
|
// MapAnnotation(
|
|
|
|
|
// coordinate: location.coordinate,
|
|
|
|
|
// content: {
|
|
|
|
|
// CircleText(text: location.latitude, color: .accentColor)
|
|
|
|
|
// }
|
|
|
|
|
// )
|
|
|
|
|
// }.frame(maxHeight: .infinity)
|
|
|
|
|
|
|
|
|
|
//Map(coordinateRegion: regionBinding,
|
|
|
|
|
// interactionModes: [.all],
|
|
|
|
|
// showsUserLocation: true,
|
|
|
|
|
// userTrackingMode: .constant(.follow), annotationItems: locationNodes) { node in
|
|
|
|
|
|
|
|
|
|
//MapAnnotation(
|
|
|
|
|
//coordinate: node.positions[0].coordinate,
|
|
|
|
|
//content: {
|
|
|
|
|
// CircleText(text: node.user!.shortName, color: .accentColor)
|
|
|
|
|
//}
|
|
|
|
|
// )
|
|
|
|
|
//}
|
|
|
|
|
//.frame(maxHeight: .infinity)
|
|
|
|
|
//.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
|
|
|
}
|
|
|
|
|
}
|