-
Notifications
You must be signed in to change notification settings - Fork 35
Extrusions example #86
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// ExtrusionsExample.h | ||
// Examples | ||
// | ||
// Created by Jordan Kiley on 5/11/17. | ||
// Copyright © 2017 Mapbox. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface ExtrusionsExample : UIViewController | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// ExtrusionsExample.m | ||
// Examples | ||
// | ||
// Created by Jordan Kiley on 5/11/17. | ||
// Copyright © 2017 Mapbox. All rights reserved. | ||
// | ||
|
||
#import "ExtrusionsExample.h" | ||
|
||
@import Mapbox; | ||
|
||
NSString *const MBXExample3DExtrusions = @"ExtrusionsExample"; | ||
|
||
@interface ExtrusionsExample () <MGLMapViewDelegate> | ||
|
||
@end | ||
|
||
@implementation ExtrusionsExample | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:[MGLStyle lightStyleURLWithVersion:9]]; | ||
|
||
// Center the map on the Colosseum in Rome, Italy. | ||
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(41.8902, 12.4922)]; | ||
|
||
// Set the map view camera's pitch and distance. | ||
mapView.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:mapView.centerCoordinate fromDistance:600 pitch:60 heading:0]; | ||
mapView.delegate = self; | ||
|
||
[self.view addSubview:mapView]; | ||
} | ||
|
||
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { | ||
|
||
// 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to reference the Style Specification here: https://www.mapbox.com/mapbox-gl-js/style-spec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment refers to properties in the runtime styling API to use as a debugging aid. There are so many differences between the runtime styling API and the style specification’s documentation on sources that we’d want to link to the more detailed API reference instead. In any case, I think #86 (comment) is relevant here as well:
|
||
MGLSource *source = [style sourceWithIdentifier:@"composite"]; | ||
MGLFillExtrusionStyleLayer *layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:@"buildings" source:source]; | ||
layer.sourceLayerIdentifier = @"building"; | ||
|
||
// Filter out buildings that should not extrude. | ||
layer.predicate = [NSPredicate predicateWithFormat:@"extrude != false AND height >=0"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Set the fill extrusion height to the value for the building height attribute. | ||
layer.fillExtrusionHeight = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"height" options:nil]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to set |
||
layer.fillExtrusionOpacity = [MGLStyleValue valueWithRawValue:@0.75]; | ||
layer.fillExtrusionColor = [MGLStyleValue valueWithRawValue:[UIColor whiteColor]]; | ||
|
||
// Insert the fill extrusion layer below a POI label layer. Use the `layers` property on a style to verify built-in layer identifiers. | ||
MGLStyleLayer *symbolLayer = [style layerWithIdentifier:@"poi-scalerank3"]; | ||
[style insertLayer:layer belowLayer:symbolLayer]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// ExtrusionsExample.swift | ||
// Examples | ||
// | ||
// Created by Jordan Kiley on 5/10/17. | ||
// Copyright © 2017 Mapbox. All rights reserved. | ||
// | ||
|
||
import Mapbox | ||
|
||
@objc(ExtrusionsExample_Swift) | ||
|
||
class ExtrusionsExample: UIViewController, MGLMapViewDelegate { | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
let mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.lightStyleURL(withVersion: 9)) | ||
|
||
// Center the map on the Colosseum in Rome, Italy. | ||
mapView.setCenter(CLLocationCoordinate2D(latitude: 41.8902, longitude: 12.4922), animated: false) | ||
|
||
// Set the map view camera's pitch and distance. | ||
mapView.camera = MGLMapCamera(lookingAtCenter: mapView.centerCoordinate, fromDistance: 600, pitch: 60, heading: 0) | ||
mapView.delegate = self | ||
|
||
view.addSubview(mapView) | ||
} | ||
|
||
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { | ||
|
||
// 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. | ||
if let source = style.source(withIdentifier: "composite") { | ||
let layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: source) | ||
layer.sourceLayerIdentifier = "building" | ||
|
||
// Filter out buildings that should not extrude. | ||
layer.predicate = NSPredicate(format: "extrude != false AND height >=0") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: missing a space between |
||
|
||
// Set the fill extrusion height to the value for the building height attribute. | ||
layer.fillExtrusionHeight = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "height", options: nil) | ||
layer.fillExtrusionOpacity = MGLStyleValue(rawValue: 0.75) | ||
layer.fillExtrusionColor = MGLStyleValue(rawValue: .white) | ||
|
||
// Insert the fill extrusion layer below a POI label layer. Use the `layers` property on a style to verify built-in layer identifiers. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment may lead a developer to think they have to use the
|
||
if let symbolLayer = style.layer(withIdentifier: "poi-scalerank3") { | ||
style.insertLayer(layer, below: symbolLayer) | ||
} else { | ||
style.addLayer(layer) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use dot notation:
mapView.centerCoordinate = …
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we’re setting the camera right below. Let’s combine the two statements.