Unverified Commit e4fa5511 authored by ASAHI OCEAN's avatar ASAHI OCEAN Committed by GitHub
Browse files

Merge pull request #20 from asahiocean/develop

Develop
parents 1568ca1f 1d514cf9
import Foundation
import UIKit
import MapKit
......@@ -40,7 +39,7 @@ extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
guard let annotation = view.annotation else { return }
mapView.deselectAnnotation(annotation, animated: true)
Model.shared.selected = nil
self.model.selected = nil
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
......@@ -48,7 +47,7 @@ extension ViewController: MKMapViewDelegate {
if let pin = annotation as? PinAnnotation {
mapView.selectAnnotation(pin, animated: true)
// If the graph is built, give the opportunity to choose the starting and ending point
if Model.shared.graphsBuilt { Model.shared.selected = pin }
if self.model.graphsBuilt { self.model.selected = pin }
}
}
......@@ -59,7 +58,7 @@ extension ViewController: MKMapViewDelegate {
case let pin as PinAnnotation:
let id = PinMarkerView.reuseId
let view = mapView.dequeueReusableAnnotationView(withIdentifier: id, for: pin)
Model.shared.pins.append(pin)
self.model.pins.append(pin)
return view
default:
return nil
......@@ -72,8 +71,8 @@ extension ViewController: MKMapViewDelegate {
switch view.annotation {
case let pin as PinAnnotation:
guard let annotation = view.annotation else { return }
Model.shared.pins.removeAll(where: { $0 == pin })
Model.shared.route.removeAll(where: { $0 == pin })
self.model.pins.removeAll(where: { $0 == pin })
self.model.route.removeAll(where: { $0 == pin })
mapView.removeAnnotation(annotation)
// After removing the marker, the graphs will be rebuilt
self.constructGraphs()
......
......@@ -37,7 +37,7 @@ extension ViewController: ModelDelegate {
let coords = mapView.model.route.compactMap({ $0.coordinate })
for (i,coord) in coords.enumerated() {
if (i + 1) < coords.count {
if (i+1) < coords.count {
createRouteTo(from: coord, to: coords[i+1])
}
}
......
......@@ -5,6 +5,7 @@ import UIKit
class ViewController: UIViewController {
var mapView: MapView!
internal var model = Model.shared
/// Button for building graphs and routes
weak var mainButton: UIButton!
......
......@@ -21,8 +21,8 @@ protocol ModelDelegate: AnyObject {
@objc dynamic var selected: PinAnnotation?
public var route: [PinAnnotation] = []
var selectedPinsKVO: NSKeyValueObservation!
var mainButtonTitle: String = "" // To save the button name
internal var selectedPinsKVO: NSKeyValueObservation!
internal var mainButtonTitle: String = "" // To save the button name
fileprivate override init() {
super.init()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment