Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] add runtime styling command for adding building extrusions
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Jun 16, 2017
1 parent 0335351 commit e1b0f94
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) {
};

typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) {
MBXSettingsRuntimeStylingWater = 0,
MBXSettingsRuntimeStylingBuildingExtrusions = 0,
MBXSettingsRuntimeStylingWater,
MBXSettingsRuntimeStylingRoads,
MBXSettingsRuntimeStylingRaster,
MBXSettingsRuntimeStylingShape,
Expand Down Expand Up @@ -324,6 +325,7 @@ - (void)dismissSettings:(__unused id)sender
break;
case MBXSettingsRuntimeStyling:
[settingsTitles addObjectsFromArray:@[
@"Add Building Extrusions",
@"Style Water With Function",
@"Style Roads With Function",
@"Add Raster & Apply Function",
Expand Down Expand Up @@ -523,6 +525,9 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
case MBXSettingsRuntimeStyling:
switch (indexPath.row)
{
case MBXSettingsRuntimeStylingBuildingExtrusions:
[self styleBuildingExtrusions];
break;
case MBXSettingsRuntimeStylingWater:
[self styleWaterLayer];
break;
Expand Down Expand Up @@ -860,6 +865,38 @@ - (void)addAnnotationWithCustomCallout
[self.mapView showAnnotations:annotations animated:YES];
}

- (void)styleBuildingExtrusions
{
MGLSource* source = [self.mapView.style sourceWithIdentifier:@"composite"];
if (source) {

MGLFillExtrusionStyleLayer* layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:@"extrudedBuildings" source:source];
layer.sourceLayerIdentifier = @"building";
layer.predicate = [NSPredicate predicateWithFormat:@"extrude == 'true' AND height > 0"];
layer.fillExtrusionBase = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"min_height" options:nil];
layer.fillExtrusionHeight = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"height" options:nil];

// Set the fill color to that of the existing building footprint layer, if it exists.
MGLFillStyleLayer* buildingLayer = (MGLFillStyleLayer*)[self.mapView.style layerWithIdentifier:@"building"];
if (buildingLayer) {
if (buildingLayer.fillColor) {
layer.fillExtrusionColor = buildingLayer.fillColor;
} else {
layer.fillExtrusionColor = [MGLStyleValue valueWithRawValue:[UIColor whiteColor]];
}

layer.fillExtrusionOpacity = [MGLStyleValue<NSNumber *> valueWithRawValue:@0.75];
}

MGLStyleLayer* labelLayer = [self.mapView.style layerWithIdentifier:@"waterway-label"];
if (labelLayer) {
[self.mapView.style insertLayer:layer belowLayer:labelLayer];
} else {
[self.mapView.style addLayer:layer];
}
}
}

- (void)styleWaterLayer
{
MGLFillStyleLayer *waterLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"water"];
Expand Down

0 comments on commit e1b0f94

Please sign in to comment.