diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-07-05 16:01:43 -0700 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-07-23 11:59:22 -0700 |
commit | 021372a80e10e95d6f3f2a6ebf0f316dc0c676a1 (patch) | |
tree | 7bae941a0c9cb3a13ceda1466b89c7bad6d3f8e5 | |
parent | ecd7ebecaf635e70821c48b4ebf32044f8556b7f (diff) | |
download | qtlocation-mapboxgl-021372a80e10e95d6f3f2a6ebf0f316dc0c676a1.tar.gz |
[ios] Add showBuildings as an MGLMapView property.
-rw-r--r-- | platform/ios/src/MGLMapView.h | 11 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 46 |
2 files changed, 57 insertions, 0 deletions
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index b2439416ae..63bdbb37e5 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -417,6 +417,17 @@ MGL_EXPORT IB_DESIGNABLE @property (nonatomic, assign) BOOL displayHeadingCalibration; /** + A Boolean value indicating whether extrusions for buildings are diaplayed. + + Setting this property to `YES` causes the map to display buildings extrusions + for buildings which `extrusion` property is set to `true` and `height` has a + greater value than cero. + + The default value of this property is `NO`. + */ +@property (nonatomic, assign) BOOL showsBuildings; + +/** The geographic coordinate that is the subject of observation as the user location is being tracked. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index cdacfb462b..0689d02efa 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2343,6 +2343,47 @@ public: } } +- (void)setShowsBuildings:(BOOL)showsBuildings +{ + if (_showsBuildings == showsBuildings) return; + + NSString *layerIdentifier = @"extrudedBuildings"; + if (showsBuildings) { + MGLSource* source = [self.style sourceWithIdentifier:@"composite"]; + if (source) { + + MGLFillExtrusionStyleLayer* layer = [[MGLFillExtrusionStyleLayer alloc] initWithIdentifier:layerIdentifier source:source]; + layer.sourceLayerIdentifier = @"building"; + layer.predicate = [NSPredicate predicateWithFormat:@"extrude == 'true' AND CAST(height, 'NSNumber') > 0"]; + layer.fillExtrusionBase = [NSExpression expressionForKeyPath:@"min_height"]; + layer.fillExtrusionHeight = [NSExpression expressionForKeyPath:@"height"]; + + // Set the fill color to that of the existing building footprint layer, if it exists. + MGLFillStyleLayer* buildingLayer = (MGLFillStyleLayer*)[self.style layerWithIdentifier:@"building"]; + if (buildingLayer) { + if (buildingLayer.fillColor) { + layer.fillExtrusionColor = buildingLayer.fillColor; + } else { + layer.fillExtrusionColor = [NSExpression expressionForConstantValue:[UIColor whiteColor]]; + } + + layer.fillExtrusionOpacity = [NSExpression expressionForConstantValue:@0.75]; + } + + MGLStyleLayer* labelLayer = [self.style layerWithIdentifier:@"waterway-label"]; + if (labelLayer) { + [self.style insertLayer:layer belowLayer:labelLayer]; + } else { + [self.style addLayer:layer]; + } + } + } else { + MGLStyleLayer *layer = [self.style layerWithIdentifier:layerIdentifier]; + if (layer) [self.style removeLayer:layer]; + } + _showsBuildings = showsBuildings; +} + #pragma mark - Accessibility - - (NSString *)accessibilityValue @@ -5645,6 +5686,11 @@ public: { [self.delegate mapView:self didFinishLoadingStyle:self.style]; } + + if (_showsBuildings) { + _showsBuildings = NO; // Forces an update. + self.showsBuildings = YES; + } } - (void)updateUserLocationAnnotationView |