NCViewerImageDetailView.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }
  21. func updateExifLocal(metadata: tableMetadata) {
  22. DispatchQueue.global().async {
  23. if metadata.typeFile == k_metadataTypeFile_image {
  24. CCExifGeo.sharedInstance()?.setExif(metadata)
  25. }
  26. if let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  27. let latitudeString = localFile.exifLatitude
  28. let longitudeString = localFile.exifLongitude
  29. self.latitude = Double(localFile.exifLatitude) ?? 0
  30. self.longitude = Double(localFile.exifLongitude) ?? 0
  31. if let location = NCManageDatabase.sharedInstance.getLocationFromGeoLatitude(latitudeString, longitude: longitudeString) {
  32. self.location = location
  33. }
  34. DispatchQueue.main.async {
  35. self.insertDataDetail()
  36. }
  37. }
  38. }
  39. }
  40. func insertDataDetail() {
  41. if self.latitude > 0 && self.longitude > 0 {
  42. annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
  43. mapView.addAnnotation(annotation)
  44. mapView.setRegion(MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
  45. locationButton.setTitle(location, for: .normal)
  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. }