aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorM.Stephen <truestyle2005@163.com>2019-07-05 13:28:09 +0800
committerM.Stephen <truestyle2005@163.com>2019-07-05 13:28:09 +0800
commitfd32a396b9cd75b0f6bd214e8016a32d30262d42 (patch)
treec9c25938bb3461ab9835a08cb02b8410d43c5178
parent16f1854a9ca98c00a5058c55e8a59df2c3463f4d (diff)
[iOS] add a test view controllerupstream/stephen-annotation-auto-test
-rw-r--r--platform/ios/app/ViewController.m102
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj4
2 files changed, 106 insertions, 0 deletions
diff --git a/platform/ios/app/ViewController.m b/platform/ios/app/ViewController.m
new file mode 100644
index 000000000..b351149c5
--- /dev/null
+++ b/platform/ios/app/ViewController.m
@@ -0,0 +1,102 @@
+#import "ViewController.h"
+@import Mapbox;
+
+@interface MyCustomPointAnnotation : MGLPointAnnotation
+@property (nonatomic, assign) BOOL willUseImage;
+@end
+
+@implementation MyCustomPointAnnotation
+@end
+
+
+@interface ViewController () <MGLMapViewDelegate>
+
+@property (nonatomic, strong) MGLMapView *mapView;
+@property (nonatomic, strong) NSMutableArray *annotations;
+@property (nonatomic, strong) NSTimer *timer;
+
+@end
+
+@implementation ViewController
+
+@synthesize mapView;
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds
+ styleURL:[MGLStyle lightStyleURL]];
+
+ mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+
+ mapView.centerCoordinate = CLLocationCoordinate2DMake(36.54,-116.97);
+ mapView.zoomLevel = 9;
+ mapView.delegate = self;
+ [self.view addSubview:mapView];
+
+ _annotations = [NSMutableArray array];
+}
+
+- (int)getRandomNumber:(int)from to:(int)to
+{
+ return (int)(from + (arc4random() % (to - from + 1)));
+}
+
+- (NSString *)getRandomString{
+ char random[10];
+ for(int i = 0 ; i < 10 ; i++){
+ char p = [self getRandomNumber:65 to:122];
+ random[i] = p;
+ }
+ return [NSString stringWithCString:random encoding:NSUTF8StringEncoding];
+}
+
+- (void)addAnnotations{
+ [mapView removeAnnotations:_annotations];
+ [_annotations removeAllObjects];
+
+ for(int i = 0 ; i < 100; i++){
+ MyCustomPointAnnotation *pointD = [[MyCustomPointAnnotation alloc] init];
+ pointD.title = [self getRandomString];
+ pointD.coordinate = CLLocationCoordinate2DMake([self getRandomNumber:-90 to:90],[self getRandomNumber:-180 to:180]);
+ [_annotations addObject:pointD];
+ }
+ [mapView addAnnotations:_annotations];
+}
+
+- (void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView{
+ _timer = [NSTimer scheduledTimerWithTimeInterval:5.0f repeats:YES block:^(NSTimer * _Nonnull timer) {
+ [self addAnnotations];
+ [mapView setCenterCoordinate:CLLocationCoordinate2DMake([self getRandomNumber:-90 to:90],[self getRandomNumber:-180 to:180]) zoomLevel:[self getRandomNumber:1 to:3] animated:YES];
+ }];
+}
+
+
+- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id <MGLAnnotation>)annotation {
+ if ([annotation isKindOfClass:[MyCustomPointAnnotation class]]) {
+ MyCustomPointAnnotation *castAnnotation = (MyCustomPointAnnotation *)annotation;
+
+ if (castAnnotation.willUseImage) {
+ return nil;
+ }
+ }
+ NSString *reuseIdentifier = @"reusableDotView";
+ MGLAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
+
+ if (!annotationView) {
+ annotationView = [[MGLAnnotationView alloc] initWithReuseIdentifier:reuseIdentifier];
+ annotationView.frame = CGRectMake(0, 0, 30, 30);
+ annotationView.layer.cornerRadius = annotationView.frame.size.width / 2;
+ annotationView.layer.borderColor = [UIColor whiteColor].CGColor;
+ annotationView.layer.borderWidth = 4.0;
+ annotationView.backgroundColor = [UIColor colorWithRed:0.03 green:0.80 blue:0.69 alpha:1.0];
+ }
+
+ return annotationView;
+}
+
+- (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id<MGLAnnotation>)annotation {
+ return YES;
+}
+
+@end
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 7c2935fc5..3ccbf90cd 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -515,6 +515,7 @@
CABE5DAD2072FAB40003AF3C /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA8847D21CBAF91600AB86E3 /* Mapbox.framework */; };
CAD9D0AA22A86D6F001B25EE /* MGLResourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CAD9D0A922A86D6F001B25EE /* MGLResourceTests.mm */; };
CAE7AD5520F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAE7AD5420F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift */; };
+ CF75A90D22CF17000058A5C4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CF75A90C22CF17000058A5C4 /* ViewController.m */; };
DA00FC8E1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA00FC8F1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA00FC901D5EEB0D009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */; };
@@ -1190,6 +1191,7 @@
CAD9D0A922A86D6F001B25EE /* MGLResourceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLResourceTests.mm; path = ../../darwin/test/MGLResourceTests.mm; sourceTree = "<group>"; };
CAE7AD5320F46EF5003B6782 /* integration-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "integration-Bridging-Header.h"; sourceTree = "<group>"; };
CAE7AD5420F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MGLMapSnapshotterSwiftTests.swift; sourceTree = "<group>"; };
+ CF75A90C22CF17000058A5C4 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = "<group>"; };
DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = "<group>"; };
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = "<group>"; };
@@ -1942,6 +1944,7 @@
DA1DC94C1CB6C1C2006E619F /* Demo App */ = {
isa = PBXGroup;
children = (
+ CF75A90C22CF17000058A5C4 /* ViewController.m */,
3E6465D52065767A00685536 /* LimeGreenStyleLayer.h */,
3E6465D42065767A00685536 /* LimeGreenStyleLayer.m */,
DA1DC9501CB6C1C2006E619F /* MBXAppDelegate.h */,
@@ -3200,6 +3203,7 @@
DA1DC96A1CB6C6B7006E619F /* MBXCustomCalloutView.m in Sources */,
075AF842227B6762008D7A4C /* MBXState.m in Sources */,
927FBCFC1F4DAA8300F8BF1F /* MBXSnapshotsViewController.m in Sources */,
+ CF75A90D22CF17000058A5C4 /* ViewController.m in Sources */,
DA1DC99B1CB6E064006E619F /* MBXViewController.m in Sources */,
40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */,
1F26B6C120E189C9007BCC21 /* MBXCustomLocationViewController.m in Sources */,