5
case CameraSetCenterCoordinate
6
case CameraSetCenterCoordinateWithZoomLevel
7
case CameraSetCenterCoordinateWithZoomLevelAndDirection
8
case CameraSetCenterCoordinateWithZoomLevelAndDirectionCompletion
11
case SetVisibleCoordinateBounds
12
case SetVisibleCoordinateBoundsWithEdgePadding
13
case SetVisibleCoordinatesWithEdgePadding
14
case SetVisibleCoordinatesWithEdgePaddingAndDirectionAndDuration
16
case SetCameraWithDuration
17
case SetCameraWithDurationAndCompletionHandler
19
case FlyToCameraWithDuration
20
case FlyToCameraWithDurationAndPeakAltitude
22
class MapsCameraViewController: UIViewController {
24
var nbMapView: NGLMapView! {
26
oldValue?.removeFromSuperview()
27
if let mapView = nbMapView {
28
configureMapView(nbMapView)
29
view.insertSubview(mapView, at: 0)
37
CameraType.CameraSetCenterCoordinate,
38
CameraType.CameraSetCenterCoordinateWithZoomLevel,
39
CameraType.CameraSetCenterCoordinateWithZoomLevelAndDirection,
40
CameraType.CameraSetCenterCoordinateWithZoomLevelAndDirectionCompletion,
41
CameraType.SetZoomLevel,
42
CameraType.SetDirection,
43
CameraType.SetVisibleCoordinateBounds,
44
CameraType.SetVisibleCoordinateBoundsWithEdgePadding,
45
CameraType.SetVisibleCoordinatesWithEdgePadding,
46
CameraType.SetVisibleCoordinatesWithEdgePaddingAndDirectionAndDuration,
48
CameraType.SetCameraWithDuration,
49
CameraType.SetCameraWithDurationAndCompletionHandler,
50
CameraType.FlyToCamera,
51
CameraType.FlyToCameraWithDuration,
52
CameraType.FlyToCameraWithDurationAndPeakAltitude,
55
func configureMapView(_ mapView: NGLMapView) {
56
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
58
mapView.delegate = self
61
override func viewDidLoad() {
63
nbMapView = NGLMapView(frame:self.view.bounds)
65
button = UIButton(type: .system)
66
button.setTitle("Settings", for: .normal)
67
button.addTarget(self, action: #selector(showSetings), for: .touchUpInside)
68
button.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
69
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)
73
@objc func showSetings() {
74
let tableViewController = UITableViewController(style: .plain)
75
tableViewController.tableView.delegate = self
76
tableViewController.tableView.dataSource = self
77
tableViewController.title = "Camera Settings"
78
self.present(tableViewController, animated: true)
85
func performeSettings(type: CameraType) {
87
case CameraType.CameraSetCenterCoordinate :
88
nbMapView.setCenter(CLLocationCoordinate2DMake(53.5511, 9.9937),animated: true )
90
case .CameraSetCenterCoordinateWithZoomLevel:
91
nbMapView.setCenter(CLLocationCoordinate2DMake(53.5511, 9.9937),zoomLevel: 18 ,animated: true )
93
case CameraType.CameraSetCenterCoordinateWithZoomLevelAndDirection :
94
nbMapView.setCenter(CLLocationCoordinate2DMake(53.5511, 9.9937),zoomLevel: 18 ,direction: 180, animated: true )
96
case CameraType.CameraSetCenterCoordinateWithZoomLevelAndDirectionCompletion :
97
nbMapView.setCenter(CLLocationCoordinate2DMake(53.5511, 9.9937),zoomLevel: 18 ,direction: 180, animated: true ,completionHandler: {
101
case CameraType.SetZoomLevel :
102
nbMapView.setZoomLevel(17, animated: true)
104
case CameraType.SetDirection :
105
nbMapView.setDirection(0, animated: true)
107
case .SetVisibleCoordinateBounds:
109
CLLocationCoordinate2DMake(53.5511, 9.9937),
110
CLLocationCoordinate2DMake(53.5311, 9.9947),
111
CLLocationCoordinate2DMake(53.5531, 9.9957),
112
CLLocationCoordinate2DMake(53.5521, 9.9967)
114
let bounds = NGLPolygon(coordinates: coords, count: UInt(coords.count)).overlayBounds
116
nbMapView.setVisibleCoordinateBounds(bounds,animated: true)
118
case .SetVisibleCoordinateBoundsWithEdgePadding:
120
CLLocationCoordinate2DMake(53.5511, 9.9937),
121
CLLocationCoordinate2DMake(53.5311, 9.9947),
122
CLLocationCoordinate2DMake(53.5531, 9.9957),
123
CLLocationCoordinate2DMake(53.5521, 9.9967)
125
let bounds = NGLPolygon(coordinates: coords, count: UInt(coords.count)).overlayBounds
127
nbMapView.setVisibleCoordinateBounds(bounds,edgePadding: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10),animated: true,completionHandler: {})
129
case .SetVisibleCoordinatesWithEdgePadding:
131
CLLocationCoordinate2DMake(53.5511, 9.9937),
132
CLLocationCoordinate2DMake(53.5313, 9.9947),
133
CLLocationCoordinate2DMake(53.5531, 9.9937),
134
CLLocationCoordinate2DMake(53.5526, 9.9968)
137
nbMapView.setVisibleCoordinates(coords,count: UInt(coords.count),edgePadding: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10),animated: true)
139
case .SetVisibleCoordinatesWithEdgePaddingAndDirectionAndDuration:
141
CLLocationCoordinate2DMake(53.5511, 9.9937),
142
CLLocationCoordinate2DMake(53.5313, 9.9987),
143
CLLocationCoordinate2DMake(53.5533, 9.9947),
144
CLLocationCoordinate2DMake(53.5529, 9.9938)
146
let function: CAMediaTimingFunction? = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
148
nbMapView.setVisibleCoordinates(coords,count: UInt(coords.count),edgePadding: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10),direction:160, duration: 2, animationTimingFunction: function,completionHandler: nil)
150
case CameraType.SetCamera :
151
let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),
158
nbMapView.setCamera(camera, animated: true)
160
case .SetCameraWithDuration:
161
let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),
165
let function: CAMediaTimingFunction? = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
169
nbMapView.setCamera(camera, withDuration: 1 ,animationTimingFunction: function)
172
case CameraType.SetCameraWithDurationAndCompletionHandler:
173
let function: CAMediaTimingFunction? = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
174
let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),
181
nbMapView.setCamera(camera, withDuration: 1 ,animationTimingFunction: function,completionHandler: {
185
case CameraType.FlyToCamera :
186
let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),
195
nbMapView.fly(to: camera)
197
case CameraType.FlyToCameraWithDuration :
198
let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),
206
nbMapView.fly(to: camera, withDuration: 2 , completionHandler: {
210
case CameraType.FlyToCameraWithDurationAndPeakAltitude :
211
let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),
220
nbMapView.fly(to: camera, withDuration: 2 , peakAltitude: 1000 ,completionHandler: {
229
extension MapsCameraViewController: NGLMapViewDelegate {
230
func mapView(_ mapView: NGLMapView, didFinishLoading style: NGLStyle){
232
nbMapView.zoomLevel = 16.0
233
nbMapView.setCenter(CLLocationCoordinate2DMake(53.5511, 9.9937),animated: false)
237
extension MapsCameraViewController: UITableViewDelegate, UITableViewDataSource {
239
func settingsTitlesForRaw(index: Int) -> String {
240
let type = typeList[index]
242
case CameraType.CameraSetCenterCoordinate :
243
return "Camera Set Center Coordinate"
244
case CameraType.CameraSetCenterCoordinateWithZoomLevelAndDirection :
245
return "Set center coordinate with zoom level and direction"
246
case CameraType.CameraSetCenterCoordinateWithZoomLevelAndDirectionCompletion :
247
return "Set center coordinate with zoom level and direction completion handler"
248
case CameraType.SetZoomLevel :
249
return "Set zoom level"
250
case CameraType.SetDirection :
251
return "Set direction"
252
case CameraType.SetVisibleCoordinateBounds :
253
return "Set visible coordinate bounds"
254
case CameraType.SetVisibleCoordinateBoundsWithEdgePadding :
255
return "Set visible coordinate bounds with edge padding"
256
case .SetVisibleCoordinatesWithEdgePadding:
257
return "Set visible coordinates with edge padding"
258
case .SetVisibleCoordinatesWithEdgePaddingAndDirectionAndDuration:
259
return "Set visible coordinates with edge padding and direction and direction"
260
case CameraType.SetCamera :
262
case CameraType.FlyToCamera :
263
return "Fly to camera"
264
case CameraType.FlyToCameraWithDuration :
265
return "Fly to camera with duration"
266
case CameraType.FlyToCameraWithDurationAndPeakAltitude :
267
return "Fly to camera with duration and peak altitude"
268
case .CameraSetCenterCoordinateWithZoomLevel:
269
return "Set center coordinate with zoom level"
270
case .SetCameraWithDurationAndCompletionHandler:
271
return "Set camera with duration and completion handler"
272
case .SetCameraWithDuration:
273
return "Set camera with duration"
277
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
278
return typeList.count
280
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
281
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
282
cell.textLabel?.text = settingsTitlesForRaw(index: indexPath.row)
285
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
286
tableView.isHidden = true
287
let type = typeList[indexPath.row]
288
dismissSettings(type: type)
291
func dismissSettings(type: CameraType) {
292
dismiss(animated: true)
293
performeSettings(type: type)