|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | #import "ExtrusionsExample.h"
|
| 10 | + |
10 | 11 | @import Mapbox;
|
11 | 12 |
|
12 | 13 | NSString *const MBXExample3DExtrusions = @"ExtrusionsExample";
|
13 | 14 |
|
14 |
| -@interface ExtrusionsExample () |
| 15 | +@interface ExtrusionsExample () <MGLMapViewDelegate> |
15 | 16 |
|
16 | 17 | @end
|
17 | 18 |
|
18 | 19 | @implementation ExtrusionsExample
|
19 | 20 |
|
20 | 21 | - (void)viewDidLoad {
|
21 | 22 | [super viewDidLoad];
|
22 |
| - // Do any additional setup after loading the view. |
23 |
| -} |
24 |
| - |
25 |
| -- (void)didReceiveMemoryWarning { |
26 |
| - [super didReceiveMemoryWarning]; |
27 |
| - // Dispose of any resources that can be recreated. |
| 23 | + |
| 24 | + MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:[MGLStyle lightStyleURLWithVersion:9]]; |
| 25 | + |
| 26 | + // Center the map on the Colosseum in Rome, Italy. |
| 27 | + [mapView setCenterCoordinate:CLLocationCoordinate2DMake(41.8902, 12.4922)]; |
| 28 | + |
| 29 | + // Set the map view camera's pitch and distance. |
| 30 | + mapView.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:mapView.centerCoordinate fromDistance:600 pitch:60 heading:0]; |
| 31 | + mapView.delegate = self; |
| 32 | + |
| 33 | + [self.view addSubview:mapView]; |
28 | 34 | }
|
29 | 35 |
|
30 |
| -/* |
31 |
| -#pragma mark - Navigation |
32 |
| -
|
33 |
| -// In a storyboard-based application, you will often want to do a little preparation before navigation |
34 |
| -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { |
35 |
| - // Get the new view controller using [segue destinationViewController]. |
36 |
| - // Pass the selected object to the new view controller. |
| 36 | +- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { |
| 37 | + |
| 38 | + // Access the Mapbox Streets source and use it to create a `MGLFillExtrusionLayer`. |
| 39 | + MGLSource *source = [style sourceWithIdentifier:@"composite"]; |
| 40 | + MGLFillExtrusionStyleLayer *layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:@"buildings" source:source]; |
| 41 | + layer.sourceLayerIdentifier = @"building"; |
| 42 | + |
| 43 | + // Filter out buildings that should not extrude. |
| 44 | + layer.predicate = [NSPredicate predicateWithFormat:@"extrude != false AND height >=0"]; |
| 45 | + |
| 46 | + // Set the fill extrusion height to the value for the building height attribute. |
| 47 | + layer.fillExtrusionHeight = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"height" options:nil]; |
| 48 | + layer.fillExtrusionOpacity = [MGLStyleValue valueWithRawValue:@0.75]; |
| 49 | + layer.fillExtrusionColor = [MGLStyleValue valueWithRawValue:[UIColor whiteColor]]; |
| 50 | + |
| 51 | + // Insert the fill extrusion layer below a POI label layer. |
| 52 | + MGLStyleLayer *symbolLayer = [style layerWithIdentifier:@"poi-scalerank3"]; |
| 53 | + [style insertLayer:layer belowLayer:symbolLayer]; |
37 | 54 | }
|
38 |
| -*/ |
39 | 55 |
|
40 | 56 | @end
|
0 commit comments