feat: Recreate mappa segnalazioni with new logic and aligned with Android app
Resolves: https://gitlab.steamware.net/eqn/eqn.ios/-/issues/34
This commit is contained in:
@@ -9,9 +9,11 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
651901B925F5358700CAFF20 /* EQNMapAnnotationSeismic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 651901B825F5358700CAFF20 /* EQNMapAnnotationSeismic.swift */; };
|
||||
6525A82625E13FD4008FE0D0 /* SeismicNetworkAdvertiseTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6525A82525E13FD4008FE0D0 /* SeismicNetworkAdvertiseTableViewCell.swift */; };
|
||||
65355FFF25F38D3300BB57D2 /* SegnalazioniMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65355FFE25F38D3300BB57D2 /* SegnalazioniMapViewController.swift */; };
|
||||
6535600425F398CD00BB57D2 /* Costanti+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6535600325F398CD00BB57D2 /* Costanti+Extensions.swift */; };
|
||||
653C67E225F3CC2E00FE52AC /* EQNCustomAnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653C67E125F3CC2E00FE52AC /* EQNCustomAnnotationView.swift */; };
|
||||
653C67E625F3CC8400FE52AC /* EQNCustomAnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653C67E125F3CC2E00FE52AC /* EQNCustomAnnotationView.swift */; };
|
||||
653C67FC25F3D63500FE52AC /* EQNMapAnnotationUserReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653C67FB25F3D63500FE52AC /* EQNMapAnnotationUserReport.swift */; };
|
||||
653C680425F3DF8A00FE52AC /* EQNBaseMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653C680325F3DF8A00FE52AC /* EQNBaseMapViewController.swift */; };
|
||||
6544416B25E9599000C41714 /* EQNDebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6544416A25E9599000C41714 /* EQNDebugViewController.swift */; };
|
||||
6586971125F44C26009C0182 /* EQNBlurredCloseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6586971025F44C26009C0182 /* EQNBlurredCloseButton.swift */; };
|
||||
@@ -25,7 +27,6 @@
|
||||
8C10B0BB2281FE7F00125C9F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8C10B0BD2281FE7F00125C9F /* Localizable.strings */; };
|
||||
8C14113121ED3E5B00A59729 /* SettingsRealTimeAlertsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C14113021ED3E5B00A59729 /* SettingsRealTimeAlertsViewController.m */; };
|
||||
8C14113721EE502800A59729 /* EQNAllertaSismica.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C14113621EE502800A59729 /* EQNAllertaSismica.m */; };
|
||||
8C2B251121938BFD00E0E25E /* SegnalazioniUtenteDettagliMappa.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C2B251021938BFD00E0E25E /* SegnalazioniUtenteDettagliMappa.m */; };
|
||||
8C465D9A21F653AB00F04673 /* Assets.xcassets in Frameworks */ = {isa = PBXBuildFile; fileRef = 8CBD3DD12149B9AD0070C963 /* Assets.xcassets */; };
|
||||
8C465D9B21F653CA00F04673 /* Assets.xcassets in Frameworks */ = {isa = PBXBuildFile; fileRef = 8CBD3DD12149B9AD0070C963 /* Assets.xcassets */; };
|
||||
8C465D9F21F7BE0600F04673 /* Assets.xcassets in Sources */ = {isa = PBXBuildFile; fileRef = 8CBD3DD12149B9AD0070C963 /* Assets.xcassets */; };
|
||||
@@ -279,8 +280,10 @@
|
||||
40CD2E5581CF2FA3D52F392D /* Pods-Earthquake Network.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Earthquake Network.release.xcconfig"; path = "Pods/Target Support Files/Pods-Earthquake Network/Pods-Earthquake Network.release.xcconfig"; sourceTree = "<group>"; };
|
||||
651901B825F5358700CAFF20 /* EQNMapAnnotationSeismic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNMapAnnotationSeismic.swift; sourceTree = "<group>"; };
|
||||
6525A82525E13FD4008FE0D0 /* SeismicNetworkAdvertiseTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeismicNetworkAdvertiseTableViewCell.swift; sourceTree = "<group>"; };
|
||||
65355FFE25F38D3300BB57D2 /* SegnalazioniMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegnalazioniMapViewController.swift; sourceTree = "<group>"; };
|
||||
6535600325F398CD00BB57D2 /* Costanti+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Costanti+Extensions.swift"; sourceTree = "<group>"; };
|
||||
653C67E125F3CC2E00FE52AC /* EQNCustomAnnotationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNCustomAnnotationView.swift; sourceTree = "<group>"; };
|
||||
653C67FB25F3D63500FE52AC /* EQNMapAnnotationUserReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNMapAnnotationUserReport.swift; sourceTree = "<group>"; };
|
||||
653C680325F3DF8A00FE52AC /* EQNBaseMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNBaseMapViewController.swift; sourceTree = "<group>"; };
|
||||
6544416A25E9599000C41714 /* EQNDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNDebugViewController.swift; sourceTree = "<group>"; };
|
||||
6586971025F44C26009C0182 /* EQNBlurredCloseButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNBlurredCloseButton.swift; sourceTree = "<group>"; };
|
||||
@@ -304,8 +307,6 @@
|
||||
8C14113021ED3E5B00A59729 /* SettingsRealTimeAlertsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsRealTimeAlertsViewController.m; sourceTree = "<group>"; };
|
||||
8C14113521EE502800A59729 /* EQNAllertaSismica.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EQNAllertaSismica.h; sourceTree = "<group>"; };
|
||||
8C14113621EE502800A59729 /* EQNAllertaSismica.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EQNAllertaSismica.m; sourceTree = "<group>"; };
|
||||
8C2B250F21938BFD00E0E25E /* SegnalazioniUtenteDettagliMappa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SegnalazioniUtenteDettagliMappa.h; sourceTree = "<group>"; };
|
||||
8C2B251021938BFD00E0E25E /* SegnalazioniUtenteDettagliMappa.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SegnalazioniUtenteDettagliMappa.m; sourceTree = "<group>"; };
|
||||
8C465D9721F6539700F04673 /* Earthquake Network.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = "Earthquake Network.xcodeproj"; sourceTree = "<group>"; };
|
||||
8C483CAD21FDA53B00259FD2 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
|
||||
8C483CB021FDA8C700259FD2 /* Earthquake Network-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Earthquake Network-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
@@ -603,6 +604,7 @@
|
||||
65DBFB5225E2A2580041CBA6 /* Map annotation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
653C67FB25F3D63500FE52AC /* EQNMapAnnotationUserReport.swift */,
|
||||
651901B825F5358700CAFF20 /* EQNMapAnnotationSeismic.swift */,
|
||||
8C602248218EDBE200C799C2 /* EQNMapAnnotationPastquakes.h */,
|
||||
8C602249218EDBE200C799C2 /* EQNMapAnnotationPastquakes.m */,
|
||||
@@ -661,8 +663,6 @@
|
||||
8CC1B159217CB09100F22178 /* DettagliMappaViewController.m */,
|
||||
8C602244218D9DB200C799C2 /* PastquakesDettagliMappa.h */,
|
||||
8C602245218D9DB200C799C2 /* PastquakesDettagliMappa.m */,
|
||||
8C2B250F21938BFD00E0E25E /* SegnalazioniUtenteDettagliMappa.h */,
|
||||
8C2B251021938BFD00E0E25E /* SegnalazioniUtenteDettagliMappa.m */,
|
||||
);
|
||||
path = "Dettagli mappa";
|
||||
sourceTree = "<group>";
|
||||
@@ -1046,6 +1046,7 @@
|
||||
children = (
|
||||
8C5EA23B2177B51C002DC156 /* SegnalazioniViewController.h */,
|
||||
8C5EA23C2177B51C002DC156 /* SegnalazioniViewController.m */,
|
||||
65355FFE25F38D3300BB57D2 /* SegnalazioniMapViewController.swift */,
|
||||
);
|
||||
path = Reports;
|
||||
sourceTree = "<group>";
|
||||
@@ -1591,6 +1592,7 @@
|
||||
8CAFD7C521825E4A00F8BD29 /* EQNSisma.m in Sources */,
|
||||
DCC23DEC24D281CE003A2404 /* SubscriptionsActiveTableViewCell.swift in Sources */,
|
||||
8CF6604F214C0E58009F4314 /* EQNCalibrazione.m in Sources */,
|
||||
65355FFF25F38D3300BB57D2 /* SegnalazioniMapViewController.swift in Sources */,
|
||||
DCBB84F0252CFC4600F12633 /* AlertsNoLocationTableViewCell.swift in Sources */,
|
||||
DCD3E3C024D15576007C78D4 /* PurchaseProVersionViewController.swift in Sources */,
|
||||
651901B925F5358700CAFF20 /* EQNMapAnnotationSeismic.swift in Sources */,
|
||||
@@ -1598,7 +1600,6 @@
|
||||
DC99A50324E66E270071BC9F /* EQNCommandProtocol.swift in Sources */,
|
||||
DCB45BC8250E86E100DB2D0C /* SeismicSettingsViewController.swift in Sources */,
|
||||
DCF10DC624D2B8C7009F34C3 /* EQNPurchaseUtility.swift in Sources */,
|
||||
8C2B251121938BFD00E0E25E /* SegnalazioniUtenteDettagliMappa.m in Sources */,
|
||||
DC0E551324F8063300D54270 /* SettingSegmentedTableViewCell.swift in Sources */,
|
||||
DC47D1BC252A0C2B004119F6 /* AlertsPastEartquakesTableViewCell.swift in Sources */,
|
||||
DCEFF21724F58569009D3FE1 /* SettingSectionHeaderView.swift in Sources */,
|
||||
@@ -1629,6 +1630,7 @@
|
||||
DCB28CEE24FB8400001F557E /* SettingsViewController.swift in Sources */,
|
||||
DCB528212560161C005288E5 /* AlertSimulatorViewController.swift in Sources */,
|
||||
DCC76BD8251F56050005C4DC /* SeismicCardSettingsViewController.swift in Sources */,
|
||||
653C67FC25F3D63500FE52AC /* EQNMapAnnotationUserReport.swift in Sources */,
|
||||
DC3CE50A250EB7A8005A7DD5 /* EQNGenericPickerViewController.swift in Sources */,
|
||||
8C602246218D9DB200C799C2 /* PastquakesDettagliMappa.m in Sources */,
|
||||
DCEFF21A24F587E3009D3FE1 /* SettingItem.swift in Sources */,
|
||||
@@ -1884,6 +1886,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = C4FB0D7EEA34F8222369E1BB /* Pods-Earthquake Network.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "Earthquake Network/Earthquake Network.entitlements";
|
||||
@@ -1995,6 +1998,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 40CD2E5581CF2FA3D52F392D /* Pods-Earthquake Network.release.xcconfig */;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "Earthquake Network/Earthquake Network.entitlements";
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
//
|
||||
// SegnalazioniMapViewController.swift
|
||||
// Earthquake Network
|
||||
//
|
||||
// Created by Andrea Busi on 06/03/21.
|
||||
// Copyright © 2021 Earthquake Network. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MapKit
|
||||
|
||||
class SegnalazioniMapViewController: EQNBaseMapViewController {
|
||||
|
||||
struct MapCircle {
|
||||
let color: UIColor
|
||||
let circle: MKCircle
|
||||
}
|
||||
|
||||
/// Contains circles and related colors to draw overlays on the map
|
||||
private var mapCircles = [MapCircle]()
|
||||
/// Reports currently showned on the map
|
||||
private var filteredReports = [EQNSegnalazione]()
|
||||
|
||||
// MARK: - View Lifecycle
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func registerMapAnnotationViews() {
|
||||
mapView.register(EQNCustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: EQNCustomAnnotationView.Identifier)
|
||||
}
|
||||
|
||||
override func loadDataSource() {
|
||||
guard let list = EQNManager.manager().elencoSelagnazioniManuali else { return }
|
||||
|
||||
// create new annotations and display them
|
||||
filteredReports = EQNUtility.filterSegnalazioni(list, forFilter: filter)
|
||||
let annotations = filteredReports.compactMap { EQNMapAnnotationUserReport(report: $0) }
|
||||
|
||||
// create circles to group cluster of reports and show on the map
|
||||
let mapCircles = elaborateCircles(for: filteredReports)
|
||||
addMapCircles(mapCircles)
|
||||
|
||||
// update map and center
|
||||
updateMap(with: annotations)
|
||||
}
|
||||
|
||||
override func centerMap() {
|
||||
var centerLocation: CLLocation?
|
||||
|
||||
// Se c'è un cluster distante dall'utente meno del raggio di notifica sulle segnalazioni,
|
||||
// allora mostro all'utente quel cluster
|
||||
if let userPosition = CLLocationManager().location {
|
||||
let nearestCluser = mapCircles
|
||||
.map { CLLocation(latitude: $0.circle.coordinate.latitude, longitude: $0.circle.coordinate.longitude) }
|
||||
.sorted(by: { abs(userPosition.distance(from: $0)) < abs(userPosition.distance(from: $1)) })
|
||||
.first
|
||||
|
||||
// controlliamo che sia inferiore al raggio impostato per le notifiche
|
||||
if let radius = Double(EQNNotificheSegnalazioniUtente.shared().distanzaPosizione),
|
||||
let nearestCluser = nearestCluser,
|
||||
abs(nearestCluser.distance(from: userPosition)) < radius {
|
||||
centerLocation = nearestCluser
|
||||
}
|
||||
}
|
||||
|
||||
// altrimenti mostro il cluster più recente
|
||||
if centerLocation == nil, let newestReport = filteredReports.sorted(by: { $0.date > $1.date }).first {
|
||||
// cerco il cerchio che contiene la segnalazione più recente
|
||||
// tra i cerchi trovati, prendo quello più piccolo
|
||||
let newestCircle = mapCircles
|
||||
.map { $0.circle }
|
||||
.filter { (circle) -> Bool in
|
||||
let location = CLLocation(latitude: circle.coordinate.latitude, longitude: circle.coordinate.longitude)
|
||||
let distance = abs(newestReport.coordinate.distance(from: location))
|
||||
return distance < circle.radius
|
||||
}
|
||||
.sorted(by: { $0.radius < $1.radius })
|
||||
.first
|
||||
if let newestCircle = newestCircle {
|
||||
centerLocation = CLLocation(latitude: newestCircle.coordinate.latitude, longitude: newestCircle.coordinate.longitude)
|
||||
}
|
||||
}
|
||||
|
||||
if let centerLocation = centerLocation {
|
||||
let span = MKCoordinateSpan(latitudeDelta: 8, longitudeDelta: 8)
|
||||
let region = MKCoordinateRegion(center: centerLocation.coordinate, span: span)
|
||||
mapView.setCenter(centerLocation.coordinate, animated: false)
|
||||
mapView.setRegion(region, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func elaborateCircles(for reports: [EQNSegnalazione]) -> [MapCircle] {
|
||||
let vector_latitude = reports.map { $0.coordinate.coordinate.latitude }
|
||||
let vector_longitude = reports.map { $0.coordinate.coordinate.longitude }
|
||||
let vector_date = reports.map { $0.date }
|
||||
let vector_state = reports.map { $0.magnitude }
|
||||
|
||||
let minutes: TimeInterval = filter.minutes
|
||||
|
||||
var cluster_code = 0
|
||||
var vector_cluster = [Int](repeating: 0, count: vector_latitude.count)
|
||||
for i in 0..<vector_latitude.count {
|
||||
let deltaMinute_i = getDeltaMinute(vector_date[i])
|
||||
if vector_cluster[i] == 0 && deltaMinute_i <= minutes {
|
||||
for j in 0..<vector_latitude.count {
|
||||
let deltaMinute_j = getDeltaMinute(vector_date[j])
|
||||
if i != j && deltaMinute_j <= minutes {
|
||||
if abs(vector_latitude[i] - vector_latitude[j]) < 4 && abs(vector_longitude[i] - vector_longitude[j]) < 4 && abs(deltaMinute_i - deltaMinute_j) <= 20 {
|
||||
if vector_cluster[j] > 0 {
|
||||
vector_cluster[i] = vector_cluster[j]
|
||||
} else {
|
||||
if vector_cluster[i] > 0 {
|
||||
vector_cluster[j] = vector_cluster[i]
|
||||
} else {
|
||||
cluster_code += 1
|
||||
vector_cluster[i] = cluster_code
|
||||
vector_cluster[j] = cluster_code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//calcola i centri dei cluster e l'intensità di ciascun cluster
|
||||
var lat_centre = [Double](repeating: 0, count: cluster_code)
|
||||
var lon_centre = [Double](repeating: 0, count: cluster_code)
|
||||
var cluster_freq = [Int](repeating: 0, count: cluster_code)
|
||||
var cluster_intensity = [Double](repeating: 0, count: cluster_code)
|
||||
|
||||
for k in 0..<cluster_code {
|
||||
lat_centre[k] = 0
|
||||
lon_centre[k] = 0
|
||||
cluster_freq[k] = 0
|
||||
cluster_intensity[k] = 0
|
||||
for i in 0..<vector_latitude.count {
|
||||
if vector_cluster[i] == k+1 {
|
||||
lat_centre[k] = lat_centre[k] + vector_latitude[i]
|
||||
lon_centre[k] = lon_centre[k] + vector_longitude[i]
|
||||
cluster_freq[k] = cluster_freq[k] + 1
|
||||
cluster_intensity[k] = cluster_intensity[k] + Double(vector_state[i])
|
||||
}
|
||||
}
|
||||
if cluster_freq[k] > 0 {
|
||||
lat_centre[k] = lat_centre[k]/Double(cluster_freq[k])
|
||||
lon_centre[k] = lon_centre[k]/Double(cluster_freq[k])
|
||||
cluster_intensity[k] = cluster_intensity[k]/Double(cluster_freq[k])
|
||||
}
|
||||
}
|
||||
|
||||
var lat_farest = [Double](repeating: 0, count: cluster_code)
|
||||
var lon_farest = [Double](repeating: 0, count: cluster_code)
|
||||
var max_distance = [Double](repeating: 0, count: cluster_code)
|
||||
//per ogni cluster calcola il punto più lontano dal centro
|
||||
for k in 0..<cluster_code {
|
||||
max_distance[k] = 0
|
||||
for i in 0..<vector_latitude.count {
|
||||
if vector_cluster[i] == k+1 {
|
||||
let distance = abs(lat_centre[k] - vector_latitude[i]) + abs(lon_centre[k] - vector_longitude[i])
|
||||
if distance >= max_distance[k] {
|
||||
lat_farest[k] = vector_latitude[i]
|
||||
lon_farest[k] = vector_longitude[i]
|
||||
max_distance[k] = distance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let circles = Array(0..<cluster_code).map { (i) -> MapCircle in
|
||||
var value_distance = max_distance[i] / 20.0
|
||||
if value_distance > 1.0 {
|
||||
value_distance = 1.0
|
||||
}
|
||||
let value_intensity = (cluster_intensity[i]-1.0) / 2.0
|
||||
let value_reference = max(value_distance, value_intensity)
|
||||
|
||||
let color: UIColor
|
||||
if value_reference <= 0.5 {
|
||||
let red = round(value_reference * 510)
|
||||
color = UIColor(red: CGFloat(red / 255.0), green: 230.0/255.0, blue: 0.0, alpha: 1.0)
|
||||
} else {
|
||||
let green = round(230 - (value_reference - 0.5) * 460)
|
||||
color = UIColor(red: 255.0, green: CGFloat(green / 255.0), blue: 0.0, alpha: 1.0)
|
||||
}
|
||||
|
||||
let centre = CLLocation(latitude: lat_centre[i], longitude: lon_centre[i])
|
||||
let farest = CLLocation(latitude: lat_farest[i], longitude: lon_farest[i])
|
||||
let radius: CLLocationDistance = centre.distance(from: farest) + 4000
|
||||
|
||||
let circle = MKCircle(center: centre.coordinate, radius: radius)
|
||||
return MapCircle(color: color, circle: circle)
|
||||
}
|
||||
return circles
|
||||
}
|
||||
|
||||
private func addMapCircles(_ circles: [MapCircle]) {
|
||||
// elimino vecchie circonferenze
|
||||
let previousCircles = mapCircles.map { $0.circle }
|
||||
mapView.removeOverlays(previousCircles)
|
||||
|
||||
// !!note: is important to assign here the circles
|
||||
// otherwise `addOverlays` will not work
|
||||
mapCircles = circles
|
||||
|
||||
// creo nuovi cerchi
|
||||
let overlays = circles.map { $0.circle }
|
||||
mapView.addOverlays(overlays)
|
||||
}
|
||||
|
||||
private func getDeltaMinute(_ date: Date) -> TimeInterval {
|
||||
Date().timeIntervalSince(date) / 60.0
|
||||
}
|
||||
|
||||
// MARK: - Map
|
||||
|
||||
override func setupAnnotationView(for annotation: MKAnnotation, on mapView: MKMapView) -> MKAnnotationView? {
|
||||
guard let annotation = annotation as? EQNMapAnnotationUserReport else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: EQNCustomAnnotationView.Identifier, for: annotation) as! EQNCustomAnnotationView
|
||||
|
||||
annotationView.image = annotation.image
|
||||
annotationView.title = annotation.title
|
||||
|
||||
return annotationView
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
|
||||
if let overlay = overlay as? MKCircle, let mapCircle = mapCircles.first(where: { $0.circle == overlay }) {
|
||||
let circle = MKCircleRenderer(overlay: overlay)
|
||||
circle.strokeColor = mapCircle.color
|
||||
circle.fillColor = mapCircle.color.withAlphaComponent(0.1)
|
||||
circle.lineWidth = 2.0
|
||||
return circle
|
||||
}
|
||||
|
||||
return MKOverlayRenderer(overlay: overlay)
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
@implementation SegnalazioniViewController
|
||||
|
||||
static NSString * const SegueIdentifierMap = @"ShowMap";
|
||||
|
||||
#pragma mark - View Lifecycle
|
||||
|
||||
- (void)viewDidLoad
|
||||
@@ -124,7 +122,8 @@ static NSString * const SegueIdentifierMap = @"ShowMap";
|
||||
|
||||
- (IBAction)openMapTapped:(id)sender
|
||||
{
|
||||
[self performSegueWithIdentifier:SegueIdentifierMap sender:nil];
|
||||
SegnalazioniMapViewController *controller = [[SegnalazioniMapViewController alloc] init];
|
||||
[self presentViewController:controller animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (IBAction)openTwitterTapped:(id)sender
|
||||
|
||||
@@ -22,4 +22,18 @@ extension EQNFiltroMappa {
|
||||
case .unAnno: return NSLocalizedString("Ultimo anno", comment: "")
|
||||
}
|
||||
}
|
||||
|
||||
var minutes: TimeInterval {
|
||||
switch self {
|
||||
case .dieciMinuti: return 10
|
||||
case .unOra: return 60
|
||||
case .dueOre: return 120
|
||||
case .seiOre: return 360
|
||||
case .dodiciOre: return 720
|
||||
case .unGiorno: return 1440
|
||||
case .unaSettimana: return 10080
|
||||
case .unMese: return 44640
|
||||
case .unAnno: return 525600
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#import "EQNUser.h"
|
||||
#import "EQNManager.h"
|
||||
#import "EQNNotificheReteSismiche.h"
|
||||
#import "EQNNotificheSegnalazioniUtente.h"
|
||||
#import "EQNSisma.h"
|
||||
#import "EQNBaseViewController.h"
|
||||
#import "SettingsBaseViewController.h"
|
||||
|
||||
@@ -34,4 +34,19 @@ extension EQNUtility {
|
||||
longSeconds,
|
||||
longDegrees >= 0 ? "E" : "W" )
|
||||
}
|
||||
|
||||
@objc
|
||||
class func formattedTimeDifference(from: Date, to: Date = Date()) -> String {
|
||||
let diffComponents = Calendar.current.dateComponents([.day, .hour, .minute], from: from, to: to)
|
||||
let days = diffComponents.day ?? 0
|
||||
let hours = diffComponents.hour ?? 0
|
||||
let minutes = diffComponents.minute ?? 0
|
||||
|
||||
if days > 0 {
|
||||
return "\(days)d"
|
||||
} else if hours > 0 {
|
||||
return "\(hours)h"
|
||||
}
|
||||
return "\(minutes)m"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
|
||||
@class EQNGenericValue;
|
||||
@class EQNSegnalazione;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -32,6 +33,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
/// @param list Annotations
|
||||
+ (NSArray *)applicaFiltroWithTime:(EQNFiltroMappa)filtro withList:(NSArray *)list;
|
||||
|
||||
/// Apply a map filter to a given set of `segnalazioni`
|
||||
/// This is a replacement of `applicaFiltroWithTime:withList:` to better use with Swift
|
||||
/// @param segnalazioni Segnalazioni
|
||||
/// @param filter Map filter
|
||||
+ (NSArray<EQNSegnalazione *> *)filterSegnalazioni:(NSArray<EQNSegnalazione *> *)segnalazioni forFilter:(EQNFiltroMappa)filter;
|
||||
|
||||
/// Clear a given string from unwanted characters
|
||||
/// @param messaggio Cleaned string
|
||||
+ (NSString *)clearStringMessaggi:(NSString *)messaggio;
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
return [NSString stringWithFormat:format, (long)finalValue];
|
||||
}
|
||||
|
||||
+ (NSArray *)applicaFiltroWithTime:(EQNFiltroMappa )filtro withList:(NSArray *)list
|
||||
+ (NSArray *)applicaFiltroWithTime:(EQNFiltroMappa)filtro withList:(NSArray *)list
|
||||
{
|
||||
NSDate *date = [self impostaFiltroWithTime:filtro];
|
||||
NSMutableArray *temp = [NSMutableArray array];
|
||||
@@ -58,25 +58,33 @@
|
||||
EQNPastquakes *anPasq = (EQNPastquakes *)object;
|
||||
if ([anPasq.date compare:date] == NSOrderedDescending) {
|
||||
[temp addObject:anPasq];
|
||||
NSLog(@"\n\naggiunto %@ filtro %@", anPasq.date, date);
|
||||
} else {
|
||||
NSLog(@"\n\nNon aggiunto %@ filtro %@", anPasq.date, date);
|
||||
}
|
||||
} else if ([object isKindOfClass:[EQNSegnalazione class]]){
|
||||
EQNSegnalazione *anSegn = (EQNSegnalazione *)object;
|
||||
if ([anSegn.date compare:date] == NSOrderedDescending) {
|
||||
[temp addObject:anSegn];
|
||||
NSLog(@"\n\naggiunto %@ filtro %@", anSegn.date, date);
|
||||
} else {
|
||||
NSLog(@"\n\nNon aggiunto %@ filtro %@", anSegn.date, date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"filtrati %lu tutti %lu", (unsigned long)temp.count, (unsigned long)list.count);
|
||||
return temp;
|
||||
}
|
||||
|
||||
+ (NSArray *)filterSegnalazioni:(NSArray<EQNSegnalazione *> *)segnalazioni forFilter:(EQNFiltroMappa)filter
|
||||
{
|
||||
NSDate *date = [self impostaFiltroWithTime:filter];
|
||||
NSMutableArray *filtered = [NSMutableArray array];
|
||||
|
||||
for (EQNSegnalazione *segnalazione in segnalazioni) {
|
||||
if ([segnalazione.date compare:date] == NSOrderedDescending) {
|
||||
[filtered addObject:segnalazione];
|
||||
}
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
|
||||
+ (NSDate *)impostaFiltroWithTime:(EQNFiltroMappa)filtro
|
||||
{
|
||||
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// EQNMapAnnotationUserReport.swift
|
||||
// Earthquake Network
|
||||
//
|
||||
// Created by Andrea Busi on 06/03/21.
|
||||
// Copyright © 2021 Earthquake Network. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
class EQNMapAnnotationUserReport: NSObject, MKAnnotation {
|
||||
|
||||
var coordinate: CLLocationCoordinate2D
|
||||
|
||||
private let magnitute: Int
|
||||
private let date: Date
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
init(report: EQNSegnalazione) {
|
||||
self.coordinate = CLLocationCoordinate2D(latitude: report.coordinate.coordinate.latitude, longitude: report.coordinate.coordinate.longitude)
|
||||
self.magnitute = report.magnitude
|
||||
self.date = report.date
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
var image: UIImage? {
|
||||
switch magnitute {
|
||||
case 1: return UIImage(named: "star_report_green")
|
||||
case 2: return UIImage(named: "star_report_yellow")
|
||||
case 3: return UIImage(named: "star_report_red")
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
|
||||
var title: String? {
|
||||
EQNUtility.formattedTimeDifference(from: date)
|
||||
}
|
||||
}
|
||||
@@ -675,7 +675,6 @@ In più sostieni il progetto di ricerca il quale non riceve finanziamenti estern
|
||||
<outlet property="bannerContainerHeightConstraint" destination="1Dm-ex-6od" id="K81-pR-aXU"/>
|
||||
<outlet property="bannerContainerView" destination="4mK-no-RDk" id="Q7n-hX-Bsv"/>
|
||||
<outlet property="tableView" destination="jl5-sK-UaA" id="ac3-YT-Eil"/>
|
||||
<segue destination="f29-jx-Bqf" kind="presentation" identifier="ShowMap" id="YRm-jy-fZO"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="SFa-PG-ACD" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
@@ -1314,111 +1313,6 @@ In più sostieni il progetto di ricerca il quale non riceve finanziamenti estern
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-4414.4927536231889" y="-7440.4017857142853"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="pK6-is-2fg">
|
||||
<objects>
|
||||
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="f29-jx-Bqf" sceneMemberID="viewController">
|
||||
<toolbarItems/>
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="cBi-pY-k1K">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="56"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
<nil name="viewControllers"/>
|
||||
<connections>
|
||||
<segue destination="pNh-Ni-Yv5" kind="relationship" relationship="rootViewController" id="j3K-QE-2O7"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="uJU-qY-Flz" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-6887" y="-6364"/>
|
||||
</scene>
|
||||
<!--Segnalazioni Utente Dettagli Mappa-->
|
||||
<scene sceneID="sxh-Vw-hzi">
|
||||
<objects>
|
||||
<viewController id="pNh-Ni-Yv5" customClass="SegnalazioniUtenteDettagliMappa" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="KVE-FS-ApD">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="iko-a1-LWv">
|
||||
<rect key="frame" x="0.0" y="56" width="414" height="647"/>
|
||||
</mapView>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="CTZ-OY-cgW">
|
||||
<rect key="frame" x="0.0" y="703" width="414" height="55"/>
|
||||
<connections>
|
||||
<action selector="visualizzaPikerFiltro:" destination="pNh-Ni-Yv5" eventType="touchUpInside" id="eoW-3k-k9E"/>
|
||||
</connections>
|
||||
</button>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kCt-Dd-MaY">
|
||||
<rect key="frame" x="0.0" y="758" width="414" height="50"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="50" id="ljc-h5-JHC"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8TU-C5-fRW">
|
||||
<rect key="frame" x="0.0" y="703" width="414" height="55"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sx2-Xi-NrV">
|
||||
<rect key="frame" x="15" y="0.0" width="344" height="55"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_arrow_drop_down_48px-128" translatesAutoresizingMaskIntoConstraints="NO" id="pv8-Xy-9z0">
|
||||
<rect key="frame" x="359" y="0.0" width="55" height="55"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="55" id="gT5-qw-bCr"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="55" id="3s0-7U-bQj"/>
|
||||
<constraint firstItem="pv8-Xy-9z0" firstAttribute="leading" secondItem="Sx2-Xi-NrV" secondAttribute="trailing" id="Ba8-Rj-cIS"/>
|
||||
<constraint firstAttribute="bottom" secondItem="Sx2-Xi-NrV" secondAttribute="bottom" id="H0f-c4-IVt"/>
|
||||
<constraint firstItem="Sx2-Xi-NrV" firstAttribute="leading" secondItem="8TU-C5-fRW" secondAttribute="leading" constant="15" id="HOa-2v-KDD"/>
|
||||
<constraint firstAttribute="bottom" secondItem="pv8-Xy-9z0" secondAttribute="bottom" id="Zse-cX-dcV"/>
|
||||
<constraint firstAttribute="trailing" secondItem="pv8-Xy-9z0" secondAttribute="trailing" id="kjJ-Jx-Ioi"/>
|
||||
<constraint firstItem="Sx2-Xi-NrV" firstAttribute="top" secondItem="8TU-C5-fRW" secondAttribute="top" id="tKe-p2-O3p"/>
|
||||
<constraint firstItem="pv8-Xy-9z0" firstAttribute="top" secondItem="8TU-C5-fRW" secondAttribute="top" id="wYT-x6-A1N"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<viewLayoutGuide key="safeArea" id="fDH-pM-Eay"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="8TU-C5-fRW" firstAttribute="trailing" secondItem="fDH-pM-Eay" secondAttribute="trailing" id="1L6-2l-kr2"/>
|
||||
<constraint firstItem="iko-a1-LWv" firstAttribute="top" secondItem="fDH-pM-Eay" secondAttribute="top" id="FCZ-a9-IpJ"/>
|
||||
<constraint firstItem="CTZ-OY-cgW" firstAttribute="width" secondItem="8TU-C5-fRW" secondAttribute="width" id="Haq-uM-Pk9"/>
|
||||
<constraint firstItem="8TU-C5-fRW" firstAttribute="leading" secondItem="fDH-pM-Eay" secondAttribute="leading" id="NXE-Lw-aXn"/>
|
||||
<constraint firstItem="kCt-Dd-MaY" firstAttribute="top" secondItem="8TU-C5-fRW" secondAttribute="bottom" id="d1j-xi-Kvc"/>
|
||||
<constraint firstItem="kCt-Dd-MaY" firstAttribute="trailing" secondItem="fDH-pM-Eay" secondAttribute="trailing" id="fle-IU-Uqv"/>
|
||||
<constraint firstItem="CTZ-OY-cgW" firstAttribute="centerX" secondItem="8TU-C5-fRW" secondAttribute="centerX" id="fuC-ta-9tn"/>
|
||||
<constraint firstItem="8TU-C5-fRW" firstAttribute="top" secondItem="iko-a1-LWv" secondAttribute="bottom" id="iDZ-TX-1dv"/>
|
||||
<constraint firstItem="iko-a1-LWv" firstAttribute="leading" secondItem="fDH-pM-Eay" secondAttribute="leading" id="n2e-k3-tjm"/>
|
||||
<constraint firstItem="kCt-Dd-MaY" firstAttribute="leading" secondItem="fDH-pM-Eay" secondAttribute="leading" id="ors-Mh-Crn"/>
|
||||
<constraint firstItem="CTZ-OY-cgW" firstAttribute="centerY" secondItem="8TU-C5-fRW" secondAttribute="centerY" id="qNd-8j-uYC"/>
|
||||
<constraint firstItem="iko-a1-LWv" firstAttribute="trailing" secondItem="fDH-pM-Eay" secondAttribute="trailing" id="rTW-4m-9My"/>
|
||||
<constraint firstItem="CTZ-OY-cgW" firstAttribute="height" secondItem="8TU-C5-fRW" secondAttribute="height" id="vkj-Xb-NpT"/>
|
||||
<constraint firstItem="kCt-Dd-MaY" firstAttribute="bottom" secondItem="fDH-pM-Eay" secondAttribute="bottom" id="wSn-ss-ZAz"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<navigationItem key="navigationItem" id="aQo-9D-Bwb"/>
|
||||
<connections>
|
||||
<outlet property="bannerContainerHeightConstraint" destination="ljc-h5-JHC" id="5OR-fA-Hrx"/>
|
||||
<outlet property="bannerContainerView" destination="kCt-Dd-MaY" id="BVk-Cz-RfM"/>
|
||||
<outlet property="buttonAzione" destination="CTZ-OY-cgW" id="dG4-M5-PPF"/>
|
||||
<outlet property="containerView" destination="8TU-C5-fRW" id="d4g-SV-NI6"/>
|
||||
<outlet property="imageAzione" destination="pv8-Xy-9z0" id="pLN-TH-GdZ"/>
|
||||
<outlet property="labelAzione" destination="Sx2-Xi-NrV" id="9Eb-Fj-U8L"/>
|
||||
<outlet property="mapView" destination="iko-a1-LWv" id="z1H-ui-HrZ"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="rgA-5b-IRk" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-6178.2608695652179" y="-6364.2857142857138"/>
|
||||
</scene>
|
||||
<!--Log View Controller-->
|
||||
<scene sceneID="bCB-QP-zCq">
|
||||
<objects>
|
||||
@@ -2077,13 +1971,13 @@ Sisma rilevato da 10 smartphone</string>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" alignment="center" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="0lY-aw-fec">
|
||||
<rect key="frame" x="11.5" y="0.0" width="106.5" height="25"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Last 24h:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hbH-vC-Yma">
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Last 24h:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hbH-vC-Yma">
|
||||
<rect key="frame" x="0.0" y="0.0" width="89" height="25"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="22"/>
|
||||
<color key="textColor" name="Gray (dark)"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="0" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BRv-IS-2fA">
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BRv-IS-2fA">
|
||||
<rect key="frame" x="93" y="0.0" width="13.5" height="25"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="22"/>
|
||||
<color key="textColor" name="Gray (dark)"/>
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
//
|
||||
// SegnalazioniUtenteDettagliMappa.h
|
||||
// Earthquake Network
|
||||
//
|
||||
// Created by Luca Beretta on 07/11/18.
|
||||
// Copyright © 2018 Luca Beretta. All rights reserved.
|
||||
//
|
||||
|
||||
#import "DettagliMappaViewController.h"
|
||||
|
||||
@interface SegnalazioniUtenteDettagliMappa : DettagliMappaViewController
|
||||
|
||||
@end
|
||||
-150
@@ -1,150 +0,0 @@
|
||||
//
|
||||
// SegnalazioniUtenteDettagliMappa.m
|
||||
// Earthquake Network
|
||||
//
|
||||
// Created by Luca Beretta on 07/11/18.
|
||||
// Copyright © 2018 Luca Beretta. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SegnalazioniUtenteDettagliMappa.h"
|
||||
#import "EQNMapAnnotationSeismicNetwork.h"
|
||||
|
||||
@interface SegnalazioniUtenteDettagliMappa ()
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *annotationArray;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SegnalazioniUtenteDettagliMappa
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[super awakeFromNib];
|
||||
|
||||
self.filtroArray = @[NSLocalizedString(@"Un giorno", @""),
|
||||
NSLocalizedString(@"Dodici ore", @""),
|
||||
NSLocalizedString(@"Sei ore", @""),
|
||||
NSLocalizedString(@"Due ore", @""),
|
||||
NSLocalizedString(@"Un ora", @""),
|
||||
NSLocalizedString(@"Dieci minuti", @"")];
|
||||
}
|
||||
|
||||
#pragma mark - View Lifecycle
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"]
|
||||
style:UIBarButtonItemStyleDone
|
||||
target:self
|
||||
action:@selector(chiudi:)];
|
||||
self.mapView.delegate = self;
|
||||
|
||||
[self.buttonAzione addTarget:self action:@selector(visualizzaPikerFiltro:) forControlEvents:UIControlEventTouchDown];
|
||||
[self applicaFiltroWithTime:@(0)];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)creaMarcherWithSegnalazione:(id)segnalazione
|
||||
{
|
||||
|
||||
[super creaMarcherWithSegnalazione:segnalazione];
|
||||
|
||||
if(!self.annotationArray)
|
||||
self.annotationArray = [NSMutableArray array];
|
||||
|
||||
EQNSegnalazione *anSegnalazione = (EQNSegnalazione *)segnalazione;
|
||||
|
||||
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(anSegnalazione.coordinate.coordinate.latitude, anSegnalazione.coordinate.coordinate.longitude);
|
||||
EQNMapAnnotationSeismicNetwork *anAnnotation = [[EQNMapAnnotationSeismicNetwork alloc] initWithTitle:anSegnalazione.address location:location magnitudo:anSegnalazione.magnitude];
|
||||
[self.annotationArray addObject:anAnnotation];
|
||||
|
||||
}
|
||||
|
||||
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
|
||||
{
|
||||
if ([annotation isKindOfClass:[EQNMapAnnotationSeismicNetwork class]]) {
|
||||
EQNMapAnnotationSeismicNetwork *anLocation = (EQNMapAnnotationSeismicNetwork *)annotation;
|
||||
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:EQNMapAnnotationSeismicNetworkIdentifier];
|
||||
if (annotationView == nil)
|
||||
annotationView = anLocation.annotationView;
|
||||
else
|
||||
annotationView.annotation = anLocation;
|
||||
|
||||
return annotationView;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)applicaFiltroWithTime:(NSNumber *)time
|
||||
{
|
||||
|
||||
EQNFiltroMappa filtro = EQNFiltroMappaUnGiorno;
|
||||
switch ([time intValue]) {
|
||||
case 0:
|
||||
filtro = EQNFiltroMappaUnGiorno;
|
||||
break;
|
||||
case 1:
|
||||
filtro = EQNFiltroMappaDodiciOre;
|
||||
break;
|
||||
case 2:
|
||||
filtro = EQNFiltroMappaSeiOre;
|
||||
break;
|
||||
case 3:
|
||||
filtro = EQNFiltroMappaDueOre;
|
||||
break;
|
||||
case 4:
|
||||
filtro = EQNFiltroMappaUnOra;
|
||||
break;
|
||||
case 5:
|
||||
filtro = EQNFiltroMappaDieciMinuti;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
NSArray *lista = [EQNUtility applicaFiltroWithTime:filtro withList:[EQNManager defaultManager].elencoSelagnazioniManuali];
|
||||
|
||||
|
||||
[self.annotationArray removeAllObjects];
|
||||
|
||||
for (EQNSegnalazione *seg in lista)
|
||||
[self creaMarcherWithSegnalazione:seg];
|
||||
|
||||
[self.mapView addAnnotations:self.annotationArray];
|
||||
[self.mapView showAnnotations:self.annotationArray animated:YES];
|
||||
self.labelAzione.text = self.filtroArray[[time intValue]];
|
||||
|
||||
if (lista.count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSSortDescriptor *dateDescriptor = [NSSortDescriptor
|
||||
sortDescriptorWithKey:@"date"
|
||||
ascending:YES];
|
||||
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
|
||||
NSArray *sortedEventArray = [lista
|
||||
sortedArrayUsingDescriptors:sortDescriptors];
|
||||
|
||||
for (EQNSegnalazione *seg in sortedEventArray) {
|
||||
|
||||
NSLog(@"seg data %@", seg.date);
|
||||
}
|
||||
|
||||
|
||||
EQNSegnalazione *segnalazione = sortedEventArray[0];
|
||||
CLLocation *coordinate = [[CLLocation alloc] initWithLatitude:segnalazione.coordinate.coordinate.latitude longitude:segnalazione.coordinate.coordinate.longitude];
|
||||
MKCoordinateSpan span = MKCoordinateSpanMake(10.5, 10.5);
|
||||
MKCoordinateRegion region = MKCoordinateRegionMake(coordinate.coordinate, span);
|
||||
self.mapView.delegate = self;
|
||||
[self.mapView setCenterCoordinate:coordinate.coordinate animated:NO];
|
||||
[self.mapView setRegion:region animated:YES];
|
||||
|
||||
[self.buttonAzione addTarget:self action:@selector(visualizzaPikerFiltro:) forControlEvents:UIControlEventTouchDown];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user