Meshtastic-Apple/MeshtasticClient/Views/Nodes/NodeMap.swift

150 lines
4.4 KiB
Swift
Raw Normal View History

2021-08-20 07:56:05 -07:00
//
2021-11-29 21:35:23 -08:00
// NodeMap.swift
// 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
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
@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
//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
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,
//locationNodes: self.locationNodes.map({ nodeinfo in return nodeinfo }),
overlays: self.overlays
//context: self.context
2022-01-10 06:09:31 +13:00
)
2022-01-16 16:58:23 -08:00
.frame(maxHeight: .infinity)
2021-12-20 22:29:28 -08:00
.ignoresSafeArea(.all, edges: [.leading, .trailing])
}
.navigationTitle("Mesh Map")
.navigationBarTitleDisplayMode(.inline)
2022-01-16 16:58:23 -08:00
.navigationBarItems(trailing:
2021-11-29 15:59:06 -08:00
ZStack {
ConnectedDevice(
bluetoothOn: bleManager.isSwitchedOn,
deviceConnected: bleManager.connectedPeripheral != nil,
name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.lastFourCode :
"????")
})
.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
})
}
.navigationViewStyle(StackNavigationViewStyle())
2021-08-20 07:56:05 -07:00
}
}
2021-09-18 21:11:54 -07:00
struct NodeMap_Previews: PreviewProvider {
static let bleManager = BLEManager()
2021-09-18 21:11:54 -07:00
static var previews: some View {
NodeMap()
2021-09-18 21:11:54 -07:00
}
}