NCViewerImageDetailView.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  35. }
  36. }
  37. func insertDataDetail() {
  38. if self.latitude > 0 && self.longitude > 0 {
  39. annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
  40. mapView.addAnnotation(annotation)
  41. mapView.setRegion(MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
  42. locationButton.setTitle(location, for: .normal)
  43. }
  44. }
  45. func hasData() -> Bool {
  46. if self.latitude > 0 && self.longitude > 0 {
  47. return true
  48. } else {
  49. return false
  50. }
  51. }
  52. }