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

Commit

Permalink
Added Objective-C
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkiley committed May 12, 2017
1 parent 3412466 commit e6c0da0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
46 changes: 31 additions & 15 deletions Examples/ObjectiveC/ExtrusionsExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,50 @@
//

#import "ExtrusionsExample.h"

@import Mapbox;

NSString *const MBXExample3DExtrusions = @"ExtrusionsExample";

@interface ExtrusionsExample ()
@interface ExtrusionsExample () <MGLMapViewDelegate>

@end

@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
20 changes: 10 additions & 10 deletions Examples/Swift/ExtrusionsExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!)

}

}

0 comments on commit e6c0da0

Please sign in to comment.