This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathMGLMapView.h
1948 lines (1566 loc) · 87.6 KB
/
MGLMapView.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import <UIKit/UIKit.h>
#import "MGLCompassButton.h"
#import "MGLFoundation.h"
#import "MGLGeometry.h"
#import "MGLMapCamera.h"
#import "MGLTypes.h"
NS_ASSUME_NONNULL_BEGIN
@class MGLAnnotationView;
@class MGLAnnotationImage;
@class MGLUserLocation;
@class MGLPolyline;
@class MGLPolygon;
@class MGLShape;
@class MGLStyle;
@protocol MGLMapViewDelegate;
@protocol MGLAnnotation;
@protocol MGLOverlay;
@protocol MGLCalloutView;
@protocol MGLFeature;
@protocol MGLLocationManager;
/** Options for `MGLMapView.decelerationRate`. */
typedef CGFloat MGLMapViewDecelerationRate NS_TYPED_EXTENSIBLE_ENUM;
/** The default deceleration rate for a map view. */
FOUNDATION_EXTERN MGL_EXPORT const MGLMapViewDecelerationRate MGLMapViewDecelerationRateNormal;
/** A fast deceleration rate for a map view. */
FOUNDATION_EXTERN MGL_EXPORT const MGLMapViewDecelerationRate MGLMapViewDecelerationRateFast;
/** Disables deceleration in a map view. */
FOUNDATION_EXTERN MGL_EXPORT const MGLMapViewDecelerationRate MGLMapViewDecelerationRateImmediate;
/**
The vertical alignment of an annotation within a map view. Used with
`MGLMapView.userLocationVerticalAlignment`.
*/
typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) {
/** Aligns the annotation vertically in the center of the map view. */
MGLAnnotationVerticalAlignmentCenter = 0,
/** Aligns the annotation vertically at the top of the map view. */
MGLAnnotationVerticalAlignmentTop,
/** Aligns the annotation vertically at the bottom of the map view. */
MGLAnnotationVerticalAlignmentBottom,
};
/**
The position of scale bar, compass, logo and attribution in a map view. Used with
`MGLMapView.scaleBarPosition`,
`MGLMapView.compassViewPosition`,
`MGLMapView.logoViewPosition`,
`MGLMapView.attributionButtonPosition`.
*/
typedef NS_ENUM(NSUInteger, MGLOrnamentPosition) {
/** Place the ornament in the top left of the map view. */
MGLOrnamentPositionTopLeft = 0,
/** Place the ornament in the top right of the map view. */
MGLOrnamentPositionTopRight,
/** Place the ornament in the bottom left of the map view. */
MGLOrnamentPositionBottomLeft,
/** Place the ornament in the bottom right of the map view. */
MGLOrnamentPositionBottomRight,
};
/**
The mode used to track the user location on the map. Used with
`MGLMapView.userTrackingMode`.
#### Related examples
See the <a href="https://docs.mapbox.com/ios/maps/examples/user-tracking-mode/">
Switch between user tracking modes</a> example to learn how to toggle modes and
how each mode behaves.
*/
typedef NS_ENUM(NSUInteger, MGLUserTrackingMode) {
/** The map does not follow the user location. */
MGLUserTrackingModeNone = 0,
/** The map follows the user location. This tracking mode falls back
to `MGLUserTrackingModeNone` if the user pans the map view. */
MGLUserTrackingModeFollow,
/**
The map follows the user location and rotates when the heading changes.
The default user location annotation displays a fan-shaped indicator with
the current heading. The heading indicator represents the direction the
device is facing, which is sized according to the reported accuracy.
This tracking mode is disabled if the user pans the map view, but
remains enabled if the user zooms in. If the user rotates the map
view, this tracking mode will fall back to `MGLUserTrackingModeFollow`.
*/
MGLUserTrackingModeFollowWithHeading,
/**
The map follows the user location and rotates when the course changes.
Course represents the direction in which the device is traveling.
The default user location annotation shows a puck-shaped indicator
that rotates as the course changes.
This tracking mode is disabled if the user pans the map view, but
remains enabled if the user zooms in. If the user rotates the map view,
this tracking mode will fall back to `MGLUserTrackingModeFollow`.
*/
MGLUserTrackingModeFollowWithCourse,
};
/** Options for `MGLMapView.preferredFramesPerSecond`. */
typedef NSInteger MGLMapViewPreferredFramesPerSecond NS_TYPED_EXTENSIBLE_ENUM;
/**
The default frame rate. This can be either 30 FPS or 60 FPS, depending on
device capabilities.
*/
FOUNDATION_EXTERN MGL_EXPORT const MGLMapViewPreferredFramesPerSecond MGLMapViewPreferredFramesPerSecondDefault;
/** A conservative frame rate; typically 30 FPS. */
FOUNDATION_EXTERN MGL_EXPORT const MGLMapViewPreferredFramesPerSecond MGLMapViewPreferredFramesPerSecondLowPower;
/** The maximum supported frame rate; typically 60 FPS. */
FOUNDATION_EXTERN MGL_EXPORT const MGLMapViewPreferredFramesPerSecond MGLMapViewPreferredFramesPerSecondMaximum;
FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const MGLMissingLocationServicesUsageDescriptionException;
FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const MGLUserLocationAnnotationTypeException;
/**
An interactive, customizable map view with an interface similar to the one
provided by Apple’s MapKit.
Using `MGLMapView`, you can embed the map inside a view, allow users to
manipulate it with standard gestures, animate the map between different
viewpoints, and present information in the form of annotations and overlays.
The map view loads scalable vector tiles that conform to the
<a href="https://github.com/mapbox/vector-tile-spec">Mapbox Vector Tile Specification</a>.
It styles them with a style that conforms to the
<a href="https://www.mapbox.com/mapbox-gl-style-spec/">Mapbox Style Specification</a>.
Such styles can be designed in
<a href="https://www.mapbox.com/studio/">Mapbox Studio</a> and hosted on
mapbox.com.
A collection of Mapbox-hosted styles is available through the `MGLStyle`
class. These basic styles use
<a href="https://www.mapbox.com/developers/vector-tiles/mapbox-streets">Mapbox Streets</a>
or <a href="https://www.mapbox.com/satellite/">Mapbox Satellite</a> data
sources, but you can specify a custom style that makes use of your own data.
Mapbox-hosted vector tiles and styles require an API access token, which you
can obtain from the
<a href="https://www.mapbox.com/studio/account/tokens/">Mapbox account page</a>.
Access tokens associate requests to Mapbox’s vector tile and style APIs with
your Mapbox account. They also deter other developers from using your styles
without your permission.
Because `MGLMapView` loads asynchronously, several delegate methods are available
for receiving map-related updates. These methods can be used to ensure that certain operations
have completed before taking any additional actions. Information on these methods is located
in the `MGLMapViewDelegate` protocol documentation.
Adding your own gesture recognizer to `MGLMapView` will block the corresponding
gesture recognizer built into `MGLMapView`. To avoid conflicts, define which
gesture takes precedence. For example, you can create your own
`UITapGestureRecognizer` that will be invoked only if the default `MGLMapView`
tap gesture fails:
```swift
let mapTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(myCustomFunction))
for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer {
mapTapGestureRecognizer.require(toFail: recognizer)
}
mapView.addGestureRecognizer(mapTapGestureRecognizer)
```
@note You are responsible for getting permission to use the map data and for
ensuring that your use adheres to the relevant terms of use.
#### Related examples
See the <a href="https://docs.mapbox.com/ios/maps/examples/simple-map-view/">
Simple map view</a> example to learn how to initialize a basic `MGLMapView`.
*/
MGL_EXPORT
@interface MGLMapView : UIView
#pragma mark Creating Instances
/**
Initializes and returns a newly allocated map view with the specified frame
and the default style.
@param frame The frame for the view, measured in points.
@return An initialized map view.
*/
- (instancetype)initWithFrame:(CGRect)frame;
/**
Initializes and returns a newly allocated map view with the specified frame
and style URL.
@param frame The frame for the view, measured in points.
@param styleURL URL of the map style to display. The URL may be a full HTTP
or HTTPS URL, a Mapbox style URL
(`mapbox://styles/{user}/{style}`), or a path to a local file relative
to the application’s resource path. Specify `nil` for the default style.
@return An initialized map view.
#### Related examples
See the <a href="https://docs.mapbox.com/ios/maps/examples/custom-style/">
Apply a style designed in Mapbox Studio</a> example to learn how to
initialize an `MGLMapView` with a custom style. See the
<a href="https://docs.mapbox.com/ios/maps/examples/raster-styles/"> Apply a
style designed in Mapbox Studio Classic</a> example to learn how to intialize
an `MGLMapView` with a Studio Classic style _or_ a custom style JSON. See the
<a href="https://docs.mapbox.com/ios/maps/examples/source-custom-vector/"> Use
third-party vector tiles</a> example to learn how to initialize an
`MGLMapView` with a third-party tile source.
*/
- (instancetype)initWithFrame:(CGRect)frame styleURL:(nullable NSURL *)styleURL;
#pragma mark Accessing the Delegate
/**
The receiver’s delegate.
A map view sends messages to its delegate to notify it of changes to its
contents or the viewpoint. The delegate also provides information about
annotations displayed on the map, such as the styles to apply to individual
annotations.
*/
@property(nonatomic, weak, nullable) IBOutlet id<MGLMapViewDelegate> delegate;
#pragma mark Configuring the Map’s Appearance
/**
The style currently displayed in the receiver.
Unlike the `styleURL` property, this property is set to an object that allows
you to manipulate every aspect of the style locally.
If the style is loading, this property is set to `nil` until the style finishes
loading. If the style has failed to load, this property is set to `nil`.
Because the style loads asynchronously, you should manipulate it in the
`-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]` or
`-[MGLMapViewDelegate mapViewDidFinishLoadingMap:]` method. It is not possible
to manipulate the style before it has finished loading.
@note The default styles provided by Mapbox contain sources and layers with
identifiers that will change over time. Applications that use APIs that
manipulate a style’s sources and layers must first set the style URL to an
explicitly versioned style using a convenience method like
`+[MGLStyle outdoorsStyleURLWithVersion:]`, `MGLMapView`’s “Style URL”
inspectable in Interface Builder, or a manually constructed `NSURL`.
*/
@property (nonatomic, readonly, nullable) MGLStyle *style;
/**
URL of the style currently displayed in the receiver.
The URL may be a full HTTP or HTTPS URL, a Mapbox
style URL (`mapbox://styles/{user}/{style}`), or a path to a local file
relative to the application’s resource path.
If you set this property to `nil`, the receiver will use the default style
and this property will automatically be set to that style’s URL.
If you want to modify the current style without replacing it outright, or if
you want to introspect individual style attributes, use the `style` property.
#### Related examples
See the <a href="https://docs.mapbox.com/ios/maps/examples/switch-styles/">
Switch between map styles</a> example to learn how to change the style of
a map at runtime.
*/
@property (nonatomic, null_resettable) NSURL *styleURL;
/**
Reloads the style.
You do not normally need to call this method. The map view automatically
responds to changes in network connectivity by reloading the style. You may
need to call this method if you change the access token after a style has
loaded but before loading a style associated with a different Mapbox account.
This method does not bust the cache. Even if the style has recently changed on
the server, calling this method does not necessarily ensure that the map view
reflects those changes.
*/
- (IBAction)reloadStyle:(nullable id)sender;
/**
A Boolean value indicating whether the map may display scale information.
The scale bar may not be shown at all zoom levels. The scale bar becomes visible
when the maximum distance visible on the map view is less than 400 miles (800
kilometers). The zoom level where this occurs depends on the latitude at the map
view’s center coordinate, as well as the device screen width. At latitudes
farther from the equator, the scale bar becomes visible at lower zoom levels.
The unit of measurement is determined by the user's device locale.
The view controlled by this property is available at `scaleBar`. The default value
of this property is `NO`.
*/
@property (nonatomic, assign) BOOL showsScale;
/**
A control indicating the scale of the map. The scale bar is positioned in the
upper-left corner. Enable the scale bar via `showsScale`.
*/
@property (nonatomic, readonly) UIView *scaleBar;
/**
The position of the scale bar. The default value is `MGLOrnamentPositionTopLeft`.
*/
@property (nonatomic, assign) MGLOrnamentPosition scaleBarPosition;
/**
A `CGPoint` indicating the position offset of the scale bar.
*/
@property (nonatomic, assign) CGPoint scaleBarMargins;
/**
A control indicating the map’s direction and allowing the user to manipulate
the direction, positioned in the upper-right corner.
*/
@property (nonatomic, readonly) MGLCompassButton *compassView;
/**
The position of the compass view. The default value is `MGLOrnamentPositionTopRight`.
*/
@property (nonatomic, assign) MGLOrnamentPosition compassViewPosition;
/**
A `CGPoint` indicating the position offset of the compass.
*/
@property (nonatomic, assign) CGPoint compassViewMargins;
/**
The Mapbox logo, positioned in the lower-left corner.
@note The Mapbox terms of service, which governs the use of Mapbox-hosted
vector tiles and styles,
<a href="https://docs.mapbox.com/help/how-mapbox-works/attribution/">requires</a> most Mapbox
customers to display the Mapbox logo. If this applies to you, do not
hide this view or change its contents.
*/
@property (nonatomic, readonly) UIImageView *logoView;
/**
The position of the logo view. The default value is `MGLOrnamentPositionBottomLeft`.
*/
@property (nonatomic, assign) MGLOrnamentPosition logoViewPosition;
/**
A `CGPoint` indicating the position offset of the logo.
*/
@property (nonatomic, assign) CGPoint logoViewMargins;
/**
A view showing legally required copyright notices and telemetry settings,
positioned at the bottom-right of the map view.
If you choose to reimplement this view, assign the `-showAttribution:` method
as the action for your view to present the default notices and settings.
@note The Mapbox terms of service, which governs the use of Mapbox-hosted
vector tiles and styles,
<a href="https://www.mapbox.com/tos/#[FamaFama]">requires</a> these
copyright notices to accompany any map that features Mapbox-designed styles,
OpenStreetMap data, or other Mapbox data such as satellite or terrain
data. If that applies to this map view, do not hide this view or remove
any notices from it.
@note You are additionally
<a href="https://www.mapbox.com/tos/#[FamaFama]">required</a>
to provide users with the option to disable anonymous usage and location
sharing (telemetry). If this view is hidden, you must implement this
setting elsewhere in your app or via `Settings.bundle`. See our
<a href="https://docs.mapbox.com/help/how-mapbox-works/attribution/#mapbox-maps-sdk-for-ios">website</a> for
implementation help.
*/
@property (nonatomic, readonly) UIButton *attributionButton;
/**
The position of the attribution button. The default value is `MGLOrnamentPositionBottomRight`.
*/
@property (nonatomic, assign) MGLOrnamentPosition attributionButtonPosition;
/**
A `CGPoint` indicating the position offset of the attribution.
*/
@property (nonatomic, assign) CGPoint attributionButtonMargins;
/**
Show the attribution and telemetry action sheet.
This action is performed when the user taps on the attribution button provided
by default via the `attributionButton` property. If you implement a custom
attribution button, you should add this action to the button.
*/
- (IBAction)showAttribution:(id)sender;
/**
The preferred frame rate at which the map view is rendered.
The default value for this property is
`MGLMapViewPreferredFramesPerSecondDefault`, which will adaptively set the
preferred frame rate based on the capability of the user’s device to maintain
a smooth experience.
In addition to the provided `MGLMapViewPreferredFramesPerSecond` options, this
property can be set to arbitrary integer values.
@see `CADisplayLink.preferredFramesPerSecond`
*/
@property (nonatomic, assign) MGLMapViewPreferredFramesPerSecond preferredFramesPerSecond;
/**
A Boolean value indicating whether the map should prefetch tiles.
When this property is set to `YES`, the map view prefetches tiles designed for
a low zoom level and displays them until receiving more detailed tiles for the
current zoom level. The prefetched tiles typically contain simplified versions
of each shape, improving the map view’s perceived performance.
The default value of this property is `YES`.
*/
@property (nonatomic, assign) BOOL prefetchesTiles;
#pragma mark Displaying the User’s Location
/**
The object that this map view uses to start and stop the delivery of
location-related updates.
To receive the current user location, implement the
`-[MGLMapViewDelegate mapView:didUpdateUserLocation:]` and
`-[MGLMapViewDelegate mapView:didFailToLocateUserWithError:]` methods.
If setting this property to `nil` or if no custom manager is provided this
property is set to the default location manager.
`MGLMapView` uses a default location manager. If you want to substitute your
own location manager, you should do so by setting this property before setting
`showsUserLocation` to `YES`. To restore the default location manager,
set this property to `nil`.
*/
@property (nonatomic, null_resettable) id<MGLLocationManager> locationManager;
/**
A Boolean value indicating whether the map may display the user location.
Setting this property to `YES` causes the map view to use the Core Location
framework to find the current location. As long as this property is `YES`, the
map view continues to track the user’s location and update it periodically.
This property does not indicate whether the user’s position is actually visible
on the map, only whether the map view is allowed to display it. To determine
whether the user’s position is visible, use the `userLocationVisible` property.
The default value of this property is `NO`.
Your app must specify a value for `NSLocationWhenInUseUsageDescription` or
`NSLocationAlwaysUsageDescription` in its `Info.plist` to satisfy the
requirements of the underlying Core Location framework when enabling this
property.
If you implement a custom location manager, set the `locationManager` before
calling `showsUserLocation`.
*/
@property (nonatomic, assign) BOOL showsUserLocation;
/**
A Boolean value indicating whether the device’s current location is visible in
the map view.
Use `showsUserLocation` to control the visibility of the on-screen user
location annotation.
*/
@property (nonatomic, assign, readonly, getter=isUserLocationVisible) BOOL userLocationVisible;
/**
Returns the annotation object indicating the user’s current location.
*/
@property (nonatomic, readonly, nullable) MGLUserLocation *userLocation;
/**
The mode used to track the user location. The default value is
`MGLUserTrackingModeNone`.
Changing the value of this property updates the map view with an animated
transition. If you don’t want to animate the change, use the
`-setUserTrackingMode:animated:` method instead.
#### Related examples
See the <a href="https://docs.mapbox.com/ios/maps/examples/user-location-annotation/">
Customize the user location annotation</a> to learn how to customize the
default user location annotation shown by `MGLUserTrackingMode`.
*/
@property (nonatomic, assign) MGLUserTrackingMode userTrackingMode;
/**
Deprecated. Sets the mode used to track the user location, with an optional transition.
To specify a completion handler to execute after the animation finishes, use
the `-setUserTrackingMode:animated:completionHandler:` method.
@param mode The mode used to track the user location.
@param animated If `YES`, there is an animated transition from the current
viewport to a viewport that results from the change to `mode`. If `NO`, the
map view instantaneously changes to the new viewport. This parameter only
affects the initial transition; subsequent changes to the user location or
heading are always animated.
*/
- (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated __attribute__((deprecated("Use `-setUserTrackingMode:animated:completionHandler:` instead.")));
/**
Sets the mode used to track the user location, with an optional transition and
completion handler.
@param mode The mode used to track the user location.
@param animated If `YES`, there is an animated transition from the current
viewport to a viewport that results from the change to `mode`. If `NO`, the
map view instantaneously changes to the new viewport. This parameter only
affects the initial transition; subsequent changes to the user location or
heading are always animated.
@param completion The block executed after the animation finishes.
*/
- (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion;
/**
The vertical alignment of the user location annotation within the receiver. The
default value is `MGLAnnotationVerticalAlignmentCenter`.
Changing the value of this property updates the map view with an animated
transition. If you don’t want to animate the change, use the
`-setUserLocationVerticalAlignment:animated:` method instead.
*/
@property (nonatomic, assign) MGLAnnotationVerticalAlignment userLocationVerticalAlignment __attribute__((deprecated("Use `-[MGLMapViewDelegate mapViewUserLocationAnchorPoint:]` instead.")));
/**
Sets the vertical alignment of the user location annotation within the
receiver, with an optional transition.
@param alignment The vertical alignment of the user location annotation.
@param animated If `YES`, the user location annotation animates to its new
position within the map view. If `NO`, the user location annotation
instantaneously moves to its new position.
*/
- (void)setUserLocationVerticalAlignment:(MGLAnnotationVerticalAlignment)alignment animated:(BOOL)animated __attribute__((deprecated("Use `-[MGLMapViewDelegate mapViewUserLocationAnchorPoint:]` instead.")));
/**
Updates the position of the user location annotation view by retreiving the user's last
known location.
*/
- (void)updateUserLocationAnnotationView;
/**
Updates the position of the user location annotation view by retreiving the user's last
known location with a specified duration.
@param duration The duration to animate the change in seconds.
*/
- (void)updateUserLocationAnnotationViewAnimatedWithDuration:(NSTimeInterval)duration;
/**
A Boolean value indicating whether the user location annotation may display a
permanent heading indicator.
Setting this property to `YES` causes the default user location annotation to
appear and always show an arrow-shaped heading indicator, if heading is
available. This property does not rotate the map; for that, see
`MGLUserTrackingModeFollowWithHeading`.
This property has no effect when `userTrackingMode` is
`MGLUserTrackingModeFollowWithHeading` or
`MGLUserTrackingModeFollowWithCourse`.
The default value of this property is `NO`.
*/
@property (nonatomic, assign) BOOL showsUserHeadingIndicator;
/**
Whether the map view should display a heading calibration alert when necessary.
The default value is `YES`.
*/
@property (nonatomic, assign) BOOL displayHeadingCalibration;
/**
The geographic coordinate that is the subject of observation as the user
location is being tracked.
By default, this property is set to an invalid coordinate, indicating that
there is no target. In course tracking mode, the target forms one of two foci
in the viewport, the other being the user location annotation. Typically, this
property is set to a destination or waypoint in a real-time navigation scene.
As the user annotation moves toward the target, the map automatically zooms in
to fit both foci optimally within the viewport.
This property has no effect if the `userTrackingMode` property is set to a
value other than `MGLUserTrackingModeFollowWithCourse`.
Changing the value of this property updates the map view with an animated
transition. If you don’t want to animate the change, use the
`-setTargetCoordinate:animated:` method instead.
*/
@property (nonatomic, assign) CLLocationCoordinate2D targetCoordinate;
/**
Deprecated. Sets the geographic coordinate that is the subject of observation as
the user location is being tracked, with an optional transition animation.
By default, the target coordinate is set to an invalid coordinate, indicating
that there is no target. In course tracking mode, the target forms one of two
foci in the viewport, the other being the user location annotation. Typically,
the target is set to a destination or waypoint in a real-time navigation scene.
As the user annotation moves toward the target, the map automatically zooms in
to fit both foci optimally within the viewport.
This method has no effect if the `userTrackingMode` property is set to a value
other than `MGLUserTrackingModeFollowWithCourse`.
To specify a completion handler to execute after the animation finishes, use
the `-setTargetCoordinate:animated:completionHandler:` method.
@param targetCoordinate The target coordinate to fit within the viewport.
@param animated If `YES`, the map animates to fit the target within the map
view. If `NO`, the map fits the target instantaneously.
*/
- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated __attribute__((deprecated("Use `-setTargetCoordinate:animated:completionHandler:` instead.")));
/**
Sets the geographic coordinate that is the subject of observation as the user
location is being tracked, with an optional transition animation and completion
handler.
By default, the target coordinate is set to an invalid coordinate, indicating
that there is no target. In course tracking mode, the target forms one of two
foci in the viewport, the other being the user location annotation. Typically,
the target is set to a destination or waypoint in a real-time navigation scene.
As the user annotation moves toward the target, the map automatically zooms in
to fit both foci optimally within the viewport.
This method has no effect if the `userTrackingMode` property is set to a value
other than `MGLUserTrackingModeFollowWithCourse`.
@param targetCoordinate The target coordinate to fit within the viewport.
@param animated If `YES`, the map animates to fit the target within the map
view. If `NO`, the map fits the target instantaneously.
@param completion The block executed after the animation finishes.
*/
- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion;
#pragma mark Configuring How the User Interacts with the Map
/**
A Boolean value that determines whether the user may zoom the map in and
out, changing the zoom level.
When this property is set to `YES`, the default, the user may zoom the map
in and out by pinching two fingers or by double tapping, holding, and moving
the finger up and down.
This property controls only user interactions with the map. If you set the
value of this property to `NO`, you may still change the map zoom
programmatically.
*/
@property(nonatomic, getter=isZoomEnabled) BOOL zoomEnabled;
/**
A Boolean value that determines whether the user may scroll around the map,
changing the center coordinate.
When this property is set to `YES`, the default, the user may scroll the map
by dragging or swiping with one finger.
This property controls only user interactions with the map. If you set the
value of this property to `NO`, you may still change the map location
programmatically.
*/
@property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
/**
A Boolean value that determines whether the user may rotate the map,
changing the direction.
When this property is set to `YES`, the default, the user may rotate the map
by moving two fingers in a circular motion.
This property controls only user interactions with the map. If you set the
value of this property to `NO`, you may still rotate the map
programmatically.
*/
@property(nonatomic, getter=isRotateEnabled) BOOL rotateEnabled;
/**
A Boolean value that determines whether the user may change the pitch (tilt) of
the map.
When this property is set to `YES`, the default, the user may tilt the map by
vertically dragging two fingers.
This property controls only user interactions with the map. If you set the
value of this property to `NO`, you may still change the pitch of the map
programmatically.
The default value of this property is `YES`.
*/
@property(nonatomic, getter=isPitchEnabled) BOOL pitchEnabled;
/**
A Boolean value that determines whether the user will receive haptic feedback
for certain interactions with the map.
When this property is set to `YES`, the default, a `UIImpactFeedbackStyleLight`
haptic feedback event be played when the user rotates the map to due north
(0°).
This feature requires a device that supports haptic feedback, running iOS 10 or
newer.
*/
@property(nonatomic, getter=isHapticFeedbackEnabled) BOOL hapticFeedbackEnabled;
/**
A floating-point value that determines the rate of deceleration after the user
lifts their finger.
Your application can use the `MGLMapViewDecelerationRateNormal` and
`MGLMapViewDecelerationRateFast` constants as reference points for reasonable
deceleration rates. `MGLMapViewDecelerationRateImmediate` can be used to
disable deceleration entirely.
*/
@property(nonatomic) CGFloat decelerationRate;
#pragma mark Manipulating the Viewpoint
/**
The geographic coordinate at the center of the map view.
Changing the value of this property centers the map on the new coordinate
without changing the current zoom level.
Changing the value of this property updates the map view immediately. If you
want to animate the change, use the `-setCenterCoordinate:animated:` method
instead.
*/
@property (nonatomic) CLLocationCoordinate2D centerCoordinate;
/**
Changes the center coordinate of the map and optionally animates the change.
Changing the center coordinate centers the map on the new coordinate without
changing the current zoom level. For animated changes, wait until the map view has
finished loading before calling this method.
@param coordinate The new center coordinate for the map.
@param animated Specify `YES` if you want the map view to scroll to the new
location or `NO` if you want the map to display the new location
immediately.
@note The behavior of this method is undefined if called in response to
`UIApplicationWillTerminateNotification`.
*/
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated;
/**
Changes the center coordinate and zoom level of the map and optionally animates
the change. For animated changes, wait until the map view has
finished loading before calling this method.
@param centerCoordinate The new center coordinate for the map.
@param zoomLevel The new zoom level for the map.
@param animated Specify `YES` if you want the map view to animate scrolling and
zooming to the new location or `NO` if you want the map to display the new
location immediately.
@note The behavior of this method is undefined if called in response to
`UIApplicationWillTerminateNotification`.
*/
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel animated:(BOOL)animated;
/**
Changes the center coordinate, zoom level, and direction of the map and
optionally animates the change. For animated changes, wait until the map view has
finished loading before calling this method.
@param centerCoordinate The new center coordinate for the map.
@param zoomLevel The new zoom level for the map.
@param direction The new direction for the map, measured in degrees relative to
true north. A negative value leaves the map’s direction unchanged.
@param animated Specify `YES` if you want the map view to animate scrolling,
zooming, and rotating to the new location or `NO` if you want the map to
display the new location immediately.
@note The behavior of this method is undefined if called in response to
`UIApplicationWillTerminateNotification`.
*/
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel direction:(CLLocationDirection)direction animated:(BOOL)animated;
/**
Changes the center coordinate, zoom level, and direction of the map, calling a
completion handler at the end of an optional animation. For animated changes,
wait until the map view has finished loading before calling this method.
@param centerCoordinate The new center coordinate for the map.
@param zoomLevel The new zoom level for the map.
@param direction The new direction for the map, measured in degrees relative to
true north. A negative value leaves the map’s direction unchanged.
@param animated Specify `YES` if you want the map view to animate scrolling,
zooming, and rotating to the new location or `NO` if you want the map to
display the new location immediately.
@param completion The block executed after the animation finishes.
@note The behavior of this method is undefined if called in response to
`UIApplicationWillTerminateNotification`.
*/
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(double)zoomLevel direction:(CLLocationDirection)direction animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion;
/** The zoom level of the receiver.
In addition to affecting the visual size and detail of features on the map,
the zoom level affects the size of the vector tiles that are loaded. At zoom
level 0, each tile covers the entire world map; at zoom level 1, it covers ¼
of the world; at zoom level 2, <sup>1</sup>⁄<sub>16</sub> of the world, and
so on.
Changing the value of this property updates the map view immediately. If you
want to animate the change, use the `-setZoomLevel:animated:` method instead.
*/
@property (nonatomic) double zoomLevel;
/**
Changes the zoom level of the map and optionally animates the change.
Changing the zoom level scales the map without changing the current center
coordinate.
@param zoomLevel The new zoom level for the map.
@param animated Specify `YES` if you want the map view to animate the change
to the new zoom level or `NO` if you want the map to display the new
zoom level immediately.
*/
- (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated;
/**
* The minimum zoom level at which the map can be shown.
*
* Depending on the map view’s aspect ratio, the map view may be prevented
* from reaching the minimum zoom level, in order to keep the map from
* repeating within the current viewport.
*
* If the value of this property is greater than that of the
* maximumZoomLevel property, the behavior is undefined.
*
* The default minimumZoomLevel is 0.
*/
@property (nonatomic) double minimumZoomLevel;
/**
* The maximum zoom level the map can be shown at.
*
* If the value of this property is smaller than that of the
* minimumZoomLevel property, the behavior is undefined.
*
* The default maximumZoomLevel is 22. The upper bound for this property
* is 25.5.
*/
@property (nonatomic) double maximumZoomLevel;
/**
The heading of the map, measured in degrees clockwise from true north.
The value `0` means that the top edge of the map view corresponds to true
north. The value `90` means the top of the map is pointing due east. The
value `180` means the top of the map points due south, and so on.
Changing the value of this property updates the map view immediately. If you
want to animate the change, use the `-setDirection:animated:` method instead.
*/
@property (nonatomic) CLLocationDirection direction;
/**
Changes the heading of the map and optionally animates the change.
@param direction The heading of the map, measured in degrees clockwise from
true north.
@param animated Specify `YES` if you want the map view to animate the change
to the new heading or `NO` if you want the map to display the new
heading immediately.
Changing the heading rotates the map without changing the current center
coordinate or zoom level.
*/
- (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated;
/**
Resets the map rotation to a northern heading — a `direction` of `0` degrees.
*/
- (IBAction)resetNorth;
/**
Resets the map to the current style’s default viewport.
If the style doesn’t specify a default viewport, the map resets to a minimum
zoom level, a center coordinate of (0, 0), and a northern heading.
*/
- (IBAction)resetPosition;
/**
The coordinate bounds visible in the receiver’s viewport.
Changing the value of this property updates the receiver immediately. If you
want to animate the change, call `-setVisibleCoordinateBounds:animated:`
instead.
If a longitude is less than −180 degrees or greater than 180 degrees, the
visible bounds straddles the antimeridian or international date line. For
example, if both Tokyo and San Francisco are visible, the visible bounds might
extend from (35.68476, −220.24257) to (37.78428, −122.41310).
*/
@property (nonatomic) MGLCoordinateBounds visibleCoordinateBounds;
/**
Changes the receiver’s viewport to fit the given coordinate bounds,
optionally animating the change.
To bring both sides of the antimeridian or international date line into view,
specify some longitudes less than −180 degrees or greater than 180 degrees. For
example, to show both Tokyo and San Francisco simultaneously, you could set the
visible bounds to extend from (35.68476, −220.24257) to (37.78428, −122.41310).
@param bounds The bounds that the viewport will show in its entirety.
@param animated Specify `YES` to animate the change by smoothly scrolling
and zooming or `NO` to immediately display the given bounds.
*/
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated;
/**
Deprecated. Changes the receiver’s viewport to fit the given coordinate bounds with
some additional padding on each side.
To bring both sides of the antimeridian or international date line into view,
specify some longitudes less than −180 degrees or greater than 180 degrees. For
example, to show both Tokyo and San Francisco simultaneously, you could set the
visible bounds to extend from (35.68476, −220.24257) to (37.78428, −122.41310).
To specify a completion handler to execute after the animation finishes, use
the `-setVisibleCoordinateBounds:edgePadding:animated:completionHandler:` method.
@param bounds The bounds that the viewport will show in its entirety.
@param insets The minimum padding (in screen points) that will be visible
around the given coordinate bounds.
@param animated Specify `YES` to animate the change by smoothly scrolling and
zooming or `NO` to immediately display the given bounds.
*/
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated __attribute__((deprecated("Use `-setVisibleCoordinateBounds:edgePadding:animated:completionHandler:` instead.")));
/**
Changes the receiver’s viewport to fit the given coordinate bounds with some
additional padding on each side, optionally calling a completion handler.
To bring both sides of the antimeridian or international date line into view,
specify some longitudes less than −180 degrees or greater than 180 degrees. For
example, to show both Tokyo and San Francisco simultaneously, you could set the
visible bounds to extend from (35.68476, −220.24257) to (37.78428, −122.41310).
@param bounds The bounds that the viewport will show in its entirety.
@param insets The minimum padding (in screen points) that will be visible
around the given coordinate bounds.
@param animated Specify `YES` to animate the change by smoothly scrolling and
zooming or `NO` to immediately display the given bounds.
@param completion The block executed after the animation finishes.
*/
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion;
/**
Changes the receiver’s viewport to fit all of the given coordinates with some
additional padding on each side.
To bring both sides of the antimeridian or international date line into view,
specify some longitudes less than −180 degrees or greater than 180 degrees. For
example, to show both Tokyo and San Francisco simultaneously, you could set the
visible coordinates to (35.68476, −220.24257) and (37.78428, −122.41310).
@param coordinates The coordinates that the viewport will show.
@param count The number of coordinates. This number must not be greater than
the number of elements in `coordinates`.
@param insets The minimum padding (in screen points) that will be visible
around the given coordinate bounds.
@param animated Specify `YES` to animate the change by smoothly scrolling and
zooming or `NO` to immediately display the given bounds.
*/
- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
/**
Changes the receiver’s viewport to fit all of the given coordinates with some
additional padding on each side, optionally calling a completion handler.
To bring both sides of the antimeridian or international date line into view,
specify some longitudes less than −180 degrees or greater than 180 degrees. For
example, to show both Tokyo and San Francisco simultaneously, you could set the
visible coordinates to (35.68476, −220.24257) and (37.78428, −122.41310).