From e6c0da0dbda185e94a098b6b652b6a0d775306de Mon Sep 17 00:00:00 2001 From: jmkiley Date: Fri, 12 May 2017 11:18:31 -0700 Subject: [PATCH] Added Objective-C --- Examples/ObjectiveC/ExtrusionsExample.m | 46 +++++++++++++++++-------- Examples/Swift/ExtrusionsExample.swift | 20 +++++------ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/Examples/ObjectiveC/ExtrusionsExample.m b/Examples/ObjectiveC/ExtrusionsExample.m index 29ef2355..700fb8bf 100644 --- a/Examples/ObjectiveC/ExtrusionsExample.m +++ b/Examples/ObjectiveC/ExtrusionsExample.m @@ -7,11 +7,12 @@ // #import "ExtrusionsExample.h" + @import Mapbox; NSString *const MBXExample3DExtrusions = @"ExtrusionsExample"; -@interface ExtrusionsExample () +@interface ExtrusionsExample () @end @@ -19,22 +20,37 @@ @implementation ExtrusionsExample - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + + 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]; } -/* -#pragma mark - Navigation - -// In a storyboard-based application, you will often want to do a little preparation before navigation -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - // Get the new view controller using [segue destinationViewController]. - // Pass the selected object to the new view controller. +- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { + + // Access the Mapbox Streets source and use it to create a `MGLFillExtrusionLayer`. + 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"]; + + // Set the fill extrusion height to the value for the building height attribute. + layer.fillExtrusionHeight = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"height" options:nil]; + layer.fillExtrusionOpacity = [MGLStyleValue valueWithRawValue:@0.75]; + layer.fillExtrusionColor = [MGLStyleValue valueWithRawValue:[UIColor whiteColor]]; + + // Insert the fill extrusion layer below a POI label layer. + MGLStyleLayer *symbolLayer = [style layerWithIdentifier:@"poi-scalerank3"]; + [style insertLayer:layer belowLayer:symbolLayer]; } -*/ @end diff --git a/Examples/Swift/ExtrusionsExample.swift b/Examples/Swift/ExtrusionsExample.swift index b86fcde2..98d02caf 100644 --- a/Examples/Swift/ExtrusionsExample.swift +++ b/Examples/Swift/ExtrusionsExample.swift @@ -12,39 +12,39 @@ import Mapbox class ExtrusionsExample: UIViewController, MGLMapViewDelegate { - var mapView : MGLMapView! override func viewDidLoad() { super.viewDidLoad() - mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.lightStyleURL(withVersion: 9)) + 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 `MGLMapCamera` to one + // 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. + // Access the Mapbox Streets source and use it to create a `MGLFillExtrusionLayer`. let source = style.source(withIdentifier: "composite") - - // Create a `MGLFillExtrusionLayer` using the building layer from that source. let layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: source!) layer.sourceLayerIdentifier = "building" - // Check that the building is should + // Filter out buildings that should not extrude. layer.predicate = NSPredicate(format: "extrude != false AND height >=0") + // 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. let symbolLayer = style.layer(withIdentifier: "poi-scalerank3") style.insertLayer(layer, below: symbolLayer!) - } }