Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit e6c0da0

Browse files
author
jmkiley
committed
Added Objective-C
1 parent 3412466 commit e6c0da0

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

Examples/ObjectiveC/ExtrusionsExample.m

+31-15
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,50 @@
77
//
88

99
#import "ExtrusionsExample.h"
10+
1011
@import Mapbox;
1112

1213
NSString *const MBXExample3DExtrusions = @"ExtrusionsExample";
1314

14-
@interface ExtrusionsExample ()
15+
@interface ExtrusionsExample () <MGLMapViewDelegate>
1516

1617
@end
1718

1819
@implementation ExtrusionsExample
1920

2021
- (void)viewDidLoad {
2122
[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];
2834
}
2935

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];
3754
}
38-
*/
3955

4056
@end

Examples/Swift/ExtrusionsExample.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,39 @@ import Mapbox
1212

1313
class ExtrusionsExample: UIViewController, MGLMapViewDelegate {
1414

15-
var mapView : MGLMapView!
1615
override func viewDidLoad() {
1716
super.viewDidLoad()
1817

19-
mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.lightStyleURL(withVersion: 9))
18+
let mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.lightStyleURL(withVersion: 9))
19+
20+
// Center the map on the Colosseum in Rome, Italy.
2021
mapView.setCenter(CLLocationCoordinate2D(latitude: 41.8902, longitude: 12.4922), animated: false)
2122

22-
// Set the `MGLMapCamera` to one
23+
// Set the map view camera's pitch and distance.
2324
mapView.camera = MGLMapCamera(lookingAtCenter: mapView.centerCoordinate, fromDistance: 600, pitch: 60, heading: 0)
24-
2525
mapView.delegate = self
26+
2627
view.addSubview(mapView)
2728
}
2829

2930
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
3031

31-
// Access the Mapbox Streets source.
32+
// Access the Mapbox Streets source and use it to create a `MGLFillExtrusionLayer`.
3233
let source = style.source(withIdentifier: "composite")
33-
34-
// Create a `MGLFillExtrusionLayer` using the building layer from that source.
3534
let layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: source!)
3635
layer.sourceLayerIdentifier = "building"
3736

38-
// Check that the building is should
37+
// Filter out buildings that should not extrude.
3938
layer.predicate = NSPredicate(format: "extrude != false AND height >=0")
4039

40+
// Set the fill extrusion height to the value for the building height attribute.
4141
layer.fillExtrusionHeight = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "height", options: nil)
42-
4342
layer.fillExtrusionOpacity = MGLStyleValue(rawValue: 0.75)
4443
layer.fillExtrusionColor = MGLStyleValue(rawValue: .white)
44+
45+
// Insert the fill extrusion layer below a POI label layer.
4546
let symbolLayer = style.layer(withIdentifier: "poi-scalerank3")
4647
style.insertLayer(layer, below: symbolLayer!)
47-
4848
}
4949

5050
}

0 commit comments

Comments
 (0)