-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTerrainExample.m
119 lines (95 loc) · 3.73 KB
/
TerrainExample.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
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// TerrainExample.m
// mapboxqs
//
// Created by Tuyen Vu on 11/03/2023.
//
#import "TerrainExample.h"
#import <MapboxMaps/MapboxMaps.h>
#import <MapboxCoreMaps/MapboxCoreMaps.h>
#import <MapboxMapObjC/MapboxMapObjC.h>
#import "MapboxMaps-Swift.h"
#import "ExampleProtocol.h"
@interface TerrainExample () <ExampleProtocol>
@property MapView* mapView;
- (void) addTerrain;
@end
@implementation TerrainExample
- (void)viewDidLoad {
[super viewDidLoad];
CLLocationCoordinate2D centerLocation = CLLocationCoordinate2DMake(32.6141, -114.34411);
TMBCameraOptions* cameraOptions = [[TMBCameraOptions alloc] initWithCenter:centerLocation padding:UIEdgeInsetsMake(0, 0, 0, 0) anchor:CGPointMake(0, 0) zoom:13.1 bearing:80 pitch:85];
MapInitOptions* options = [MapInitOptionsFactory
createWithMapOptions:nil
cameraOptions:cameraOptions
styleURI:@"mapbox://styles/mapbox-map-design/ckhqrf2tz0dt119ny6azh975y"
styleJSON:nil
antialiasingSampleCount:1];
MapView* mapView = [MapViewFactory createWithFrame:self.view.bounds
options:options];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
__weak TerrainExample *weakSelf = self;
[[mapView mapboxMap] onStyleLoaded:^(id _Nonnull) {
[weakSelf addTerrain];
if ([weakSelf respondsToSelector:@selector(finish)]) {
[weakSelf finish];
}
}];
self.mapView = mapView;
[self.view addSubview:mapView];
}
- (TMBSkyLayer*) createSkyLayer {
TMBSkyLayer* layer = [[TMBSkyLayer alloc] initWithId:@"sky-layer"];
layer.skyType = [TMBValue skyType:TMBSkyType.atmosphere];
layer.skyAtmosphereSun = [TMBValue constant: @[@0.0, @0.0]];
layer.skyAtmosphereSunIntensity = [TMBValue constant: @15.0];
return layer;
}
- (void) addTerrain {
NSString* sourceId = @"mapbox-dem";
// Use builder
// [self.mapView addRasterDemSource: sourceId
// configure:^(RasterDemSourceBuilder * _Nonnull builder) {
// [builder url:@"mapbox://mapbox.mapbox-terrain-dem-v1"];
// [builder tileSize:514.0];
// [builder maxzoom:14.0];
// }
// onError:nil];
[[self.mapView mapboxMap] addSourceWithId:sourceId
properties:@{
@"type": @"raster-dem",
@"url": @"mapbox://mapbox.mapbox-terrain-dem-v1",
@"tileSize": @514.0,
@"maxzoom": @14.0
}
completion:^(NSError * _Nonnull error) {
if (error) {
NSLog(@"%@", error);
}
}];
TMBTerrain* terrain = [[TMBTerrain alloc] initWithSourceId:sourceId];
TMBValue* value = [[TMBValue alloc] initWithConstant:@1.5];
terrain.exaggeration = value;
[[self.mapView mapboxMap] setTerrain:terrain completion:^(NSError * _Nonnull error) {
if (error) {
NSLog(@"%@", error);
}
}];
[[self.mapView mapboxMap]
addLayer:[self createSkyLayer]
layerPosition:nil
completion:^(NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
}
}];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end