summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-06-07 10:26:21 +0200
committerKonstantin Käfer <mail@kkaefer.com>2017-06-16 17:41:03 +0200
commite1b0f94be0228d41e881aa52ff9529e815e5d59b (patch)
tree16f392ec9836a8763400db6dc369940b5b8b3aa7
parent0335351d9a6da7f57f59c978a538a299cda40e7e (diff)
downloadqtlocation-mapboxgl-e1b0f94be0228d41e881aa52ff9529e815e5d59b.tar.gz
[ios] add runtime styling command for adding building extrusions
-rw-r--r--platform/ios/app/MBXViewController.m39
1 files changed, 38 insertions, 1 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 7f3adfb78b..672bb3b997 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -52,7 +52,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) {
};
typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) {
- MBXSettingsRuntimeStylingWater = 0,
+ MBXSettingsRuntimeStylingBuildingExtrusions = 0,
+ MBXSettingsRuntimeStylingWater,
MBXSettingsRuntimeStylingRoads,
MBXSettingsRuntimeStylingRaster,
MBXSettingsRuntimeStylingShape,
@@ -324,6 +325,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
break;
case MBXSettingsRuntimeStyling:
[settingsTitles addObjectsFromArray:@[
+ @"Add Building Extrusions",
@"Style Water With Function",
@"Style Roads With Function",
@"Add Raster & Apply Function",
@@ -523,6 +525,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
case MBXSettingsRuntimeStyling:
switch (indexPath.row)
{
+ case MBXSettingsRuntimeStylingBuildingExtrusions:
+ [self styleBuildingExtrusions];
+ break;
case MBXSettingsRuntimeStylingWater:
[self styleWaterLayer];
break;
@@ -860,6 +865,38 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[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"];