diff options
Diffstat (limited to 'platform/ios/app/MBXViewController.m')
-rw-r--r-- | platform/ios/app/MBXViewController.m | 239 |
1 files changed, 146 insertions, 93 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 1046644f8c..282dc901d6 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -75,6 +75,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { MBXSettingsRuntimeStylingImageSource, MBXSettingsRuntimeStylingRouteLine, MBXSettingsRuntimeStylingDDSPolygon, + MBXSettingsRuntimeStylingCustomLatLonGrid, }; typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @@ -111,7 +112,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @interface MBXViewController () <UITableViewDelegate, UITableViewDataSource, - MGLMapViewDelegate> + MGLMapViewDelegate, + MGLComputedShapeSourceDataSource> @property (nonatomic) IBOutlet MGLMapView *mapView; @@ -353,6 +355,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @"Style Image Source", @"Add Route Line", @"Dynamically Style Polygon", + @"Add Custom Lat/Lon Grid", ]]; break; case MBXSettingsMiscellaneous: @@ -529,6 +532,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { case MBXSettingsRuntimeStylingDDSPolygon: [self stylePolygonWithDDS]; break; + case MBXSettingsRuntimeStylingCustomLatLonGrid: + [self addLatLonGrid]; + break; default: NSAssert(NO, @"All runtime styling setting rows should be implemented"); break; @@ -891,8 +897,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { 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]; + 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.mapView.style layerWithIdentifier:@"building"]; @@ -900,10 +906,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { if (buildingLayer.fillColor) { layer.fillExtrusionColor = buildingLayer.fillColor; } else { - layer.fillExtrusionColor = [MGLStyleValue valueWithRawValue:[UIColor whiteColor]]; + layer.fillExtrusionColor = [NSExpression expressionForConstantValue:[UIColor whiteColor]]; } - layer.fillExtrusionOpacity = [MGLStyleValue<NSNumber *> valueWithRawValue:@0.75]; + layer.fillExtrusionOpacity = [NSExpression expressionForConstantValue:@0.75]; } MGLStyleLayer* labelLayer = [self.mapView.style layerWithIdentifier:@"waterway-label"]; @@ -918,48 +924,45 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { - (void)styleWaterLayer { MGLFillStyleLayer *waterLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"water"]; - NSDictionary *waterColorStops = @{@6.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor yellowColor]], - @8.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]], - @10.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]], - @12.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor greenColor]], - @14.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]]}; - MGLStyleValue *waterColorFunction = [MGLStyleValue<UIColor *> valueWithInterpolationMode:MGLInterpolationModeExponential - cameraStops:waterColorStops - options: nil]; - waterLayer.fillColor = waterColorFunction; - - NSDictionary *fillAntialiasedStops = @{@11: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES], - @12: [MGLStyleValue<NSNumber *> valueWithRawValue:@NO], - @13: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES], - @14: [MGLStyleValue<NSNumber *> valueWithRawValue:@NO], - @15: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]}; - MGLStyleValue *fillAntialiasedFunction = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeInterval - cameraStops:fillAntialiasedStops - options:nil]; - waterLayer.fillAntialiased = fillAntialiasedFunction; + NSDictionary *waterColorStops = @{@6.0f: [UIColor yellowColor], + @8.0f: [UIColor blueColor], + @10.0f: [UIColor redColor], + @12.0f: [UIColor greenColor], + @14.0f: [UIColor blueColor]}; + waterLayer.fillColor = [NSExpression expressionWithFormat: + @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", + waterColorStops]; + + NSDictionary *fillAntialiasedStops = @{@11: @YES, + @12: @NO, + @13: @YES, + @14: @NO, + @15: @YES}; + waterLayer.fillAntialiased = [NSExpression expressionWithFormat: + @"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', false, %@)", + fillAntialiasedStops]; } - (void)styleRoadLayer { MGLLineStyleLayer *roadLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"road-primary"]; - roadLayer.lineColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blackColor]]; - - NSDictionary *lineWidthStops = @{@5: [MGLStyleValue<NSNumber *> valueWithRawValue:@5], - @10: [MGLStyleValue<NSNumber *> valueWithRawValue:@15], - @15: [MGLStyleValue<NSNumber *> valueWithRawValue:@30]}; - MGLStyleValue *lineWidthFunction = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential - cameraStops:lineWidthStops - options:nil]; - roadLayer.lineWidth = lineWidthFunction; - roadLayer.lineGapWidth = lineWidthFunction; - - NSDictionary *roadLineColorStops = @{@10: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor purpleColor]], - @13: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor yellowColor]], - @16: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor cyanColor]]}; - MGLStyleValue *roadLineColor = [MGLStyleValue<UIColor *> valueWithInterpolationMode:MGLInterpolationModeExponential - cameraStops:roadLineColorStops - options: nil]; - roadLayer.lineColor = roadLineColor; + roadLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor blackColor]]; + + NSDictionary *lineWidthStops = @{@5: @5, + @10: @15, + @15: @30}; + NSExpression *lineWidthExpression = [NSExpression expressionWithFormat: + @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", + lineWidthStops]; + roadLayer.lineWidth = lineWidthExpression; + roadLayer.lineGapWidth = lineWidthExpression; + + NSDictionary *roadLineColorStops = @{@10: [UIColor purpleColor], + @13: [UIColor yellowColor], + @16: [UIColor cyanColor]}; + roadLayer.lineColor = [NSExpression expressionWithFormat: + @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", + roadLineColorStops]; roadLayer.visible = YES; roadLayer.maximumZoomLevel = 15; @@ -973,11 +976,11 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:rasterSource]; MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"my-raster-layer" source:rasterSource]; - MGLStyleValue *opacityFunction = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential - cameraStops:@{@20.0f: [MGLStyleValue<NSNumber *> valueWithRawValue:@1.0f], - @5.0f: [MGLStyleValue<NSNumber *> valueWithRawValue:@0.0f]} - options:nil]; - rasterLayer.rasterOpacity = opacityFunction; + NSDictionary *opacityStops = @{@20.0f: @1.0f, + @5.0f: @0.0f}; + rasterLayer.rasterOpacity = [NSExpression expressionWithFormat: + @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", + opacityStops]; [self.mapView.style addLayer:rasterLayer]; } @@ -989,7 +992,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:source]; MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source]; - fillLayer.fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor purpleColor]]; + fillLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor purpleColor]]; [self.mapView.style addLayer:fillLayer]; } @@ -997,7 +1000,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { - (void)styleSymbolLayer { MGLSymbolStyleLayer *stateLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"state-label-lg"]; - stateLayer.textColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]; + stateLayer.textColor = [NSExpression expressionForConstantValue:[UIColor redColor]]; } - (void)styleBuildingLayer @@ -1005,13 +1008,13 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MGLTransition transition = { 5, 1 }; self.mapView.style.transition = transition; MGLFillStyleLayer *buildingLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"building"]; - buildingLayer.fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor purpleColor]]; + buildingLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor purpleColor]]; } - (void)styleFerryLayer { MGLLineStyleLayer *ferryLineLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"ferry"]; - ferryLineLayer.lineColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]; + ferryLineLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor redColor]]; } - (void)removeParkLayer @@ -1035,8 +1038,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { statesLayer.predicate = [NSPredicate predicateWithFormat:@"name == 'Texas'"]; // paint properties - statesLayer.fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]; - statesLayer.fillOpacity = [MGLStyleValue<NSNumber *> valueWithRawValue:@0.25]; + statesLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor redColor]]; + statesLayer.fillOpacity = [NSExpression expressionForConstantValue:@0.25]; }); } @@ -1055,9 +1058,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { countiesLayer.predicate = [NSPredicate predicateWithFormat:@"NAME10 == 'Washington'"]; // paint properties - countiesLayer.lineColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]; - countiesLayer.lineOpacity = [MGLStyleValue<NSNumber *> valueWithRawValue:@0.75]; - countiesLayer.lineWidth = [MGLStyleValue<NSNumber *> valueWithRawValue:@5]; + countiesLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor redColor]]; + countiesLayer.lineOpacity = [NSExpression expressionForConstantValue:@0.75]; + countiesLayer.lineWidth = [NSExpression expressionForConstantValue:@5]; }); } @@ -1076,8 +1079,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { regionsLayer.predicate = [NSPredicate predicateWithFormat:@"HRRNUM >= %@ AND HRRNUM < 300", @(200)]; // paint properties - regionsLayer.fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]]; - regionsLayer.fillOpacity = [MGLStyleValue<NSNumber *> valueWithRawValue:@0.5]; + regionsLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor blueColor]]; + regionsLayer.fillOpacity = [NSExpression expressionForConstantValue:@0.5]; }); } @@ -1107,8 +1110,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:source]; MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:queryLayerID source:source]; - fillLayer.fillColor = [MGLConstantStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]]; - fillLayer.fillOpacity = [MGLConstantStyleValue<NSNumber *> valueWithRawValue:@0.5]; + fillLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor blueColor]]; + fillLayer.fillOpacity = [NSExpression expressionForConstantValue:@0.5]; [self.mapView.style addLayer:fillLayer]; }); } @@ -1161,8 +1164,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-fill-layer" source:source]; layer.predicate = [NSPredicate predicateWithFormat:@"color = 'red'"]; - MGLStyleValue *fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]; - layer.fillColor = fillColor; + layer.fillColor = [NSExpression expressionForConstantValue:[UIColor redColor]]; [self.mapView.style addLayer:layer]; NSString *geoJSON = @"{\"type\": \"Feature\", \"properties\": {\"color\": \"green\"}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -114.06847000122069, 51.050459433092655 ] }}"; @@ -1173,7 +1175,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:pointSource]; MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"leaf-circle-layer" source:pointSource]; - circleLayer.circleColor = [MGLStyleValue valueWithRawValue:[UIColor greenColor]]; + circleLayer.circleColor = [NSExpression expressionForConstantValue:[UIColor greenColor]]; circleLayer.predicate = [NSPredicate predicateWithFormat:@"color = 'green'"]; [self.mapView.style addLayer:circleLayer]; @@ -1190,7 +1192,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:plainShapeSource]; MGLFillStyleLayer *plainFillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-plain-fill-layer" source:plainShapeSource]; - plainFillLayer.fillColor = [MGLStyleValue valueWithRawValue:[UIColor yellowColor]]; + plainFillLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor yellowColor]]; [self.mapView.style addLayer:plainFillLayer]; } @@ -1267,8 +1269,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:source]; MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"mutable-data-layer-features-id" source:source]; - MGLStyleValue *fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]; - layer.fillColor = fillColor; + layer.fillColor = [NSExpression expressionForConstantValue:[UIColor redColor]]; [self.mapView.style addLayer:layer]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ @@ -1301,16 +1302,14 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:vectorSource]; MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"style-vector-background-layer-id"]; - backgroundLayer.backgroundColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blackColor]]; + backgroundLayer.backgroundColor = [NSExpression expressionForConstantValue:[UIColor blackColor]]; [self.mapView.style addLayer:backgroundLayer]; MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-vector-line-layer-id" source:vectorSource]; lineLayer.sourceLayerIdentifier = @"contour"; - NSUInteger lineJoinValue = MGLLineJoinRound; - lineLayer.lineJoin = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue value:&lineJoinValue withObjCType:@encode(MGLLineJoin)]]; - NSUInteger lineCapValue = MGLLineCapRound; - lineLayer.lineCap = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue value:&lineCapValue withObjCType:@encode(MGLLineCap)]]; - lineLayer.lineColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor greenColor]]; + lineLayer.lineJoin = [NSExpression expressionForConstantValue:@"round"]; + lineLayer.lineCap = [NSExpression expressionForConstantValue:@"round"]; + lineLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor greenColor]]; [self.mapView.style addLayer:lineLayer]; } @@ -1388,19 +1387,19 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:routeSource]; MGLLineStyleLayer *baseRouteLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource]; - baseRouteLayer.lineColor = [MGLConstantStyleValue valueWithRawValue:[UIColor orangeColor]]; - baseRouteLayer.lineWidth = [MGLConstantStyleValue valueWithRawValue:@20]; - baseRouteLayer.lineOpacity = [MGLConstantStyleValue valueWithRawValue:@0.5]; - baseRouteLayer.lineCap = [MGLConstantStyleValue valueWithRawValue:[NSValue valueWithMGLLineCap:MGLLineCapRound]]; - baseRouteLayer.lineJoin = [MGLConstantStyleValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinRound]]; + baseRouteLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor orangeColor]]; + baseRouteLayer.lineWidth = [NSExpression expressionForConstantValue:@20]; + baseRouteLayer.lineOpacity = [NSExpression expressionForConstantValue:@0.5]; + baseRouteLayer.lineCap = [NSExpression expressionForConstantValue:@"round"]; + baseRouteLayer.lineJoin = [NSExpression expressionForConstantValue:@"round"]; [self.mapView.style addLayer:baseRouteLayer]; MGLLineStyleLayer *routeLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-route-layer" source:routeSource]; - routeLayer.lineColor = [MGLConstantStyleValue valueWithRawValue:[UIColor whiteColor]]; - routeLayer.lineWidth = [MGLConstantStyleValue valueWithRawValue:@15]; - routeLayer.lineOpacity = [MGLConstantStyleValue valueWithRawValue:@0.8]; - routeLayer.lineCap = [MGLConstantStyleValue valueWithRawValue:[NSValue valueWithMGLLineCap:MGLLineCapRound]]; - routeLayer.lineJoin = [MGLConstantStyleValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinRound]]; + routeLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor whiteColor]]; + routeLayer.lineWidth = [NSExpression expressionForConstantValue:@15]; + routeLayer.lineOpacity = [NSExpression expressionForConstantValue:@0.8]; + routeLayer.lineCap = [NSExpression expressionForConstantValue:@"round"]; + routeLayer.lineJoin = [NSExpression expressionForConstantValue:@"round"]; [self.mapView.style addLayer:routeLayer]; } @@ -1430,22 +1429,28 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { // source, categorical function that sets any feature with a "fill" attribute value of true to red color and anything without to green MGLFillStyleLayer *fillStyleLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fill-layer" source:shapeSource]; - NSDictionary *stops = @{@(YES): [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor greenColor]]}; - NSDictionary *fillColorOptions = @{MGLStyleFunctionOptionDefaultValue: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]}; - fillStyleLayer.fillColor = [MGLStyleValue<UIColor *> valueWithInterpolationMode:MGLInterpolationModeCategorical - sourceStops:stops - attributeName:@"fill" - options:fillColorOptions]; + fillStyleLayer.fillColor = [NSExpression expressionWithFormat:@"TERNARY(fill, %@, %@)", [UIColor greenColor], [UIColor redColor]]; // source, identity function that sets any feature with an "opacity" attribute to use that value and anything without to 1.0 - NSDictionary *fillOpacityOptions = @{MGLStyleFunctionOptionDefaultValue: [MGLStyleValue<NSNumber *> valueWithRawValue:@(1.0)]}; - fillStyleLayer.fillOpacity = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeIdentity - sourceStops:nil - attributeName:@"opacity" - options:fillOpacityOptions]; + fillStyleLayer.fillOpacity = [NSExpression expressionWithFormat:@"TERNARY(opacity != nil, opacity, 1.0)"]; [self.mapView.style addLayer:fillStyleLayer]; } +- (void)addLatLonGrid +{ + MGLComputedShapeSource *source = [[MGLComputedShapeSource alloc] initWithIdentifier:@"latlon" + options:@{MGLShapeSourceOptionMaximumZoomLevel:@14}]; + source.dataSource = self; + [self.mapView.style addSource:source]; + MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"latlonlines" + source:source]; + [self.mapView.style addLayer:lineLayer]; + MGLSymbolStyleLayer *labelLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"latlonlabels" + source:source]; + labelLayer.text = [NSExpression expressionForKeyPath:@"value"]; + [self.mapView.style addLayer:labelLayer]; +} + - (NSString *)bestLanguageForUser { // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview @@ -1912,4 +1917,52 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.hudLabel setTitle:hudString forState:UIControlStateNormal]; } +#pragma mark - MGLComputedShapeSourceDataSource + +- (NSArray<id <MGLFeature>>*)featuresInCoordinateBounds:(MGLCoordinateBounds)bounds zoomLevel:(NSUInteger)zoom { + double gridSpacing; + if(zoom >= 13) { + gridSpacing = 0.01; + } else if(zoom >= 11) { + gridSpacing = 0.05; + } else if(zoom == 10) { + gridSpacing = .1; + } else if(zoom == 9) { + gridSpacing = 0.25; + } else if(zoom == 8) { + gridSpacing = 0.5; + } else if (zoom >= 6) { + gridSpacing = 1; + } else if(zoom == 5) { + gridSpacing = 2; + } else if(zoom >= 4) { + gridSpacing = 5; + } else if(zoom == 2) { + gridSpacing = 10; + } else { + gridSpacing = 20; + } + + NSMutableArray <id <MGLFeature>> * features = [NSMutableArray array]; + CLLocationCoordinate2D coords[2]; + + for (double y = ceil(bounds.ne.latitude / gridSpacing) * gridSpacing; y >= floor(bounds.sw.latitude / gridSpacing) * gridSpacing; y -= gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(y, bounds.sw.longitude); + coords[1] = CLLocationCoordinate2DMake(y, bounds.ne.longitude); + MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; + feature.attributes = @{@"value": @(y)}; + [features addObject:feature]; + } + + for (double x = floor(bounds.sw.longitude / gridSpacing) * gridSpacing; x <= ceil(bounds.ne.longitude / gridSpacing) * gridSpacing; x += gridSpacing) { + coords[0] = CLLocationCoordinate2DMake(bounds.sw.latitude, x); + coords[1] = CLLocationCoordinate2DMake(bounds.ne.latitude, x); + MGLPolylineFeature *feature = [MGLPolylineFeature polylineWithCoordinates:coords count:2]; + feature.attributes = @{@"value": @(x)}; + [features addObject:feature]; + } + + return features; +} + @end |