NCViewerImageDetailView.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // NCViewerImageDetailView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 31/10/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. import MapKit
  10. class NCViewerImageDetailView: UIView {
  11. @IBOutlet weak var mapView: MKMapView!
  12. @IBOutlet weak var locationButton: UIButton!
  13. var annotation = MKPointAnnotation()
  14. var latitude: Double = 0
  15. var longitude: Double = 0
  16. var location: String = ""
  17. override func awakeFromNib() {
  18. super.awakeFromNib()
  19. mapView.layer.cornerRadius = 6
  20. mapView.isZoomEnabled = false
  21. mapView.isScrollEnabled = false
  22. mapView.isUserInteractionEnabled = false
  23. }
  24. func updateExifLocal(metadata: tableMetadata) {
  25. DispatchQueue.global().async {
  26. if metadata.typeFile == k_metadataTypeFile_image {
  27. CCExifGeo.sharedInstance()?.setExif(metadata)
  28. }
  29. if let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  30. let latitudeString = localFile.exifLatitude
  31. let longitudeString = localFile.exifLongitude
  32. self.latitude = Double(localFile.exifLatitude) ?? 0
  33. self.longitude = Double(localFile.exifLongitude) ?? 0
  34. if let location = NCManageDatabase.sharedInstance.getLocationFromGeoLatitude(latitudeString, longitude: longitudeString) {
  35. self.location = location
  36. }
  37. DispatchQueue.main.async {
  38. if self.latitude > 0 && self.longitude > 0 {
  39. self.annotation.coordinate = CLLocationCoordinate2D(latitude: self.latitude, longitude: self.longitude)
  40. self.mapView.addAnnotation(self.annotation)
  41. self.mapView.setRegion(MKCoordinateRegion(center: self.annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
  42. self.locationButton.setTitle(self.location, for: .normal)
  43. }
  44. }
  45. }
  46. }
  47. }
  48. func hasData() -> Bool {
  49. if self.latitude > 0 && self.longitude > 0 {
  50. return true
  51. } else {
  52. return false
  53. }
  54. }
  55. }