Maps Delegate implementation
This example lists all of the NGLMapViewDelegate
methods and describes each of them.
For all code examples, refer to Maps Code Examples
MapViewDelegateViewController view source
1import Foundation
2import UIKit
3import Nbmap
4class MapViewDelegateViewController: UIViewController {
5 var nbMapView: NGLMapView! {
6 didSet {
7 oldValue?.removeFromSuperview()
8 if let mapView = nbMapView {
9 configureMapView(nbMapView)
10 view.insertSubview(mapView, at: 0)
11 }
12 }
13 }
14
15 func configureMapView(_ mapView: NGLMapView) {
16 mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
17 //Set the delegate
18 mapView.delegate = self
19
20 }
21
22 override func viewDidLoad() {
23 super.viewDidLoad()
24 nbMapView = NGLMapView(frame:self.view.bounds)
25 }
26
27
28}
29extension MapViewDelegateViewController: NGLMapViewDelegate {
30 /**
31 Tells the user that the map has just finished loading a style.
32 This method is called during the initialization of the map view and after any
33 subsequent loading of a new style. This method is called between the
34 `-mapViewWillStartRenderingMap:` and `-mapViewDidFinishRenderingMap:` delegate
35 methods. Changes to sources or layers of the current style do not cause this
36 method to be called.
37 This method is the earliest opportunity to modify the layout or appearance of
38 the current style before the map view is displayed to the user.
39 @param mapView The map view that has just loaded a style.
40 @param style The style that was loaded.
41 */
42 func mapView(_ mapView: NGLMapView, didFinishLoading style: NGLStyle){
43 let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),
44 acrossDistance:1000,
45 pitch:0,
46 heading:0)
47 nbMapView.fly(to: camera)
48
49 }
50
51 /**
52 Asks the user whether the map view should be allowed to change from the
53 existing camera to the new camera in response to a user gesture.
54 This method is called as soon as the user gesture is recognized. It is not
55 called in response to a programmatic camera change, such as by setting the
56 `centerCoordinate` property or calling `-flyToCamera:completionHandler:`.
57 This method is called many times during gesturing, so you should avoid performing
58 complex or performance-intensive tasks in your implementation.
59 @param mapView The map view that the user is manipulating.
60 @param oldCamera The camera representing the viewpoint at the moment the
61 gesture is recognized. If this method returns `NO`, the map view's camera
62 continues to be this camera.
63 @param newCamera The expected camera after the gesture completes. If this
64 method returns `YES`, this camera becomes the map view's camera.
65 @return A Boolean value indicating whether the map view should stay at
66 `oldCamera` or change to `newCamera`.
67 */
68 private func mapView(_ mapView: NGLMapView, shouldChangeFromCamera oldCamera: NGLMapCamera, to newCamera: NGLMapCamera ){
69
70
71 }
72
73 /**
74 Asks the user whether the map view should be allowed to change from the
75 existing camera to the new camera in response to a user gesture.
76 This method is called as soon as the user gesture is recognized. It is not
77 called in response to a programmatic camera change, such as by setting the
78 `centerCoordinate` property or calling `-flyToCamera:completionHandler:`.
79 This method is called many times during gesturing, so you should avoid performing
80 complex or performance-intensive tasks in your implementation.
81 @param mapView The map view that the user is manipulating.
82 @param oldCamera The camera representing the viewpoint at the moment the
83 gesture is recognized. If this method returns `NO`, the map view's camera
84 continues to be this camera.
85 @param newCamera The expected camera after the gesture completes. If this
86 method returns `YES`, the viewport of the map will transition to the new camera. Note that the new camera cannot be modified.
87 @param reason The reason for the camera change.
88 @return A Boolean value indicating whether the map view should stay at
89 `oldCamera` or transition to `newCamera`.
90 @note If this method is implemented `-mapView:shouldChangeFromCamera:toCamera:` will not be called.
91 */
92 func mapView(_ mapView: NGLMapView, shouldChangeFrom oldCamera: NGLMapCamera, to newCamera: NGLMapCamera, reason: NGLCameraChangeReason) -> Bool {
93 return true
94 }
95
96 /**
97 Tells the user that the viewpoint depicted by the map view is about to change.
98 This method is called whenever the currently displayed map camera will start
99 changing for any reason.
100 @param mapView The map view whose viewpoint will change.
101 @param animated Whether the change will cause an animated effect on the map.
102 */
103 func mapView(_ mapView: NGLMapView, regionWillChangeAnimated animated: Bool){
104
105
106 }
107
108 /**
109 Tells the user that the viewpoint depicted by the map view is about to change.
110 This method is called whenever the currently displayed map camera will start
111 changing for any reason.
112 @param mapView The map view whose viewpoint will change.
113 @param animated Whether the change will cause an animated effect on the map.
114 @param reason The reason for the camera change.
115 @note If this method is implemented `-mapView:regionWillChangeAnimated:` will not be called.
116 */
117 func mapView(_ mapView: NGLMapView, regionWillChangeWith reason: NGLCameraChangeReason, animated: Bool){
118
119
120 }
121
122 /**
123 Tells the user that the viewpoint depicted by the map view is changing.
124 This method is called as the currently displayed map camera changes as part of
125 an animation, whether due to a user gesture or due to a call to a method such
126 as `-[NGLMapView setCamera:animated:]`. This method can be called before
127 `-mapViewDidFinishLoadingMap:` is called.
128 During the animation, this method may be called many times to report updates to
129 the viewpoint. Therefore, your implementation of this method should be as lightweight
130 as possible to avoid affecting performance.
131 @param mapView The map view whose viewpoint is changing.
132 */
133 func mapViewRegionIsChanging(_ mapView: NGLMapView){
134
135
136 }
137
138 /**
139 Tells the user that the viewpoint depicted by the map view is changing.
140 This method is called as the currently displayed map camera changes as part of
141 an animation, whether due to a user gesture or due to a call to a method such
142 as `-[NGLMapView setCamera:animated:]`. This method can be called before
143 `-mapViewDidFinishLoadingMap:` is called.
144 During the animation, this method may be called many times to report updates to
145 the viewpoint. Therefore, your implementation of this method should be as lightweight
146 as possible to avoid affecting performance.
147 @param mapView The map view whose viewpoint is changing.
148 @param reason The reason for the camera change.
149 @note If this method is implemented `-mapViewRegionIsChanging:` will not be called.
150 */
151 func mapView(_ mapView: NGLMapView, regionIsChangingWith reason: NGLCameraChangeReason){
152
153
154 }
155
156 /**
157 Tells the user that the viewpoint depicted by the map view has finished
158 changing.
159 This method is called whenever the currently displayed map camera has finished
160 changing, after any calls to `-mapViewRegionIsChanging:` due to animation. Therefore,
161 this method can be called before `-mapViewDidFinishLoadingMap:` is called.
162 @param mapView The map view whose viewpoint has changed.
163 @param animated Whether the change caused an animated effect on the map.
164 */
165 func mapView(_ mapView: NGLMapView, regionDidChangeAnimated animated: Bool){
166
167
168 }
169
170 /**
171 Tells the user that the viewpoint depicted by the map view has finished
172 changing.
173 This method is called whenever the currently displayed map camera has finished
174 changing, after any calls to `-mapViewRegionIsChanging:` due to animation. Therefore,
175 this method can be called before `-mapViewDidFinishLoadingMap:` is called.
176 @param mapView The map view whose viewpoint has changed.
177 @param animated Whether the change caused an animated effect on the map.
178 @param reason The reason for the camera change.
179 @note If this method is implemented `-mapView:regionDidChangeAnimated:` will not be called.
180 */
181 func mapView(_ mapView: NGLMapView, regionDidChangeWith reason: NGLCameraChangeReason, animated: Bool){
182
183
184 }
185
186// ##pragma mark Loading the Map
187
188 /**
189 Tells the user that the map view will begin to load.
190 This method is called whenever the map view starts loading, including when a
191 new style has been set and the map must reload.
192 @param mapView The map view that is starting to load.
193 */
194 func mapViewWillStartLoadingMap(_ mapView: NGLMapView) {
195
196 }
197
198 /**
199 Tells the user that the map view has finished loading.
200 This method is called whenever the map view finishes loading, either after the
201 initial load or after a style change has forced a reload.
202 @param mapView The map view that has finished loading.
203 */
204 func mapViewDidFinishLoadingMap(_ mapView: NGLMapView) {
205
206 }
207
208 /**
209 Tells the user that the map view was unable to load data needed for
210 displaying the map.
211 This method may be called for a variety of reasons, including a network
212 connection failure or a failure to fetch the style from the server. You can use
213 the given error message to notify the user that map data is unavailable.
214 @param mapView The map view that is unable to load the data.
215 @param error The reason the data could not be loaded.
216 */
217 func mapViewDidFailLoadingMap(_ apView: NGLMapView,withError error: Error) {
218
219 }
220
221 /**
222 Tells the user that the map view is about to redraw.
223 This method is called any time the map view needs to redraw due to a change in
224 the viewpoint or style property transition. This method may be called very
225 frequently, even moreso than `-mapViewRegionIsChanging:`. Therefore, your
226 implementation of this method should be as lightweight as possible to avoid
227 affecting performance.
228 @param mapView The map view that is about to redraw.
229 */
230 func mapViewWillStartRenderingFrame(_ mapView: NGLMapView ) {
231
232 }
233
234 /**
235 Tells the user that the map view has just redrawn.
236 This method is called any time the map view needs to redraw due to a change in
237 the viewpoint or style property transition. This method may be called very
238 frequently, even moreso than `-mapViewRegionIsChanging:`. Therefore, your
239 implementation of this method should be as lightweight as possible to avoid
240 affecting performance.
241 @param mapView The map view that has just redrawn.
242 */
243 func mapViewDidFinishRenderingFrame(_ mapView: NGLMapView,fullyRendered:Bool) {
244
245 }
246
247 /**
248 Tells the user that the map view is entering an idle state, and no more
249 drawing will be necessary until new data is loaded or there is some interaction
250 with the map.
251
252 - No camera transitions are in progress
253 - All currently requested tiles have loaded
254 - All fade/transition animations have completed
255
256 @param mapView The map view that has just entered the idle state.
257 */
258 func mapViewDidBecomeIdle(_ mapView: NGLMapView ) {
259
260 }
261
262 func mapView(_ mapView: NGLMapView, didFailToLoadImage imageName: String) -> UIImage? {
263 return nil
264 }
265
266 /**
267 Asks the user whether the map view should evict cached images.
268
269 This method is called in two scenarios: when the cumulative size of unused images
270 exceeds the cache size or when the last tile that includes the image is removed from
271 memory.
272
273 @param mapView The map view that is evicting the image.
274 @param imageName The image name that is going to be removed.
275 @return A Boolean value indicating whether the map view should evict
276 the cached image.
277 */
278 func mapView(_ mapView: NGLMapView, shouldRemoveStyleImage imageName: String) -> Bool {
279 return true
280 }
281
282// #pragma mark Tracking User Location
283
284 /**
285 Tells the user that the map view will begin tracking the user's location.
286 This method is called when the value of the `showsUserLocation` property
287 changes to `YES`.
288 @param mapView The map view that is tracking the user's location.
289 */
290 func mapViewWillStartLocatingUser(_ mapView: NGLMapView) {
291
292 }
293
294 /**
295 Tells the user that the map view has stopped tracking the user's location.
296 This method is called when the value of the `showsUserLocation` property
297 changes to `NO`.
298 @param mapView The map view that is tracking the user's location.
299 */
300 func mapViewDidStopLocatingUser(_ mapView: NGLMapView) {
301
302 }
303
304
305 /**
306 Asks the user styling options for each default user location annotation view.
307
308 This method is called many times during gesturing, so you should avoid performing
309 complex or performance-intensive tasks in your implementation.
310
311 @param mapView The map view that is tracking the user's location.
312 */
313 func mapView(styleForDefaultUserLocationAnnotationView mapView: NGLMapView) -> NGLUserLocationAnnotationViewStyle {
314 let locationStyle = NGLUserLocationAnnotationViewStyle()
315 /**
316 The fill color for the puck view.
317 */
318 locationStyle.puckFillColor = UIColor.blue
319 /**
320 The shadow color for the puck view.
321 */
322 locationStyle.puckShadowColor = UIColor.red
323 /**
324 The shadow opacity for the puck view.
325 Set any value between 0.0 and 1.0.
326 The default value of this property is equal to `0.25`
327 */
328 locationStyle.puckShadowOpacity = 0.25
329 /**
330 The fill color for the arrow puck.
331 */
332 locationStyle.puckArrowFillColor = UIColor.black
333 /**
334 The fill color for the puck view.
335 */
336 locationStyle.haloFillColor = UIColor.white
337
338 if #available(iOS 14, *) {
339 /**
340 The halo fill color for the approximate view.
341 */
342 locationStyle.approximateHaloFillColor = UIColor.white
343 /**
344 The halo border color for the approximate view.
345 */
346 locationStyle.approximateHaloBorderColor = UIColor.white
347 /**
348 The halo border width for the approximate view.
349 The default value of this property is equal to `2.0`
350 */
351 locationStyle.approximateHaloBorderWidth = 2.0
352 /**
353 The halo opacity for the approximate view.
354 Set any value between 0.0 and 1.0
355 The default value of this property is equal to `0.15`
356 */
357 locationStyle.approximateHaloOpacity = 0.15
358 }
359
360 return locationStyle
361 }
362
363 /**
364 Tells the user that the location of the user was updated.
365 While the `showsUserLocation` property is set to `YES`, this method is called
366 whenever a new location update is received by the map view. This method is also
367 called if the map view's user tracking mode is set to
368 `NGLUserTrackingModeFollowWithHeading` and the heading changes, or if it is set
369 to `NGLUserTrackingModeFollowWithCourse` and the course changes.
370 This method is not called if the application is currently running in the
371 background. If you want to receive location updates while running in the
372 background, you must use the Core Location framework.
373 private @param mapView The map view that is tracking the user's location.
374 @param userLocation The location object representing the user's latest
375 location. This property may be `nil`.
376 */
377 func mapView(_ mapView: NGLMapView, didUpdate userLocation: NGLUserLocation?) {
378
379 }
380
381 /**
382 Tells the user that an attempt to locate the user's position failed.
383 @param mapView The map view that is tracking the user's location.
384 @param error An error object containing the reason why location tracking
385 failed.
386 */
387 func mapView(_ mapView: NGLMapView, didFailToLocateUserWithError error: Error) {
388
389 }
390
391
392 /**
393 Tells the user that the map view's user tracking mode has changed.
394 This method is called after the map view asynchronously changes to reflect the
395 new user tracking mode, for example by beginning to zoom or rotate.
396 private @param mapView The map view that changed its tracking mode.
397 @param mode The new tracking mode.
398 @param animated Whether the change caused an animated effect on the map.
399 */
400 func mapView(_ mapView: NGLMapView, didChange mode: NGLUserTrackingMode, animated: Bool ) {
401
402 }
403
404 /**
405 Returns a screen coordinate at which to position the user location annotation.
406 This coordinate is relative to the map view's origin after applying the map view's
407 content insets.
408 When unimplemented, the user location annotation is aligned within the center of
409 the map view with respect to the content insets.
410 This method will override any values set by `NGLMapView.userLocationVerticalAlignment`
411 or `-[NGLMapView setUserLocationVerticalAlignment:animated:]`.
412 @param mapView The map view that is tracking the user's location.
413
414 We don't need to set the anchor point for now, so comment out this method first
415 */
416// func mapViewUserLocationAnchorPoint(_ mapView: NGLMapView ) -> CGPoint {
417// return nil
418// }
419 /**
420 Tells the user that the map's location updates accuracy authorization has changed.
421
422 This method is called after the user changes location accuracy authorization when
423 requesting location permissions or in privacy settings.
424
425 @param mapView The map view that changed its location accuracy authorization.
426 @param manager The location manager reporting the update.
427
428 */
429 func mapView(_ apView: NGLMapView, didChangeLocationManagerAuthorization manager: NGLLocationManager) {
430
431 }
432
433
434// #pragma mark Managing the Appearance of Annotations
435 /**
436 Returns an annotation image object to mark the given point annotation object on
437 the map.
438 Implement this method to mark a point annotation with a static image. If you
439 want to mark a particular point annotation with an annotation view instead,
440 omit this method or have it return `nil` for that annotation, then implement
441 `-mapView:viewForAnnotation:`.
442 Static annotation images use less memory and draw more quickly than annotation
443 views. On the other hand, annotation views are compatible with UIKit, Core
444 Animation, and other Cocoa Touch frameworks.
445 @param mapView The map view that requested the annotation image.
446 @param annotation The object representing the annotation that is about to be
447 displayed.
448 @return The annotation image object to display for the given annotation or
449 `nil` if you want to display the default marker image or an annotation view.
450 */
451 func mapView(_ mapView: NGLMapView, imageFor annotation: NGLAnnotation) -> NGLAnnotationImage? {
452 return nil
453 }
454 /**
455 Returns the alpha value to use when rendering a shape annotation.
456 A value of `0.0` results in a completely transparent shape. A value of `1.0`,
457 the default, results in a completely opaque shape.
458 This method sets the opacity of an entire shape, inclusive of its stroke and
459 fill. To independently set the values for stroke or fill, specify an alpha
460 component in the color returned by `-mapView:strokeColorForShapeAnnotation:` or
461 `-mapView:fillColorForPolygonAnnotation:`.
462 @param mapView The map view rendering the shape annotation.
463 @param annotation The annotation being rendered.
464 @return An alpha value between `0` and `1.0`.
465 */
466 func mapView(_ mapView: NGLMapView, alphaForShapeAnnotation annotation: NGLShape) -> CGFloat {
467 return 1.0
468 }
469 /**
470 Returns the color to use when rendering the outline of a shape annotation.
471 The default stroke color is the map view's tint color. If a pattern color is
472 specified, the result is undefined.
473 Opacity may be set by specifying an alpha component. The default alpha value is
474 `1.0` and results in a completely opaque stroke.
475 @param mapView The map view rendering the shape annotation.
476 @param annotation The annotation being rendered.
477 @return A color to use for the shape outline.
478 */
479 func mapView(_ mapView: NGLMapView, strokeColorForShapeAnnotation annotation: NGLShape) -> UIColor {
480 return UIColor.red
481 }
482 /**
483 Returns the color to use when rendering the fill of a polygon annotation.
484 The default fill color is the map view's tint color. If a pattern color is
485 specified, the result is undefined.
486 Opacity may be set by specifying an alpha component. The default alpha value is
487 `1.0` and results in a completely opaque shape.
488 @param mapView The map view rendering the polygon annotation.
489 @param annotation The annotation being rendered.
490 @return The polygon's interior fill color.
491 */
492
493 func mapView(_ mapView: NGLMapView, fillColorForPolygonAnnotation annotation: NGLPolygon) -> UIColor {
494 return UIColor.red
495 }
496
497 /**
498 Returns the line width in points to use when rendering the outline of a
499 polyline annotation.
500 By default, the polyline is outlined with a line `3.0` points wide.
501 @param mapView The map view rendering the polygon annotation.
502 @param annotation The annotation being rendered.
503 @return A line width for the polyline, measured in points.
504 */
505 func mapView(_ mapView: NGLMapView, lineWidthForPolylineAnnotation annotation: NGLPolyline) -> CGFloat {
506 return 3.0
507 }
508// #pragma mark Managing Annotation Views
509 /**
510 Returns a view object to mark the given point annotation object on the map.
511 Implement this method to mark a point annotation with a view object. If you
512 want to mark a particular point annotation with a static image instead, omit
513 this method or have it return `nil` for that annotation, then implement
514 `-mapView:imageForAnnotation:` instead.
515 Annotation views are compatible with UIKit, Core Animation, and other Cocoa
516 Touch frameworks. On the other hand, static annotation images use less memory
517 and draw more quickly than annotation views.
518 The user location annotation view can also be customized via this method. When
519 `annotation` is an instance of `NGLUserLocation` (or equal to the map view's
520 `userLocation` property), return an instance of `NGLUserLocationAnnotationView`
521 (or a subclass thereof).
522 @param mapView The map view that requested the annotation view.
523 @param annotation The object representing the annotation that is about to be
524 displayed.
525 @return The view object to display for the given annotation or `nil` if you
526 want to display an annotation image instead.
527 */
528 func mapView(_ mapView: NGLMapView, viewFor annotation: NGLAnnotation) -> NGLAnnotationView? {
529 return nil
530 }
531
532 /**
533 Tells the user that one or more annotation views have been added and
534 positioned on the map.
535 This method is called just after the views are added to the map. You can
536 implement this method to animate the addition of the annotation views.
537 @param mapView The map view to which the annotation views were added.
538 @param annotationViews An array of `NGLAnnotationView` objects representing the
539 views that were added.
540 */
541 func mapView(mapView: NGLMapView, didAddAnnotationViews annotationViews: [NGLAnnotation]) {
542
543 }
544
545// #pragma mark Selecting Annotations
546 /**
547 Returns a Boolean value indicating whether the shape annotation can be selected.
548 If the return value is `YES`, the user can select the annotation by tapping
549 on it. If the delegate does not implement this method, the default value is `YES`.
550 @param mapView The map view that has selected the annotation.
551 @param annotation The object representing the shape annotation.
552 @return A Boolean value indicating whether the annotation can be selected.
553 */
554 func mapView(_ mapView: NGLMapView, shapeAnnotationIsEnabled annotation: NGLShape) -> Bool{
555 return true
556 }
557
558 /**
559 Tells the user that one of its annotations was selected.
560 You can use this method to track changes in the selection state of annotations.
561 If the annotation is associated with an annotation view, you can also implement
562 `-mapView:didSelectAnnotationView:`, which is called immediately after this
563 method is called.
564 @param mapView The map view containing the annotation.
565 @param annotation The annotation that was selected.
566 */
567 func mapView(_ mapView: NGLMapView, didSelect annotation: NGLAnnotation){
568
569 }
570 /**
571 Tells the user that one of its annotations was deselected.
572 You can use this method to track changes in the selection state of annotations.
573 If the annotation is associated with an annotation view, you can also implement
574 `-mapView:didDeselectAnnotationView:`, which is called immediately after this
575 method is called.
576 @param mapView The map view containing the annotation.
577 @param annotation The annotation that was deselected.
578 */
579 func mapView(_ mapView: NGLMapView, didDeselect annotation: NGLAnnotation){
580
581 }
582
583 /**
584 Tells the user that one of its annotation views was selected.
585 You can use this method to track changes in the selection state of annotation
586 views.
587 This method is only called for annotation views. To track changes in the
588 selection state of all annotations, including those associated with static
589 annotation images, implement `-mapView:didSelectAnnotation:`, which is called
590 immediately before this method is called.
591 @param mapView The map view containing the annotation.
592 @param annotationView The annotation view that was selected.
593 */
594 func mapView(_ mapView: NGLMapView, didSelect annotationView: NGLAnnotationView){
595
596 }
597
598 /**
599 Tells the user that one of its annotation views was deselected.
600 You can use this method to track changes in the selection state of annotation
601 views.
602 This method is only called for annotation views. To track changes in the
603 selection state of all annotations, including those associated with static
604 annotation images, implement `-mapView:didDeselectAnnotation:`, which is called
605 immediately before this method is called.
606 @param mapView The map view containing the annotation.
607 @param annotationView The annotation view that was deselected.
608 */
609 func mapView(_ mapView: NGLMapView, didDeselect annotationView: NGLAnnotationView){
610
611 }
612// #pragma mark Managing Callout Views
613 /**
614 Returns a Boolean value indicating whether the annotation is able to display
615 extra information in a callout bubble.
616 This method is called after an annotation is selected, before any callout is
617 displayed for the annotation.
618 If the return value is `YES`, a callout view is shown when the user taps on an
619 annotation, selecting it. The default callout displays the annotation's title
620 and subtitle. You can add accessory views to either end of the callout by
621 implementing the `-mapView:leftCalloutAccessoryViewForAnnotation:` and
622 `-mapView:rightCalloutAccessoryViewForAnnotation:` methods. You can further
623 customize the callout's contents by implementing the
624 `-mapView:calloutViewForAnnotation:` method.
625 If the return value is `NO`, or if this method is absent from the delegate, or
626 if the annotation lacks a title, the annotation will not show a callout even
627 when selected.
628 @param mapView The map view that has selected the annotation.
629 @param annotation The object representing the annotation.
630 @return A Boolean value indicating whether the annotation should show a
631 callout.
632 */
633 func mapView(_ mapView: NGLMapView, annotationCanShowCallout annotation: NGLAnnotation) -> Bool{
634 return true
635 }
636
637 /**
638 Returns a callout view to display for the given annotation.
639 If this method is present in the delegate, it must return a new instance of a
640 view dedicated to display the callout. The returned view will be configured by
641 the map view.
642 If this method is absent from the delegate, or if it returns `nil`, a standard,
643 two-line, bubble-like callout view is displayed by default.
644 @param mapView The map view that requested the callout view.
645 @param annotation The object representing the annotation.
646 @return A view conforming to the `NGLCalloutView` protocol, or `nil` to use the
647 default callout view.
648 */
649 func mapView(_ mapView: NGLMapView, calloutViewFor annotation: NGLAnnotation) -> NGLCalloutView? {
650 return nil
651 }
652
653 /**
654 Returns the view to display on the left side of the standard callout bubble.
655 The left callout view is typically used to convey information about the
656 annotation or to link to custom information provided by your application.
657 If the view you specify is a descendant of the `UIControl` class, you can use
658 the map view's delegate to receive notifications when your control is tapped,
659 by implementing the `-mapView:annotation:calloutAccessoryControlTapped:`
660 method. If the view you specify does not descend from `UIControl`, your view is
661 responsible for handling any touch events within its bounds.
662 If this method is absent from the delegate, or if it returns `nil`, the
663 standard callout view has no accessory view on its left side. The return value
664 of this method is ignored if `-mapView:calloutViewForAnnotation:` is present in
665 the delegate.
666 To display a view on the callout's right side, implement the
667 `-mapView:rightCalloutAccessoryViewForAnnotation:` method.
668 @param mapView The map view presenting the annotation callout.
669 @param annotation The object representing the annotation with the callout.
670 @return The accessory view to display.
671 */
672 func mapView(_ mapView: NGLMapView, leftCalloutAccessoryViewFor annotation: NGLAnnotation) -> UIView? {
673 return nil
674 }
675
676 /**
677 Returns the view to display on the right side of the standard callout bubble.
678 The right callout view is typically used to convey information about the
679 annotation or to link to custom information provided by your application.
680 If the view you specify is a descendant of the `UIControl` class, you can use
681 the map view's delegate to receive notifications when your control is tapped,
682 by implementing the `-mapView:annotation:calloutAccessoryControlTapped:`
683 method. If the view you specify does not descend from `UIControl`, your view is
684 responsible for handling any touch events within its bounds.
685 If this method is absent from the delegate, or if it returns `nil`, the
686 standard callout view has no accessory view on its right side. The return value
687 of this method is ignored if `-mapView:calloutViewForAnnotation:` is present in
688 the delegate.
689 To display a view on the callout's left side, implement the
690 `-mapView:leftCalloutAccessoryViewForAnnotation:` method.
691 @param mapView The map view presenting the annotation callout.
692 @param annotation The object representing the annotation with the callout.
693 @return The accessory view to display.
694 */
695 func mapView(_ mapView: NGLMapView, rightCalloutAccessoryViewFor annotation: NGLAnnotation) -> UIView? {
696 return nil
697 }
698
699 /**
700 Tells the user that the user tapped one of the accessory controls in the
701 annotation's callout view.
702 In a standard callout view, accessory views contain custom content and are
703 positioned on either side of the annotation title text. If an accessory view
704 you specify is a descendant of the `UIControl` class, the map view calls this
705 method as a convenience whenever the user taps your view. You can use this
706 method to respond to taps and perform any actions associated with that control.
707 For example, if your control displays additional information about the
708 annotation, you could use this method to present a modal panel with that
709 information.
710 If your custom accessory views are not descendants of the `UIControl` class,
711 the map view does not call this method. If the annotation has a custom callout
712 view via the `-mapView:calloutViewForAnnotation:` method, you can specify the
713 custom accessory views using the `NGLCalloutView` protocol's
714 `leftAccessoryView` and `rightAccessoryView` properties.
715 @param mapView The map view containing the specified annotation.
716 @param annotation The annotation whose accessory view was tapped.
717 @param control The control that was tapped.
718 */
719 func mapView(_ mapView: NGLMapView, calloutAccessoryControlTapped control: UIControl){
720
721 }
722
723 /**
724 Tells the user that the user tapped on an annotation's callout view.
725 This method is called when the user taps on the body of the callout view, as
726 opposed to the callout's left or right accessory view. If the annotation has a
727 custom callout view via the `-mapView:calloutViewForAnnotation:` method, this
728 method is only called whenever the callout view calls its delegate's
729 `-[NGLCalloutViewDelegate calloutViewTapped:]` method.
730 If this method is present on the delegate, the standard callout view's body
731 momentarily highlights when the user taps it, whether or not this method does
732 anything in response to the tap.
733 @param mapView The map view containing the specified annotation.
734 @param annotation The annotation whose callout was tapped.
735 */
736 func mapView(_ mapView: NGLMapView, tapOnCalloutFor annotation: NGLAnnotation){
737
738 }
739}
The code initializes a MapViewDelegateViewController class that subclasses UIViewController. It includes a property nbMapView of type NGLMapView, which represents a map view. The nbMapView property is configured in the configureMapView method, where the autoresizing mask is set and the delegate is assigned. In viewDidLoad, an instance of NGLMapView is created and assigned to nbMapView.
The code extends the MapViewDelegateViewController class to conform to the NGLMapViewDelegate protocol. It implements various delegate methods that provide information and respond to events related to the map view. These methods include:
-
mapView(_:didFinishLoading:): This method is called when the map view finishes loading its style. It creates a new camera object and sets it as the camera for the map view using the fly(to:completionHandler:) method.
-
mapView(_:shouldChangeFrom:to:): This method is called when the map view is about to change from the existing camera to a new camera. It can be used to determine whether the camera change should be allowed or not.
-
mapView(_:shouldChangeFrom:to:reason:): This method is similar to the previous one but provides additional information about the reason for the camera change.
-
mapView(_:regionWillChangeAnimated:) and mapView(_:regionWillChangeWith:animated:): These methods are called when the map view's viewpoint is about to change. They can be used to perform actions or update UI before the change occurs.
-
mapViewRegionIsChanging(_:) and mapView(_:regionIsChangingWith:): These methods are called while the map view's viewpoint is changing, either due to user interaction or animation. They can be used to track the ongoing changes in the viewpoint.
-
mapView(_:regionDidChangeAnimated:) and mapView(_:regionDidChangeWith:animated:): These methods are called when the map view's viewpoint has finished changing. They can be used to perform actions or update UI after the change has occurred.
-
Various other methods are implemented to handle events such as map loading, rendering, user location tracking, managing the appearance of annotations, etc. These methods provide customization options and allow the developer to respond to specific events related to the map view.
Overall, the code sets up a map view, configures its delegate, and implements delegate methods to control its behavior and respond to user interactions and map events.