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 Foundation2import UIKit3import Nbmap4class MapViewDelegateViewController: UIViewController {5var nbMapView: NGLMapView! {6didSet {7oldValue?.removeFromSuperview()8if let mapView = nbMapView {9configureMapView(nbMapView)10view.insertSubview(mapView, at: 0)11}12}13}1415func configureMapView(_ mapView: NGLMapView) {16mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]17//Set the delegate18mapView.delegate = self1920}2122override func viewDidLoad() {23super.viewDidLoad()24nbMapView = NGLMapView(frame:self.view.bounds)25}262728}29extension MapViewDelegateViewController: NGLMapViewDelegate {30/**31Tells the user that the map has just finished loading a style.32This method is called during the initialization of the map view and after any33subsequent loading of a new style. This method is called between the34`-mapViewWillStartRenderingMap:` and `-mapViewDidFinishRenderingMap:` delegate35methods. Changes to sources or layers of the current style do not cause this36method to be called.37This method is the earliest opportunity to modify the layout or appearance of38the 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*/42func mapView(_ mapView: NGLMapView, didFinishLoading style: NGLStyle){43let camera = NGLMapCamera(lookingAtCenter: CLLocationCoordinate2DMake(53.5511, 9.9937),44acrossDistance:1000,45pitch:0,46heading:0)47nbMapView.fly(to: camera)4849}5051/**52Asks the user whether the map view should be allowed to change from the53existing camera to the new camera in response to a user gesture.54This method is called as soon as the user gesture is recognized. It is not55called in response to a programmatic camera change, such as by setting the56`centerCoordinate` property or calling `-flyToCamera:completionHandler:`.57This method is called many times during gesturing, so you should avoid performing58complex 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 the61gesture is recognized. If this method returns `NO`, the map view's camera62continues to be this camera.63@param newCamera The expected camera after the gesture completes. If this64method returns `YES`, this camera becomes the map view's camera.65@return A Boolean value indicating whether the map view should stay at66`oldCamera` or change to `newCamera`.67*/68private func mapView(_ mapView: NGLMapView, shouldChangeFromCamera oldCamera: NGLMapCamera, to newCamera: NGLMapCamera ){697071}7273/**74Asks the user whether the map view should be allowed to change from the75existing camera to the new camera in response to a user gesture.76This method is called as soon as the user gesture is recognized. It is not77called in response to a programmatic camera change, such as by setting the78`centerCoordinate` property or calling `-flyToCamera:completionHandler:`.79This method is called many times during gesturing, so you should avoid performing80complex 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 the83gesture is recognized. If this method returns `NO`, the map view's camera84continues to be this camera.85@param newCamera The expected camera after the gesture completes. If this86method 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 at89`oldCamera` or transition to `newCamera`.90@note If this method is implemented `-mapView:shouldChangeFromCamera:toCamera:` will not be called.91*/92func mapView(_ mapView: NGLMapView, shouldChangeFrom oldCamera: NGLMapCamera, to newCamera: NGLMapCamera, reason: NGLCameraChangeReason) -> Bool {93return true94}9596/**97Tells the user that the viewpoint depicted by the map view is about to change.98This method is called whenever the currently displayed map camera will start99changing 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*/103func mapView(_ mapView: NGLMapView, regionWillChangeAnimated animated: Bool){104105106}107108/**109Tells the user that the viewpoint depicted by the map view is about to change.110This method is called whenever the currently displayed map camera will start111changing 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*/117func mapView(_ mapView: NGLMapView, regionWillChangeWith reason: NGLCameraChangeReason, animated: Bool){118119120}121122/**123Tells the user that the viewpoint depicted by the map view is changing.124This method is called as the currently displayed map camera changes as part of125an animation, whether due to a user gesture or due to a call to a method such126as `-[NGLMapView setCamera:animated:]`. This method can be called before127`-mapViewDidFinishLoadingMap:` is called.128During the animation, this method may be called many times to report updates to129the viewpoint. Therefore, your implementation of this method should be as lightweight130as possible to avoid affecting performance.131@param mapView The map view whose viewpoint is changing.132*/133func mapViewRegionIsChanging(_ mapView: NGLMapView){134135136}137138/**139Tells the user that the viewpoint depicted by the map view is changing.140This method is called as the currently displayed map camera changes as part of141an animation, whether due to a user gesture or due to a call to a method such142as `-[NGLMapView setCamera:animated:]`. This method can be called before143`-mapViewDidFinishLoadingMap:` is called.144During the animation, this method may be called many times to report updates to145the viewpoint. Therefore, your implementation of this method should be as lightweight146as 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*/151func mapView(_ mapView: NGLMapView, regionIsChangingWith reason: NGLCameraChangeReason){152153154}155156/**157Tells the user that the viewpoint depicted by the map view has finished158changing.159This method is called whenever the currently displayed map camera has finished160changing, after any calls to `-mapViewRegionIsChanging:` due to animation. Therefore,161this 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*/165func mapView(_ mapView: NGLMapView, regionDidChangeAnimated animated: Bool){166167168}169170/**171Tells the user that the viewpoint depicted by the map view has finished172changing.173This method is called whenever the currently displayed map camera has finished174changing, after any calls to `-mapViewRegionIsChanging:` due to animation. Therefore,175this 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*/181func mapView(_ mapView: NGLMapView, regionDidChangeWith reason: NGLCameraChangeReason, animated: Bool){182183184}185186// ##pragma mark Loading the Map187188/**189Tells the user that the map view will begin to load.190This method is called whenever the map view starts loading, including when a191new style has been set and the map must reload.192@param mapView The map view that is starting to load.193*/194func mapViewWillStartLoadingMap(_ mapView: NGLMapView) {195196}197198/**199Tells the user that the map view has finished loading.200This method is called whenever the map view finishes loading, either after the201initial load or after a style change has forced a reload.202@param mapView The map view that has finished loading.203*/204func mapViewDidFinishLoadingMap(_ mapView: NGLMapView) {205206}207208/**209Tells the user that the map view was unable to load data needed for210displaying the map.211This method may be called for a variety of reasons, including a network212connection failure or a failure to fetch the style from the server. You can use213the 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*/217func mapViewDidFailLoadingMap(_ apView: NGLMapView,withError error: Error) {218219}220221/**222Tells the user that the map view is about to redraw.223This method is called any time the map view needs to redraw due to a change in224the viewpoint or style property transition. This method may be called very225frequently, even moreso than `-mapViewRegionIsChanging:`. Therefore, your226implementation of this method should be as lightweight as possible to avoid227affecting performance.228@param mapView The map view that is about to redraw.229*/230func mapViewWillStartRenderingFrame(_ mapView: NGLMapView ) {231232}233234/**235Tells the user that the map view has just redrawn.236This method is called any time the map view needs to redraw due to a change in237the viewpoint or style property transition. This method may be called very238frequently, even moreso than `-mapViewRegionIsChanging:`. Therefore, your239implementation of this method should be as lightweight as possible to avoid240affecting performance.241@param mapView The map view that has just redrawn.242*/243func mapViewDidFinishRenderingFrame(_ mapView: NGLMapView,fullyRendered:Bool) {244245}246247/**248Tells the user that the map view is entering an idle state, and no more249drawing will be necessary until new data is loaded or there is some interaction250with the map.251252- No camera transitions are in progress253- All currently requested tiles have loaded254- All fade/transition animations have completed255256@param mapView The map view that has just entered the idle state.257*/258func mapViewDidBecomeIdle(_ mapView: NGLMapView ) {259260}261262func mapView(_ mapView: NGLMapView, didFailToLoadImage imageName: String) -> UIImage? {263return nil264}265266/**267Asks the user whether the map view should evict cached images.268269This method is called in two scenarios: when the cumulative size of unused images270exceeds the cache size or when the last tile that includes the image is removed from271memory.272273@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 evict276the cached image.277*/278func mapView(_ mapView: NGLMapView, shouldRemoveStyleImage imageName: String) -> Bool {279return true280}281282// #pragma mark Tracking User Location283284/**285Tells the user that the map view will begin tracking the user's location.286This method is called when the value of the `showsUserLocation` property287changes to `YES`.288@param mapView The map view that is tracking the user's location.289*/290func mapViewWillStartLocatingUser(_ mapView: NGLMapView) {291292}293294/**295Tells the user that the map view has stopped tracking the user's location.296This method is called when the value of the `showsUserLocation` property297changes to `NO`.298@param mapView The map view that is tracking the user's location.299*/300func mapViewDidStopLocatingUser(_ mapView: NGLMapView) {301302}303304305/**306Asks the user styling options for each default user location annotation view.307308This method is called many times during gesturing, so you should avoid performing309complex or performance-intensive tasks in your implementation.310311@param mapView The map view that is tracking the user's location.312*/313func mapView(styleForDefaultUserLocationAnnotationView mapView: NGLMapView) -> NGLUserLocationAnnotationViewStyle {314let locationStyle = NGLUserLocationAnnotationViewStyle()315/**316The fill color for the puck view.317*/318locationStyle.puckFillColor = UIColor.blue319/**320The shadow color for the puck view.321*/322locationStyle.puckShadowColor = UIColor.red323/**324The shadow opacity for the puck view.325Set any value between 0.0 and 1.0.326The default value of this property is equal to `0.25`327*/328locationStyle.puckShadowOpacity = 0.25329/**330The fill color for the arrow puck.331*/332locationStyle.puckArrowFillColor = UIColor.black333/**334The fill color for the puck view.335*/336locationStyle.haloFillColor = UIColor.white337338if #available(iOS 14, *) {339/**340The halo fill color for the approximate view.341*/342locationStyle.approximateHaloFillColor = UIColor.white343/**344The halo border color for the approximate view.345*/346locationStyle.approximateHaloBorderColor = UIColor.white347/**348The halo border width for the approximate view.349The default value of this property is equal to `2.0`350*/351locationStyle.approximateHaloBorderWidth = 2.0352/**353The halo opacity for the approximate view.354Set any value between 0.0 and 1.0355The default value of this property is equal to `0.15`356*/357locationStyle.approximateHaloOpacity = 0.15358}359360return locationStyle361}362363/**364Tells the user that the location of the user was updated.365While the `showsUserLocation` property is set to `YES`, this method is called366whenever a new location update is received by the map view. This method is also367called if the map view's user tracking mode is set to368`NGLUserTrackingModeFollowWithHeading` and the heading changes, or if it is set369to `NGLUserTrackingModeFollowWithCourse` and the course changes.370This method is not called if the application is currently running in the371background. If you want to receive location updates while running in the372background, you must use the Core Location framework.373private @param mapView The map view that is tracking the user's location.374@param userLocation The location object representing the user's latest375location. This property may be `nil`.376*/377func mapView(_ mapView: NGLMapView, didUpdate userLocation: NGLUserLocation?) {378379}380381/**382Tells 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 tracking385failed.386*/387func mapView(_ mapView: NGLMapView, didFailToLocateUserWithError error: Error) {388389}390391392/**393Tells the user that the map view's user tracking mode has changed.394This method is called after the map view asynchronously changes to reflect the395new user tracking mode, for example by beginning to zoom or rotate.396private @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*/400func mapView(_ mapView: NGLMapView, didChange mode: NGLUserTrackingMode, animated: Bool ) {401402}403404/**405Returns a screen coordinate at which to position the user location annotation.406This coordinate is relative to the map view's origin after applying the map view's407content insets.408When unimplemented, the user location annotation is aligned within the center of409the map view with respect to the content insets.410This method will override any values set by `NGLMapView.userLocationVerticalAlignment`411or `-[NGLMapView setUserLocationVerticalAlignment:animated:]`.412@param mapView The map view that is tracking the user's location.413414We don't need to set the anchor point for now, so comment out this method first415*/416// func mapViewUserLocationAnchorPoint(_ mapView: NGLMapView ) -> CGPoint {417// return nil418// }419/**420Tells the user that the map's location updates accuracy authorization has changed.421422This method is called after the user changes location accuracy authorization when423requesting location permissions or in privacy settings.424425@param mapView The map view that changed its location accuracy authorization.426@param manager The location manager reporting the update.427428*/429func mapView(_ apView: NGLMapView, didChangeLocationManagerAuthorization manager: NGLLocationManager) {430431}432433434// #pragma mark Managing the Appearance of Annotations435/**436Returns an annotation image object to mark the given point annotation object on437the map.438Implement this method to mark a point annotation with a static image. If you439want to mark a particular point annotation with an annotation view instead,440omit this method or have it return `nil` for that annotation, then implement441`-mapView:viewForAnnotation:`.442Static annotation images use less memory and draw more quickly than annotation443views. On the other hand, annotation views are compatible with UIKit, Core444Animation, 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 be447displayed.448@return The annotation image object to display for the given annotation or449`nil` if you want to display the default marker image or an annotation view.450*/451func mapView(_ mapView: NGLMapView, imageFor annotation: NGLAnnotation) -> NGLAnnotationImage? {452return nil453}454/**455Returns the alpha value to use when rendering a shape annotation.456A value of `0.0` results in a completely transparent shape. A value of `1.0`,457the default, results in a completely opaque shape.458This method sets the opacity of an entire shape, inclusive of its stroke and459fill. To independently set the values for stroke or fill, specify an alpha460component in the color returned by `-mapView:strokeColorForShapeAnnotation:` or461`-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*/466func mapView(_ mapView: NGLMapView, alphaForShapeAnnotation annotation: NGLShape) -> CGFloat {467return 1.0468}469/**470Returns the color to use when rendering the outline of a shape annotation.471The default stroke color is the map view's tint color. If a pattern color is472specified, the result is undefined.473Opacity may be set by specifying an alpha component. The default alpha value is474`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*/479func mapView(_ mapView: NGLMapView, strokeColorForShapeAnnotation annotation: NGLShape) -> UIColor {480return UIColor.red481}482/**483Returns the color to use when rendering the fill of a polygon annotation.484The default fill color is the map view's tint color. If a pattern color is485specified, the result is undefined.486Opacity may be set by specifying an alpha component. The default alpha value is487`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*/492493func mapView(_ mapView: NGLMapView, fillColorForPolygonAnnotation annotation: NGLPolygon) -> UIColor {494return UIColor.red495}496497/**498Returns the line width in points to use when rendering the outline of a499polyline annotation.500By 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*/505func mapView(_ mapView: NGLMapView, lineWidthForPolylineAnnotation annotation: NGLPolyline) -> CGFloat {506return 3.0507}508// #pragma mark Managing Annotation Views509/**510Returns a view object to mark the given point annotation object on the map.511Implement this method to mark a point annotation with a view object. If you512want to mark a particular point annotation with a static image instead, omit513this method or have it return `nil` for that annotation, then implement514`-mapView:imageForAnnotation:` instead.515Annotation views are compatible with UIKit, Core Animation, and other Cocoa516Touch frameworks. On the other hand, static annotation images use less memory517and draw more quickly than annotation views.518The user location annotation view can also be customized via this method. When519`annotation` is an instance of `NGLUserLocation` (or equal to the map view's520`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 be524displayed.525@return The view object to display for the given annotation or `nil` if you526want to display an annotation image instead.527*/528func mapView(_ mapView: NGLMapView, viewFor annotation: NGLAnnotation) -> NGLAnnotationView? {529return nil530}531532/**533Tells the user that one or more annotation views have been added and534positioned on the map.535This method is called just after the views are added to the map. You can536implement 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 the539views that were added.540*/541func mapView(mapView: NGLMapView, didAddAnnotationViews annotationViews: [NGLAnnotation]) {542543}544545// #pragma mark Selecting Annotations546/**547Returns a Boolean value indicating whether the shape annotation can be selected.548If the return value is `YES`, the user can select the annotation by tapping549on 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*/554func mapView(_ mapView: NGLMapView, shapeAnnotationIsEnabled annotation: NGLShape) -> Bool{555return true556}557558/**559Tells the user that one of its annotations was selected.560You can use this method to track changes in the selection state of annotations.561If the annotation is associated with an annotation view, you can also implement562`-mapView:didSelectAnnotationView:`, which is called immediately after this563method is called.564@param mapView The map view containing the annotation.565@param annotation The annotation that was selected.566*/567func mapView(_ mapView: NGLMapView, didSelect annotation: NGLAnnotation){568569}570/**571Tells the user that one of its annotations was deselected.572You can use this method to track changes in the selection state of annotations.573If the annotation is associated with an annotation view, you can also implement574`-mapView:didDeselectAnnotationView:`, which is called immediately after this575method is called.576@param mapView The map view containing the annotation.577@param annotation The annotation that was deselected.578*/579func mapView(_ mapView: NGLMapView, didDeselect annotation: NGLAnnotation){580581}582583/**584Tells the user that one of its annotation views was selected.585You can use this method to track changes in the selection state of annotation586views.587This method is only called for annotation views. To track changes in the588selection state of all annotations, including those associated with static589annotation images, implement `-mapView:didSelectAnnotation:`, which is called590immediately before this method is called.591@param mapView The map view containing the annotation.592@param annotationView The annotation view that was selected.593*/594func mapView(_ mapView: NGLMapView, didSelect annotationView: NGLAnnotationView){595596}597598/**599Tells the user that one of its annotation views was deselected.600You can use this method to track changes in the selection state of annotation601views.602This method is only called for annotation views. To track changes in the603selection state of all annotations, including those associated with static604annotation images, implement `-mapView:didDeselectAnnotation:`, which is called605immediately before this method is called.606@param mapView The map view containing the annotation.607@param annotationView The annotation view that was deselected.608*/609func mapView(_ mapView: NGLMapView, didDeselect annotationView: NGLAnnotationView){610611}612// #pragma mark Managing Callout Views613/**614Returns a Boolean value indicating whether the annotation is able to display615extra information in a callout bubble.616This method is called after an annotation is selected, before any callout is617displayed for the annotation.618If the return value is `YES`, a callout view is shown when the user taps on an619annotation, selecting it. The default callout displays the annotation's title620and subtitle. You can add accessory views to either end of the callout by621implementing the `-mapView:leftCalloutAccessoryViewForAnnotation:` and622`-mapView:rightCalloutAccessoryViewForAnnotation:` methods. You can further623customize the callout's contents by implementing the624`-mapView:calloutViewForAnnotation:` method.625If the return value is `NO`, or if this method is absent from the delegate, or626if the annotation lacks a title, the annotation will not show a callout even627when 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 a631callout.632*/633func mapView(_ mapView: NGLMapView, annotationCanShowCallout annotation: NGLAnnotation) -> Bool{634return true635}636637/**638Returns a callout view to display for the given annotation.639If this method is present in the delegate, it must return a new instance of a640view dedicated to display the callout. The returned view will be configured by641the map view.642If this method is absent from the delegate, or if it returns `nil`, a standard,643two-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 the647default callout view.648*/649func mapView(_ mapView: NGLMapView, calloutViewFor annotation: NGLAnnotation) -> NGLCalloutView? {650return nil651}652653/**654Returns the view to display on the left side of the standard callout bubble.655The left callout view is typically used to convey information about the656annotation or to link to custom information provided by your application.657If the view you specify is a descendant of the `UIControl` class, you can use658the map view's delegate to receive notifications when your control is tapped,659by implementing the `-mapView:annotation:calloutAccessoryControlTapped:`660method. If the view you specify does not descend from `UIControl`, your view is661responsible for handling any touch events within its bounds.662If this method is absent from the delegate, or if it returns `nil`, the663standard callout view has no accessory view on its left side. The return value664of this method is ignored if `-mapView:calloutViewForAnnotation:` is present in665the delegate.666To display a view on the callout's right side, implement the667`-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*/672func mapView(_ mapView: NGLMapView, leftCalloutAccessoryViewFor annotation: NGLAnnotation) -> UIView? {673return nil674}675676/**677Returns the view to display on the right side of the standard callout bubble.678The right callout view is typically used to convey information about the679annotation or to link to custom information provided by your application.680If the view you specify is a descendant of the `UIControl` class, you can use681the map view's delegate to receive notifications when your control is tapped,682by implementing the `-mapView:annotation:calloutAccessoryControlTapped:`683method. If the view you specify does not descend from `UIControl`, your view is684responsible for handling any touch events within its bounds.685If this method is absent from the delegate, or if it returns `nil`, the686standard callout view has no accessory view on its right side. The return value687of this method is ignored if `-mapView:calloutViewForAnnotation:` is present in688the delegate.689To display a view on the callout's left side, implement the690`-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*/695func mapView(_ mapView: NGLMapView, rightCalloutAccessoryViewFor annotation: NGLAnnotation) -> UIView? {696return nil697}698699/**700Tells the user that the user tapped one of the accessory controls in the701annotation's callout view.702In a standard callout view, accessory views contain custom content and are703positioned on either side of the annotation title text. If an accessory view704you specify is a descendant of the `UIControl` class, the map view calls this705method as a convenience whenever the user taps your view. You can use this706method to respond to taps and perform any actions associated with that control.707For example, if your control displays additional information about the708annotation, you could use this method to present a modal panel with that709information.710If your custom accessory views are not descendants of the `UIControl` class,711the map view does not call this method. If the annotation has a custom callout712view via the `-mapView:calloutViewForAnnotation:` method, you can specify the713custom accessory views using the `NGLCalloutView` protocol's714`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*/719func mapView(_ mapView: NGLMapView, calloutAccessoryControlTapped control: UIControl){720721}722723/**724Tells the user that the user tapped on an annotation's callout view.725This method is called when the user taps on the body of the callout view, as726opposed to the callout's left or right accessory view. If the annotation has a727custom callout view via the `-mapView:calloutViewForAnnotation:` method, this728method is only called whenever the callout view calls its delegate's729`-[NGLCalloutViewDelegate calloutViewTapped:]` method.730If this method is present on the delegate, the standard callout view's body731momentarily highlights when the user taps it, whether or not this method does732anything 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*/736func mapView(_ mapView: NGLMapView, tapOnCalloutFor annotation: NGLAnnotation){737738}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.