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

Commit c58a37a

Browse files
jmkileyjmkiley
authored and
jmkiley
committed
Extrusions example (#86)
1 parent 82c280a commit c58a37a

File tree

6 files changed

+133
-2
lines changed

6 files changed

+133
-2
lines changed

Examples.xcodeproj/project.pbxproj

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
07F53B851E00D02100B58DB3 /* AnnotationViewMultipleExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 07F53B841E00D02100B58DB3 /* AnnotationViewMultipleExample.m */; };
1616
1F1F84751E538ABB00332CC3 /* BlockingGesturesDelegateExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F1F84741E538ABB00332CC3 /* BlockingGesturesDelegateExample.m */; };
1717
1F1F84771E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1F84761E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift */; };
18+
3E085B801EC526C500163C99 /* ExtrusionsExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E085B7F1EC526C500163C99 /* ExtrusionsExample.swift */; };
19+
3E085B831EC526E500163C99 /* ExtrusionsExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E085B821EC526E500163C99 /* ExtrusionsExample.m */; };
1820
3E3BFAD91E81D7A300D0BEA1 /* DDSLayerSelectionExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3BFAD81E81D7A300D0BEA1 /* DDSLayerSelectionExample.swift */; };
1921
3E3BFADC1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E3BFADB1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.m */; };
2022
3EBCD7161DC28240001E342F /* AnnotationViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBCD7021DC28240001E342F /* AnnotationViewExample.swift */; };
@@ -146,6 +148,9 @@
146148
1F1F84741E538ABB00332CC3 /* BlockingGesturesDelegateExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BlockingGesturesDelegateExample.m; sourceTree = "<group>"; };
147149
1F1F84761E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockingGesturesDelegateExample.swift; sourceTree = "<group>"; };
148150
29A0D7C8DCD539DCA5DA1BAC /* Pods-Examples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Examples.release.xcconfig"; path = "Pods/Target Support Files/Pods-Examples/Pods-Examples.release.xcconfig"; sourceTree = "<group>"; };
151+
3E085B7F1EC526C500163C99 /* ExtrusionsExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExtrusionsExample.swift; sourceTree = "<group>"; };
152+
3E085B811EC526E500163C99 /* ExtrusionsExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtrusionsExample.h; sourceTree = "<group>"; };
153+
3E085B821EC526E500163C99 /* ExtrusionsExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExtrusionsExample.m; sourceTree = "<group>"; };
149154
3E3BFAD81E81D7A300D0BEA1 /* DDSLayerSelectionExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DDSLayerSelectionExample.swift; sourceTree = "<group>"; };
150155
3E3BFADA1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDSLayerSelectionExample.h; sourceTree = "<group>"; };
151156
3E3BFADB1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDSLayerSelectionExample.m; sourceTree = "<group>"; };
@@ -330,8 +335,7 @@
330335
968247191C5C115000494AB8 /* DrawingAGeoJSONLineExample.m */,
331336
9682470E1C5BF12700494AB8 /* DrawingAMarkerExample.m */,
332337
9682471F1C5C1C0400494AB8 /* DrawingAPolygonExample.m */,
333-
968247291C5C1FF800494AB8 /* PointConversionExample.m */,
334-
3EC11D241EA8405A001AAAB8 /* PointHotspotExample.m */,
338+
3E085B821EC526E500163C99 /* ExtrusionsExample.m */,
335339
646B62A31DEF7115000AA523 /* RuntimeAddLineExample.m */,
336340
646B62A51DEF7121000AA523 /* RuntimeAnimateLineExample.m */,
337341
646B62BC1DEF965A000AA523 /* RuntimeCircleStylesExample.m */,
@@ -373,6 +377,7 @@
373377
3EBCD70E1DC28240001E342F /* DrawingAGeoJSONLineExample.swift */,
374378
3EBCD70F1DC28240001E342F /* DrawingAMarkerExample.swift */,
375379
3EBCD7101DC28240001E342F /* DrawingAPolygonExample.swift */,
380+
3E085B7F1EC526C500163C99 /* ExtrusionsExample.swift */,
376381
3EBCD7111DC28240001E342F /* OfflinePackExample.swift */,
377382
3EBCD7121DC28240001E342F /* PointConversionExample.swift */,
378383
3EC11D261EA84091001AAAB8 /* PointHotspotExample.swift */,
@@ -502,6 +507,7 @@
502507
968247181C5C115000494AB8 /* DrawingAGeoJSONLineExample.h */,
503508
9682470D1C5BF12700494AB8 /* DrawingAMarkerExample.h */,
504509
9682471E1C5C1C0400494AB8 /* DrawingAPolygonExample.h */,
510+
3E085B811EC526E500163C99 /* ExtrusionsExample.h */,
505511
96115A661CAD4E1C000963B8 /* OfflinePackExample.h */,
506512
968247281C5C1FF800494AB8 /* PointConversionExample.h */,
507513
3EC11D231EA8405A001AAAB8 /* PointHotspotExample.h */,
@@ -891,6 +897,7 @@
891897
968247201C5C1C0400494AB8 /* DrawingAPolygonExample.m in Sources */,
892898
3EBCD7221DC28240001E342F /* DrawingAGeoJSONLineExample.swift in Sources */,
893899
96A2A1D21C8CA74B0059441E /* CustomCalloutView.m in Sources */,
900+
3E085B831EC526E500163C99 /* ExtrusionsExample.m in Sources */,
894901
64BBDAF61DF232FD00BB705D /* SelectFeatureExample.swift in Sources */,
895902
64BBDAF81DF2330B00BB705D /* SelectFeatureExample.m in Sources */,
896903
96D431FC1C84B4F7007D09D1 /* DrawingACustomMarkerExample.m in Sources */,
@@ -902,6 +909,7 @@
902909
3EBCD71D1DC28240001E342F /* CustomRasterStyleExample.swift in Sources */,
903910
646B62B01DEF7161000AA523 /* RuntimeAnimateLineExample.swift in Sources */,
904911
07F53B851E00D02100B58DB3 /* AnnotationViewMultipleExample.m in Sources */,
912+
3E085B801EC526C500163C99 /* ExtrusionsExample.swift in Sources */,
905913
3EBCD7231DC28240001E342F /* DrawingAMarkerExample.swift in Sources */,
906914
961962911C581700002D3DAB /* main.m in Sources */,
907915
968247131C5C0F0F00494AB8 /* CalloutDelegateUsageExample.m in Sources */,

Examples/Examples.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern NSString *const MBXExampleDrawingAGeoJSONLine;
3434
extern NSString *const MBXExampleDrawingACustomMarker;
3535
extern NSString *const MBXExampleDrawingAMarker;
3636
extern NSString *const MBXExampleDrawingAPolygon;
37+
extern NSString *const MBXExample3DExtrusions;
3738
extern NSString *const MBXExampleOfflinePack;
3839
extern NSString *const MBXExamplePointConversion;
3940
extern NSString *const MBXExamplePointHotspot;

Examples/Examples.m

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ + (NSArray *)list {
3232
MBXExampleDrawingACustomMarker,
3333
MBXExampleDrawingAMarker,
3434
MBXExampleDrawingAPolygon,
35+
MBXExample3DExtrusions,
3536
MBXExampleOfflinePack,
3637
MBXExamplePointConversion,
3738
MBXExamplePointHotspot,
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ExtrusionsExample.h
3+
// Examples
4+
//
5+
// Created by Jordan Kiley on 5/11/17.
6+
// Copyright © 2017 Mapbox. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface ExtrusionsExample : UIViewController
12+
13+
@end
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// ExtrusionsExample.m
3+
// Examples
4+
//
5+
// Created by Jordan Kiley on 5/11/17.
6+
// Copyright © 2017 Mapbox. All rights reserved.
7+
//
8+
9+
#import "ExtrusionsExample.h"
10+
11+
@import Mapbox;
12+
13+
NSString *const MBXExample3DExtrusions = @"ExtrusionsExample";
14+
15+
@interface ExtrusionsExample () <MGLMapViewDelegate>
16+
17+
@end
18+
19+
@implementation ExtrusionsExample
20+
21+
- (void)viewDidLoad {
22+
[super viewDidLoad];
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+
28+
// Center the map view on the Colosseum in Rome, Italy and set the camera's pitch and distance.
29+
mapView.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:CLLocationCoordinate2DMake(41.8902, 12.4922) fromDistance:600 pitch:60 heading:0];
30+
mapView.delegate = self;
31+
32+
[self.view addSubview:mapView];
33+
}
34+
35+
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
36+
37+
// Access the Mapbox Streets source and use it to create a `MGLFillExtrusionStyleLayer`. The source identifier is `composite`. Use the `sources` property on a style to verify source identifiers.
38+
MGLSource *source = [style sourceWithIdentifier:@"composite"];
39+
MGLFillExtrusionStyleLayer *layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:@"buildings" source:source];
40+
layer.sourceLayerIdentifier = @"building";
41+
42+
// Filter out buildings that should not extrude.
43+
layer.predicate = [NSPredicate predicateWithFormat:@"extrude == 'true' AND height >= 0"];
44+
45+
// Set the fill extrusion height to the value for the building height attribute.
46+
layer.fillExtrusionHeight = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"height" options:nil];
47+
layer.fillExtrusionBase =[MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"min_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. If you aren’t sure what the layer is called, you can view the style in Mapbox Studio or iterate over the style’s layers property, printing out each layer’s identifier.
52+
MGLStyleLayer *symbolLayer = [style layerWithIdentifier:@"poi-scalerank3"];
53+
[style insertLayer:layer belowLayer:symbolLayer];
54+
}
55+
56+
@end
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// ExtrusionsExample.swift
3+
// Examples
4+
//
5+
// Created by Jordan Kiley on 5/10/17.
6+
// Copyright © 2017 Mapbox. All rights reserved.
7+
//
8+
9+
import Mapbox
10+
11+
@objc(ExtrusionsExample_Swift)
12+
13+
class ExtrusionsExample: UIViewController, MGLMapViewDelegate {
14+
15+
override func viewDidLoad() {
16+
super.viewDidLoad()
17+
18+
let mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.lightStyleURL(withVersion: 9))
19+
20+
// Center the map view on the Colosseum in Rome, Italy and set the camera's pitch and distance.
21+
mapView.camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 41.8902, longitude: 12.4922), fromDistance: 600, pitch: 60, heading: 0)
22+
mapView.delegate = self
23+
24+
view.addSubview(mapView)
25+
}
26+
27+
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
28+
29+
let array = [1, 2, 4, 6]
30+
// Access the Mapbox Streets source and use it to create a `MGLFillExtrusionStyleLayer`. The source identifier is `composite`. Use the `sources` property on a style to verify source identifiers.
31+
if let source = style.source(withIdentifier: "composite") {
32+
let layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: source)
33+
layer.sourceLayerIdentifier = "building"
34+
35+
// Filter out buildings that should not extrude.
36+
layer.predicate = NSPredicate(format: "extrude == 'true' AND height >= 0")
37+
38+
// Set the fill extrusion height to the value for the building height attribute.
39+
layer.fillExtrusionHeight = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "height", options: nil)
40+
layer.fillExtrusionBase = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "min_height", options: nil)
41+
layer.fillExtrusionOpacity = MGLStyleValue(rawValue: 0.75)
42+
layer.fillExtrusionColor = MGLStyleValue(rawValue: .white)
43+
44+
// Insert the fill extrusion layer below a POI label layer. If you aren’t sure what the layer is called, you can view the style in Mapbox Studio or iterate over the style’s layers property, printing out each layer’s identifier.
45+
if let symbolLayer = style.layer(withIdentifier: "poi-scalerank3") {
46+
style.insertLayer(layer, below: symbolLayer)
47+
} else {
48+
style.addLayer(layer)
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)