-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPointAnnotationClusteringExample.m
106 lines (83 loc) · 3.91 KB
/
PointAnnotationClusteringExample.m
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
//
// PointAnnotationClusteringExample.m
// mapboxqs
//
// Created by Tuyen Vu on 11/03/2023.
//
#import "PointAnnotationClusteringExample.h"
#import <MapboxMaps/MapboxMaps.h>
#import <MapboxCoreMaps/MapboxCoreMaps.h>
#import <MapboxMapObjC/MapboxMapObjC.h>
#import "MapboxMaps-Swift.h"
@interface PointAnnotationClusteringExample ()
@end
@implementation PointAnnotationClusteringExample {
MapView* mapView;
NSMutableSet<TMBCancelable*>* cancelables;
}
- (void)viewDidLoad {
[super viewDidLoad];
cancelables = [NSMutableSet new];
// Center the map over Washington, D.C.
CLLocationCoordinate2D centerLocation = CLLocationCoordinate2DMake(38.889215, -77.039354);
TMBCameraOptions* cameraOptions = [[TMBCameraOptions alloc] initWithCenter:centerLocation padding:UIEdgeInsetsMake(0, 0, 0, 0) anchor:CGPointMake(0, 0) zoom:11 bearing:0 pitch:0];
MapInitOptions* options = [MapInitOptionsFactory createWithMapOptions:nil cameraOptions:cameraOptions styleURI:BuiltInStyles.light styleJSON:nil antialiasingSampleCount:1];
mapView = [MapViewFactory createWithFrame:self.view.bounds
options:options];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:mapView];
__weak PointAnnotationClusteringExample *weakSelf = self;
// // Add an additional target to the single tap gesture recognizer for when users click on a cluster
// mapView.gestures.singleTapGestureRecognizer.addTarget(self, action: #selector(handleTap(gestureRecognizer:)))
// Add the source and style layers once the map has loaded.
[cancelables addObject: [[mapView mapboxMap] onMapLoaded:^(id _Nonnull _) {
[weakSelf addPointAnnotations];
}]];
}
- (void) addPointAnnotations {
// The image named `fire-station-11` is included in the app's Assets.xcassets bundle.
UIImage *image = [UIImage imageNamed: @"fire-station-11"];
// Fire_Hydrants.geojson contains information about fire hydrants in Washington, D.C.
// It was downloaded on 6/10/21 from https://opendata.dc.gov/datasets/DCGIS::fire-hydrants/about
// Decode the GeoJSON into a feature collection on a background thread
[NSBundle.mainBundle URLForResource:@"Fire_Hydrants" withExtension: @"geojson"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
});
// DispatchQueue.global(qos: .userInitiated).async {
// guard let featureCollection = try? self.decodeGeoJSON(from: "Fire_Hydrants") else {
// return
// }
//
// // Create an array of annotations for each fire hydrant
// var annotations = [PointAnnotation]()
// for feature in featureCollection.features {
// guard let geometry = feature.geometry, case let Geometry.point(point) = geometry else {
// return
// }
// var pointAnnotation = PointAnnotation(coordinate: point.coordinates)
// pointAnnotation.image = .init(image: image, name: "fire-station-11")
// annotations.append(pointAnnotation)
// }
// DispatchQueue.main.async {
// self.createClusters(annotations: annotations)
// }
// }
}
// Load GeoJSON file from local bundle and decode into a `FeatureCollection`.
- (void) decodeGeoJSONWithFileName: (NSString* ) fileName {
NSString* path = [NSBundle.mainBundle pathForResource:fileName ofType:@"geojson"];
if (!path) {
NSLog(@"%@ not found", fileName);
return;
}
NSURL* filePath = [NSURL fileURLWithPath:path];
// var featureCollection: FeatureCollection?
// do {
// let data = try Data(contentsOf: filePath)
// featureCollection = try JSONDecoder().decode(FeatureCollection.self, from: data)
// } catch {
// print("Error parsing data: \(error)")
// }
// return featureCollection
}
@end