NCViewerImageDetailView.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. @IBAction func touchLocation(_ sender: Any) {
  25. if self.latitude > 0 && self.longitude > 0 {
  26. let url = URL(string: "http://maps.apple.com/maps?saddr=&daddr=\(latitude),\(longitude)")
  27. UIApplication.shared.open(url!)
  28. }
  29. }
  30. func updateExifLocal(metadata: tableMetadata) {
  31. DispatchQueue.global().async {
  32. if metadata.typeFile == k_metadataTypeFile_image {
  33. CCExifGeo.sharedInstance()?.setExif(metadata)
  34. }
  35. if let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  36. let latitudeString = localFile.exifLatitude
  37. let longitudeString = localFile.exifLongitude
  38. self.latitude = Double(localFile.exifLatitude) ?? 0
  39. self.longitude = Double(localFile.exifLongitude) ?? 0
  40. if let location = NCManageDatabase.sharedInstance.getLocationFromGeoLatitude(latitudeString, longitude: longitudeString) {
  41. self.location = location
  42. }
  43. DispatchQueue.main.async {
  44. if self.latitude > 0 && self.longitude > 0 {
  45. self.annotation.coordinate = CLLocationCoordinate2D(latitude: self.latitude, longitude: self.longitude)
  46. self.mapView.addAnnotation(self.annotation)
  47. self.mapView.setRegion(MKCoordinateRegion(center: self.annotation.coordinate, latitudinalMeters: 500, longitudinalMeters: 500), animated: false)
  48. self.locationButton.setTitle(self.location, for: .normal)
  49. }
  50. }
  51. }
  52. }
  53. }
  54. func hasData() -> Bool {
  55. if self.latitude > 0 && self.longitude > 0 {
  56. return true
  57. } else {
  58. return false
  59. }
  60. }
  61. }