Show map controls in toolbar

This commit is contained in:
Milan Stute
2021-03-11 08:57:44 +01:00
parent 599b604fa9
commit a68448a25c
2 changed files with 19 additions and 73 deletions
@@ -44,7 +44,8 @@ struct OpenHaystackMainView: View {
.navigationTitle(self.focusedAccessory?.name ?? "OpenHaystack")
ZStack {
self.mapView
AccessoryMapView(accessoryController: self.accessoryController, mapType: self.$mapType, focusedAccessory: self.focusedAccessory)
.overlay(self.mapOverlay)
if self.popUpAlertType != nil {
VStack {
Spacer()
@@ -55,6 +56,17 @@ struct OpenHaystackMainView: View {
}
}
.ignoresSafeArea(.all)
.toolbar(content: {
Picker("", selection: self.$mapType) {
Text("Satellite").tag(MKMapType.hybrid)
Text("Standard").tag(MKMapType.standard)
}
.pickerStyle(SegmentedPickerStyle())
Button(action: self.downloadLocationReports) {
Label("Reload", systemImage: "arrow.clockwise")
}
.disabled(self.accessories.isEmpty)
})
.alert(
item: self.$alertType,
content: { alertType in
@@ -95,39 +107,6 @@ struct OpenHaystackMainView: View {
}
}
/// Right side of the view showing a map with all items presented.
var mapView: some View {
ZStack {
AccessoryMapView(accessoryController: self.accessoryController, mapType: self.$mapType, focusedAccessory: self.focusedAccessory)
.overlay(self.mapOverlay)
VStack {
Spacer()
HStack {
Picker("", selection: self.$mapType) {
Text("Satellite").tag(MKMapType.hybrid)
Text("Standard").tag(MKMapType.standard)
}
.pickerStyle(SegmentedPickerStyle())
.frame(width: 150, alignment: .center)
Button(
action: self.downloadLocationReports,
label: {
Image(systemName: "arrow.clockwise")
Text("Reload")
}
)
.opacity(1.0)
.disabled(self.accessories.isEmpty)
}
.padding(.bottom, 25)
}
}
}
func onAppear() {
/// Checks if the search party token can be fetched without the Mail Plugin. If true the plugin is not needed for this environment. (e.g. when SIP is disabled)
@@ -19,34 +19,6 @@ final class MapViewController: NSViewController, MKMapViewDelegate {
self.mapView.register(AccessoryAnnotationView.self, forAnnotationViewWithReuseIdentifier: "Accessory")
}
func addLocationsReports(from devices: [FindMyDevice]) {
if !self.mapView.annotations.isEmpty {
self.mapView.removeAnnotations(self.mapView.annotations)
}
// Zoom to first location
if let location = devices.first?.decryptedReports?.first {
let coordinate = CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
let span = MKCoordinateSpan(latitudeDelta: 5.0, longitudeDelta: 5.0)
let region = MKCoordinateRegion(center: coordinate, span: span)
self.mapView.setRegion(region, animated: true)
}
// Add pins
for device in devices {
guard let reports = device.decryptedReports else { continue }
for report in reports {
let pin = MKPointAnnotation()
pin.title = device.deviceId
pin.coordinate = CLLocationCoordinate2D(latitude: report.latitude, longitude: report.longitude)
self.mapView.addAnnotation(pin)
}
}
}
func zoom(on accessory: Accessory?) {
self.focusedAccessory = accessory
guard let location = accessory?.lastLocation else { return }
@@ -58,8 +30,12 @@ final class MapViewController: NSViewController, MKMapViewDelegate {
}
func addLastLocations(from accessories: [Accessory]) {
if !self.mapView.annotations.isEmpty {
self.mapView.removeAnnotations(self.mapView.annotations)
// Add pins
self.mapView.removeAnnotations(self.mapView.annotations)
for accessory in accessories {
guard accessory.lastLocation != nil else { continue }
let annotation = AccessoryAnnotation(accessory: accessory)
self.mapView.addAnnotation(annotation)
}
// Zoom to first location
@@ -70,15 +46,6 @@ final class MapViewController: NSViewController, MKMapViewDelegate {
self.mapView.setRegion(region, animated: true)
}
}
// Add pins
for accessory in accessories {
guard accessory.lastLocation != nil else { continue }
let annotation = AccessoryAnnotation(accessory: accessory)
self.mapView.addAnnotation(annotation)
}
}
func changeMapType(_ mapType: MKMapType) {