Skip to content

Instantly share code, notes, and snippets.

@boundsj
Created September 7, 2016 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boundsj/168eb88eb8808edb2c10ae210ccb95f6 to your computer and use it in GitHub Desktop.
Save boundsj/168eb88eb8808edb2c10ae210ccb95f6 to your computer and use it in GitHub Desktop.
style_vector_layer
- (void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView
{
    [self.mapView setStyleURL:[MGLStyle darkStyleURLWithVersion:9]];
    
    NSURL *url = [[NSURL alloc] initWithString:@"mapbox://mapbox.mapbox-terrain-v2"];
    MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithSourceIdentifier:@"terrain-data" URL:url];
    [self.mapView.style addSource:vectorSource];
    
    MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithLayerIdentifier:@"background"];
    backgroundLayer.backgroundColor = [UIColor blackColor];
    [self.mapView.style addLayer:backgroundLayer];
    
    MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithLayerIdentifier:@"terrain-data" source:vectorSource sourceLayer:@"contour"];
    NSUInteger lineJoineValue = (NSUInteger)MGLLineStyleLayerLineJoinRound;
    [lineLayer setLineJoin:[NSValue value:&lineJoineValue withObjCType:@encode(MGLLineStyleLayerLineJoin)]];
    NSUInteger lineCapValue = (NSUInteger)MGLLineStyleLayerLineCapRound;
    [lineLayer setLineCap:[NSValue value:&lineCapValue withObjCType:@encode(MGLLineStyleLayerLineCap)]];
    [lineLayer setLineColor:[UIColor greenColor]];
    [self.mapView.style addLayer:lineLayer];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment