Map with global events
This commit is contained in:
parent
f6d13af17e
commit
e4085ee665
@ -96,6 +96,8 @@
|
||||
7ADF6C97250F41B000F237B2 /* PNKeyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C96250F41B000F237B2 /* PNKeyboard.swift */; };
|
||||
7ADF6C99250F872C00F237B2 /* RoadNumbers.otf in Resources */ = {isa = PBXBuildFile; fileRef = 7ADF6C98250F872C00F237B2 /* RoadNumbers.otf */; };
|
||||
7ADF6C9D250FA96000F237B2 /* SwiftMaskTextfield.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C9C250FA96000F237B2 /* SwiftMaskTextfield.swift */; };
|
||||
7ADF6C9F251201D200F237B2 /* GlobalEventsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6C9E251201D200F237B2 /* GlobalEventsController.swift */; };
|
||||
7ADF6CA12512244400F237B2 /* MapExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ADF6CA02512244400F237B2 /* MapExt.swift */; };
|
||||
7AE26A3324EEF9EC00625033 /* UIViewControllerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */; };
|
||||
7AE26A3524F31B0700625033 /* EventsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3424F31B0700625033 /* EventsController.swift */; };
|
||||
7AEFE728240455E200910EB7 /* SettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AEFE727240455E200910EB7 /* SettingsController.swift */; };
|
||||
@ -188,6 +190,8 @@
|
||||
7ADF6C96250F41B000F237B2 /* PNKeyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PNKeyboard.swift; sourceTree = "<group>"; };
|
||||
7ADF6C98250F872C00F237B2 /* RoadNumbers.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = RoadNumbers.otf; sourceTree = "<group>"; };
|
||||
7ADF6C9C250FA96000F237B2 /* SwiftMaskTextfield.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftMaskTextfield.swift; sourceTree = "<group>"; };
|
||||
7ADF6C9E251201D200F237B2 /* GlobalEventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalEventsController.swift; sourceTree = "<group>"; };
|
||||
7ADF6CA02512244400F237B2 /* MapExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapExt.swift; sourceTree = "<group>"; };
|
||||
7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExt.swift; sourceTree = "<group>"; };
|
||||
7AE26A3424F31B0700625033 /* EventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsController.swift; sourceTree = "<group>"; };
|
||||
7AEFE727240455E200910EB7 /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = "<group>"; };
|
||||
@ -347,6 +351,7 @@
|
||||
7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */,
|
||||
7A21112924FC3D7E003BBF6F /* AudioEngine.swift */,
|
||||
7ADF6C92250B954900F237B2 /* Navigation.swift */,
|
||||
7ADF6CA02512244400F237B2 /* MapExt.swift */,
|
||||
);
|
||||
path = Extensions;
|
||||
sourceTree = "<group>";
|
||||
@ -431,6 +436,7 @@
|
||||
7A813DC8250B5C9700CC93B9 /* LocationRow.swift */,
|
||||
7A813DCA250B5DC900CC93B9 /* LocationPickerController.swift */,
|
||||
7ADF6C94250D037700F237B2 /* ShowEventController.swift */,
|
||||
7ADF6C9E251201D200F237B2 /* GlobalEventsController.swift */,
|
||||
);
|
||||
path = Location;
|
||||
sourceTree = "<group>";
|
||||
@ -560,6 +566,7 @@
|
||||
7A27ADF3249F8B650035F39E /* RecordsController.swift in Sources */,
|
||||
7A8A2209248D10EC0073DFD9 /* ResizeImage.swift in Sources */,
|
||||
7A6DD90E24337930009DE740 /* PlateNumber.swift in Sources */,
|
||||
7ADF6CA12512244400F237B2 /* MapExt.swift in Sources */,
|
||||
7A659B5B24A3768A0043A0F2 /* Substrings.swift in Sources */,
|
||||
7AEFE728240455E200910EB7 /* SettingsController.swift in Sources */,
|
||||
7A27ADF7249FEF690035F39E /* Recorder.swift in Sources */,
|
||||
@ -587,6 +594,7 @@
|
||||
7A813DC5250AAF3C00CC93B9 /* LocationEditController.swift in Sources */,
|
||||
7A43F9F8246C8A6200BA5B49 /* JWT.swift in Sources */,
|
||||
7A6DD903242BF4A5009DE740 /* PlateView.swift in Sources */,
|
||||
7ADF6C9F251201D200F237B2 /* GlobalEventsController.swift in Sources */,
|
||||
7A488C3F24A74B990054D0B2 /* RealmBindObserver.swift in Sources */,
|
||||
7AAE6AD324CDDF950023860B /* VehicleEvent.swift in Sources */,
|
||||
7A11470323FDE7E500B424AF /* SceneDelegate.swift in Sources */,
|
||||
@ -755,7 +763,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 32;
|
||||
CURRENT_PROJECT_VERSION = 34;
|
||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
@ -777,7 +785,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 32;
|
||||
CURRENT_PROJECT_VERSION = 34;
|
||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
|
||||
@ -47,22 +47,6 @@
|
||||
</Locations>
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "339C709C-134A-4B97-9F9C-949886D4AD65"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "AutoCat/Controllers/SearchController.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "94"
|
||||
endingLineNumber = "94"
|
||||
landmarkName = "onFilter(_:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
@ -79,5 +63,21 @@
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "6FAE6E70-6839-4B41-B519-961651A97BE2"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "AutoCat/Utils/Api.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "228"
|
||||
endingLineNumber = "228"
|
||||
landmarkName = "add(event:to:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
@ -328,14 +328,14 @@
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="VehicleCell" id="VEP-QD-i6y" customClass="VehicleCell" customModule="AutoCat" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="28" width="375" height="85.5"/>
|
||||
<rect key="frame" x="0.0" y="28" width="375" height="85"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="VEP-QD-i6y" id="8hH-8I-XLB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="85.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="85"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Kia (JF) Optima" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AQY-7N-q8D">
|
||||
<rect key="frame" x="8" y="8" width="124" height="21.5"/>
|
||||
<rect key="frame" x="8" y="8" width="124" height="21"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
@ -347,7 +347,7 @@
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cvf-vM-QnT" customClass="PlateView" customModule="AutoCat" customModuleProvider="target">
|
||||
<rect key="frame" x="8" y="37.5" width="317" height="40"/>
|
||||
<rect key="frame" x="8" y="37" width="317" height="40"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="40" id="Xoz-Iw-PCU"/>
|
||||
@ -387,13 +387,21 @@
|
||||
</view>
|
||||
<navigationItem key="navigationItem" id="kEp-Rw-7hu">
|
||||
<barButtonItem key="backBarButtonItem" title="Back" id="7QQ-Qi-qEw"/>
|
||||
<barButtonItem key="rightBarButtonItem" image="line.horizontal.3.decrease" catalog="system" id="mvq-Q5-tVc">
|
||||
<connections>
|
||||
<action selector="onFilter:" destination="UPf-uT-oOr" id="z2g-n9-tJ0"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<rightBarButtonItems>
|
||||
<barButtonItem image="line.horizontal.3.decrease" catalog="system" id="mvq-Q5-tVc">
|
||||
<connections>
|
||||
<action selector="onFilter:" destination="UPf-uT-oOr" id="z2g-n9-tJ0"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<barButtonItem image="map" catalog="system" id="iVh-uQ-fX5">
|
||||
<connections>
|
||||
<action selector="showOnMap:" destination="UPf-uT-oOr" id="PYv-B4-dqB"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
</rightBarButtonItems>
|
||||
</navigationItem>
|
||||
<connections>
|
||||
<outlet property="showMapButton" destination="iVh-uQ-fX5" id="19X-3N-bDb"/>
|
||||
<outlet property="tableView" destination="dB3-iP-QRo" id="b3n-R9-6lI"/>
|
||||
<segue destination="xtc-Md-WHl" kind="show" id="XGo-Dt-MEf"/>
|
||||
</connections>
|
||||
@ -762,7 +770,6 @@
|
||||
<segue destination="RK6-pn-2Bg" kind="relationship" relationship="viewControllers" id="KNz-WF-Kyy"/>
|
||||
<segue destination="GCa-Re-j14" kind="relationship" relationship="viewControllers" id="FGp-f6-fUh"/>
|
||||
<segue destination="4jU-Z3-PF2" kind="relationship" relationship="viewControllers" id="aH2-IT-86l"/>
|
||||
<segue destination="5k8-Cz-8yP" kind="relationship" relationship="viewControllers" id="w22-e0-uc5"/>
|
||||
</connections>
|
||||
</tabBarController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="AJs-8F-Qbu" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
@ -888,10 +895,10 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="199" y="143"/>
|
||||
</scene>
|
||||
<!--View Controller-->
|
||||
<!--Title-->
|
||||
<scene sceneID="akP-Pw-M4Q">
|
||||
<objects>
|
||||
<viewController id="nFZ-L6-cSY" sceneMemberID="viewController">
|
||||
<viewController storyboardIdentifier="GlobalEventsController" hidesBottomBarWhenPushed="YES" id="nFZ-L6-cSY" customClass="GlobalEventsController" customModule="AutoCat" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="qu5-Ue-dlv">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
@ -909,11 +916,22 @@
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="gve-eU-fKS"/>
|
||||
</view>
|
||||
<navigationItem key="navigationItem" id="jf2-Du-fcn"/>
|
||||
<toolbarItems/>
|
||||
<navigationItem key="navigationItem" title="Title" id="f2h-mm-Zd0">
|
||||
<barButtonItem key="rightBarButtonItem" title="Close" id="hCi-F4-z7b">
|
||||
<connections>
|
||||
<action selector="close:" destination="nFZ-L6-cSY" id="to7-KD-Vec"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
</navigationItem>
|
||||
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
|
||||
<connections>
|
||||
<outlet property="map" destination="q5m-0R-HGC" id="ufy-Qx-9G1"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="XB6-0a-b8N" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="4200.8000000000002" y="-1374.0629685157423"/>
|
||||
<point key="canvasLocation" x="7518" y="144"/>
|
||||
</scene>
|
||||
<!--Check-->
|
||||
<scene sceneID="pUX-kf-oY1">
|
||||
@ -990,24 +1008,23 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="3261.5999999999999" y="1660.1199400299852"/>
|
||||
</scene>
|
||||
<!--Map-->
|
||||
<scene sceneID="XqL-ef-b4J">
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="fRx-9f-ao6">
|
||||
<objects>
|
||||
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="5k8-Cz-8yP" sceneMemberID="viewController">
|
||||
<tabBarItem key="tabBarItem" title="Map" image="map" catalog="system" id="emU-RO-5HQ"/>
|
||||
<navigationController storyboardIdentifier="GlobalEventsNavigation" automaticallyAdjustsScrollViewInsets="NO" id="HWa-Ea-ZKD" sceneMemberID="viewController">
|
||||
<toolbarItems/>
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="0UP-PJ-Rc3">
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="REm-5j-xeL">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
<nil name="viewControllers"/>
|
||||
<connections>
|
||||
<segue destination="nFZ-L6-cSY" kind="relationship" relationship="rootViewController" id="iQf-3h-ziw"/>
|
||||
<segue destination="nFZ-L6-cSY" kind="relationship" relationship="rootViewController" id="qjn-Wc-HGC"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="THp-Fz-ftx" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="Zbo-fQ-UCM" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="3261.5999999999999" y="-1374.0629685157423"/>
|
||||
<point key="canvasLocation" x="6577" y="143"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
|
||||
@ -178,7 +178,9 @@ class CheckController: UIViewController, UITableViewDelegate, UITextFieldDelegat
|
||||
}
|
||||
eventSingle
|
||||
.flatMap { event in event.findAddress().map{ event }.catchErrorJustReturn(event) }
|
||||
.flatMap { Api.add(event: $0, to: vehicle.number) }
|
||||
.flatMap {
|
||||
Api.add(event: $0, to: vehicle.number)
|
||||
}
|
||||
.subscribe(onSuccess: self.save(vehicle:), onError: { print("Error adding event: \($0)") })
|
||||
.disposed(by: self.bag)
|
||||
}
|
||||
|
||||
@ -17,13 +17,18 @@ class EventPin: NSObject, MKAnnotation {
|
||||
|
||||
convenience init(event: VehicleEvent) {
|
||||
let coordinate = CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude)
|
||||
let subtitle = event.address ?? "\(event.latitude), \(event.longitude)"
|
||||
let address = event.address ?? "\(event.latitude), \(event.longitude)"
|
||||
let date = Date(timeIntervalSince1970: event.date)
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .short
|
||||
let title = formatter.string(from: date)
|
||||
self.init(coordinate: coordinate, title: title, subtitle: subtitle)
|
||||
let dateStr = formatter.string(from: date)
|
||||
|
||||
if let number = event.number {
|
||||
self.init(coordinate: coordinate, title: number, subtitle: dateStr)
|
||||
} else {
|
||||
self.init(coordinate: coordinate, title: dateStr, subtitle: address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,33 +80,10 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele
|
||||
func updateInterface() {
|
||||
self.map.removeAnnotations(self.map.annotations)
|
||||
self.map.addAnnotations(self.pins)
|
||||
self.centerMap()
|
||||
self.map.centerOnPins()
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
|
||||
func centerMap() {
|
||||
guard let vehicle = self.vehicle else { return }
|
||||
|
||||
var minLat = 0.0, maxLat = 0.0, minLon = 0.0, maxLon = 0.0
|
||||
for event in vehicle.events {
|
||||
if event.latitude < minLat || minLat == 0 { minLat = event.latitude }
|
||||
if event.latitude > maxLat || maxLat == 0 { maxLat = event.latitude }
|
||||
if event.longitude < minLon || minLon == 0 { minLon = event.longitude }
|
||||
if event.longitude > maxLon || maxLon == 0 { maxLon = event.longitude }
|
||||
}
|
||||
|
||||
let center = CLLocationCoordinate2D(latitude: (minLat + maxLat)/2, longitude: (minLon + maxLon)/2)
|
||||
let leftTop = CLLocation(latitude: minLat, longitude: minLon)
|
||||
let rightBottom = CLLocation(latitude: maxLat, longitude: maxLon)
|
||||
var diagonal = leftTop.distance(from: rightBottom)*1.2
|
||||
if diagonal < 1000 {
|
||||
diagonal = 1000
|
||||
}
|
||||
|
||||
let region = MKCoordinateRegion(center: center, latitudinalMeters: diagonal, longitudinalMeters: diagonal)
|
||||
self.map.setRegion(region, animated: true)
|
||||
}
|
||||
|
||||
@objc func switchMode(_ sender: UIBarButtonItem) {
|
||||
switch self.mode {
|
||||
case .map:
|
||||
|
||||
38
AutoCat/Controllers/Location/GlobalEventsController.swift
Normal file
38
AutoCat/Controllers/Location/GlobalEventsController.swift
Normal file
@ -0,0 +1,38 @@
|
||||
import UIKit
|
||||
import MapKit
|
||||
import RxSwift
|
||||
|
||||
class GlobalEventsController: UIViewController {
|
||||
|
||||
@IBOutlet weak var map: MKMapView!
|
||||
|
||||
let bag = DisposeBag()
|
||||
var filter: Filter!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
#if targetEnvironment(macCatalyst)
|
||||
self.map.showsZoomControls = true
|
||||
#endif
|
||||
|
||||
IHProgressHUD.show()
|
||||
Api.events(with: self.filter)
|
||||
.observeOn(MainScheduler.init())
|
||||
.subscribe(onSuccess: { events in
|
||||
self.title = "Events found: \(events.count)"
|
||||
let pins = events.map(EventPin.init(event:))
|
||||
self.map.removeAnnotations(self.map.annotations)
|
||||
self.map.addAnnotations(pins)
|
||||
self.map.centerOnPins()
|
||||
IHProgressHUD.dismiss()
|
||||
}) { error in
|
||||
IHProgressHUD.show(error: error)
|
||||
}
|
||||
.disposed(by: self.bag)
|
||||
}
|
||||
|
||||
@IBAction func close(_ sender: UIBarButtonItem) {
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@ import RxCocoa
|
||||
class SearchController: UIViewController, UISearchResultsUpdating {
|
||||
|
||||
@IBOutlet weak var tableView: UITableView!
|
||||
@IBOutlet weak var showMapButton: UIBarButtonItem!
|
||||
|
||||
let bag = DisposeBag()
|
||||
let searchController = UISearchController(searchResultsController: nil)
|
||||
@ -16,6 +17,8 @@ class SearchController: UIViewController, UISearchResultsUpdating {
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
self.showMapButton.isEnabled = false
|
||||
|
||||
searchController.searchResultsUpdater = self
|
||||
searchController.obscuresBackgroundDuringPresentation = false
|
||||
searchController.searchBar.placeholder = "Search plate numbers"
|
||||
@ -45,7 +48,10 @@ class SearchController: UIViewController, UISearchResultsUpdating {
|
||||
.debounce(.milliseconds(500), scheduler: MainScheduler.instance)
|
||||
.flatMap(Api.getVehicles)
|
||||
.observeOn(MainScheduler.instance)
|
||||
.do(onNext: { self.navigationItem.title = "\($0.count) vehicles found" })
|
||||
.do(onNext: {
|
||||
self.navigationItem.title = "\($0.count) vehicles found"
|
||||
self.showMapButton.isEnabled = $0.count > 0
|
||||
})
|
||||
.map { $0.groupedByDate() }
|
||||
.bind(to: self.tableView.rx.items(dataSource: ds))
|
||||
.disposed(by: self.bag)
|
||||
@ -96,4 +102,16 @@ class SearchController: UIViewController, UISearchResultsUpdating {
|
||||
}
|
||||
self.navigationController?.pushViewController(controller, animated: true)
|
||||
}
|
||||
|
||||
@IBAction func showOnMap(_ sender: UIBarButtonItem) {
|
||||
let sb = UIStoryboard(name: "Main", bundle: nil)
|
||||
let controller = sb.instantiateViewController(identifier: "GlobalEventsNavigation") as UINavigationController
|
||||
if let eventsVC = controller.viewControllers.first as? GlobalEventsController {
|
||||
eventsVC.filter = self.filter
|
||||
}
|
||||
|
||||
controller.modalPresentationStyle = .fullScreen
|
||||
//self.navigationController?.pushViewController(controller, animated: true)
|
||||
self.present(controller, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
25
AutoCat/Extensions/MapExt.swift
Normal file
25
AutoCat/Extensions/MapExt.swift
Normal file
@ -0,0 +1,25 @@
|
||||
import Foundation
|
||||
import MapKit
|
||||
|
||||
extension MKMapView {
|
||||
func centerOnPins() {
|
||||
var minLat = 0.0, maxLat = 0.0, minLon = 0.0, maxLon = 0.0
|
||||
for annotation in self.annotations {
|
||||
if annotation.coordinate.latitude < minLat || minLat == 0 { minLat = annotation.coordinate.latitude }
|
||||
if annotation.coordinate.latitude > maxLat || maxLat == 0 { maxLat = annotation.coordinate.latitude }
|
||||
if annotation.coordinate.longitude < minLon || minLon == 0 { minLon = annotation.coordinate.longitude }
|
||||
if annotation.coordinate.longitude > maxLon || maxLon == 0 { maxLon = annotation.coordinate.longitude }
|
||||
}
|
||||
|
||||
let center = CLLocationCoordinate2D(latitude: (minLat + maxLat)/2, longitude: (minLon + maxLon)/2)
|
||||
let leftTop = CLLocation(latitude: minLat, longitude: minLon)
|
||||
let rightBottom = CLLocation(latitude: maxLat, longitude: maxLon)
|
||||
var diagonal = leftTop.distance(from: rightBottom)*1.2
|
||||
if diagonal < 1000 {
|
||||
diagonal = 1000
|
||||
}
|
||||
|
||||
let region = MKCoordinateRegion(center: center, latitudinalMeters: diagonal, longitudinalMeters: diagonal)
|
||||
self.setRegion(region, animated: true)
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@ import RealmSwift
|
||||
import RxSwift
|
||||
import CoreLocation
|
||||
|
||||
public class VehicleEvent: Object, Codable {
|
||||
class VehicleEvent: Object, Codable {
|
||||
@objc dynamic var id: String?
|
||||
@objc dynamic var date: TimeInterval = Date().timeIntervalSince1970
|
||||
@objc dynamic var latitude: Double = 0
|
||||
@ -12,6 +12,7 @@ public class VehicleEvent: Object, Codable {
|
||||
@objc dynamic var direction: Double = 0
|
||||
@objc dynamic var address: String? = nil
|
||||
|
||||
var number: String?
|
||||
var coordinate: CLLocationCoordinate2D {
|
||||
return CLLocationCoordinate2D(latitude: self.latitude, longitude: self.longitude)
|
||||
}
|
||||
@ -42,4 +43,8 @@ public class VehicleEvent: Object, Codable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override static func ignoredProperties() -> [String] {
|
||||
return ["plateNumber"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,4 +241,8 @@ class Api {
|
||||
let body = ["event": event]
|
||||
return self.makeBodyRequest(api: "events", body: body, method: "PUT")
|
||||
}
|
||||
|
||||
public static func events(with filter: Filter) -> Single<[VehicleEvent]> {
|
||||
return self.makeGetRequest(api: "events", params: filter.queryDictionary())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user