-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathViewController.swift
More file actions
70 lines (57 loc) · 2.31 KB
/
ViewController.swift
File metadata and controls
70 lines (57 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// ViewController.swift
// JPSThumbnailAnnotation
//
// Created by JP Simard on 5/1/15.
// Copyright (c) 2015 JP Simard. All rights reserved.
//
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
var annotations: [JPSThumbnailAnnotation] {
// Empire State Building
let empire = JPSThumbnail()
empire.image = UIImage(named: "empire.jpg")
empire.title = "Empire State Building"
empire.subtitle = "NYC Landmark"
empire.coordinate = CLLocationCoordinate2DMake(40.75, -73.99)
empire.disclosureBlock = { println("selected Empire") }
// Apple HQ
let apple = JPSThumbnail()
apple.image = UIImage(named: "apple.jpg")
apple.title = "Apple HQ"
apple.subtitle = "Apple Headquarters"
apple.coordinate = CLLocationCoordinate2DMake(37.33, -122.03)
apple.disclosureBlock = { println("selected Apple") }
// Parliament of Canada
let ottawa = JPSThumbnail()
ottawa.image = UIImage(named: "ottawa.jpg")
ottawa.title = "Parliament of Canada"
ottawa.subtitle = "Oh Canada!"
ottawa.coordinate = CLLocationCoordinate2DMake(45.43, -75.70)
ottawa.disclosureBlock = { println("selected Ottawa") }
return [empire, apple, ottawa].map {
JPSThumbnailAnnotation(thumbnail: $0)
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Map View
let mapView = MKMapView(frame: view.bounds)
mapView.autoresizingMask = .FlexibleHeight | .FlexibleWidth
mapView.delegate = self
view.addSubview(mapView)
// Annotations
mapView.addAnnotations(annotations)
}
// MARK: MKMapViewDelegate
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
(view as? JPSThumbnailAnnotationViewProtocol)?.didSelectAnnotationViewInMap(mapView)
}
func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!) {
(view as? JPSThumbnailAnnotationViewProtocol)?.didDeselectAnnotationViewInMap(mapView)
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
return (annotation as? JPSThumbnailAnnotationProtocol)?.annotationViewInMap(mapView)
}
}