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

Commit de63625

Browse files
author
jmkiley
committed
addressed friedbunny's comments
1 parent 8d9c5d7 commit de63625

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

Examples/ObjectiveC/ExtrusionsExample.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ - (void)viewDidLoad {
3535

3636
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
3737

38-
// Access the Mapbox Streets source and use it to create a `MGLFillExtrusionLayer`.
38+
// 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.
3939
MGLSource *source = [style sourceWithIdentifier:@"composite"];
4040
MGLFillExtrusionStyleLayer *layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:@"buildings" source:source];
4141
layer.sourceLayerIdentifier = @"building";
@@ -48,7 +48,7 @@ - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
4848
layer.fillExtrusionOpacity = [MGLStyleValue valueWithRawValue:@0.75];
4949
layer.fillExtrusionColor = [MGLStyleValue valueWithRawValue:[UIColor whiteColor]];
5050

51-
// Insert the fill extrusion layer below a POI label layer.
51+
// Insert the fill extrusion layer below a POI label layer. Use the `layers` property on a style to verify built-in layer identifiers.
5252
MGLStyleLayer *symbolLayer = [style layerWithIdentifier:@"poi-scalerank3"];
5353
[style insertLayer:layer belowLayer:symbolLayer];
5454
}

Examples/Swift/ExtrusionsExample.swift

+21-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ExtrusionsExample: UIViewController, MGLMapViewDelegate {
1919

2020
// Center the map on the Colosseum in Rome, Italy.
2121
mapView.setCenter(CLLocationCoordinate2D(latitude: 41.8902, longitude: 12.4922), animated: false)
22-
22+
2323
// Set the map view camera's pitch and distance.
2424
mapView.camera = MGLMapCamera(lookingAtCenter: mapView.centerCoordinate, fromDistance: 600, pitch: 60, heading: 0)
2525
mapView.delegate = self
@@ -29,22 +29,25 @@ class ExtrusionsExample: UIViewController, MGLMapViewDelegate {
2929

3030
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
3131

32-
// Access the Mapbox Streets source and use it to create a `MGLFillExtrusionLayer`.
33-
let source = style.source(withIdentifier: "composite")
34-
let layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: source!)
35-
layer.sourceLayerIdentifier = "building"
36-
37-
// Filter out buildings that should not extrude.
38-
layer.predicate = NSPredicate(format: "extrude != false AND height >=0")
39-
40-
// Set the fill extrusion height to the value for the building height attribute.
41-
layer.fillExtrusionHeight = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "height", options: nil)
42-
layer.fillExtrusionOpacity = MGLStyleValue(rawValue: 0.75)
43-
layer.fillExtrusionColor = MGLStyleValue(rawValue: .white)
44-
45-
// Insert the fill extrusion layer below a POI label layer.
46-
let symbolLayer = style.layer(withIdentifier: "poi-scalerank3")
47-
style.insertLayer(layer, below: symbolLayer!)
32+
// 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.
33+
if let source = style.source(withIdentifier: "composite") {
34+
let layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: source)
35+
layer.sourceLayerIdentifier = "building"
36+
37+
// Filter out buildings that should not extrude.
38+
layer.predicate = NSPredicate(format: "extrude != false AND height >=0")
39+
40+
// Set the fill extrusion height to the value for the building height attribute.
41+
layer.fillExtrusionHeight = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "height", options: nil)
42+
layer.fillExtrusionOpacity = MGLStyleValue(rawValue: 0.75)
43+
layer.fillExtrusionColor = MGLStyleValue(rawValue: .white)
44+
45+
// Insert the fill extrusion layer below a POI label layer. Use the `layers` property on a style to verify built-in layer identifiers.
46+
if let symbolLayer = style.layer(withIdentifier: "poi-scalerank3") {
47+
style.insertLayer(layer, below: symbolLayer)
48+
} else {
49+
style.addLayer(layer)
50+
}
51+
}
4852
}
49-
5053
}

0 commit comments

Comments
 (0)