Switching Map Styles

The SDK supports multiple base map styles.

Enum

1
typedef NS_ENUM(NSUInteger, NGMapStyleType) {
2
Bright,
3
Night,
4
Satellite
5
};

Set Styles when Map is Initialized

Swift

1
// After your nbMapView is ready (e.g., in a delegate/callback)
2
nbMapView.setStyleWith(.Bright)

Objective-C

1
// Example if there is an Obj-C bridge
2
[nbMapView setStyleWith:Bright];

Best Practices & Notes

  • Coordinate with tiler changes: When you change the tile server, switch (or re-apply) the map style to force a clean reload of base tiles so users see the tiles from the new provider immediately.

  • Performance: Style changes reload resources. Bundle switches at natural UX moments (e.g., theme toggles).

  • Night mode: Consider mapping Night to your app’s dark theme or system appearance for consistency.

Verify Style Load Completion

You can verify that the map style has finished loading via the delegate callback. This is the safest point to add custom layers, sources, images, or adjust styling—your changes won’t be overwritten by subsequent style loads.

Objective-C

#pragma mark - NGLMapViewDelegate

1
- (void)mapView:(NGLMapView *)mapView didFinishLoadingStyle:(NGLStyle *)style {
2
// The style is fully loaded here.
3
// Example: add a geojson source and a symbol layer
4
NGLShapeSource *source = [[NGLShapeSource alloc] initWithIdentifier:@"pois" URL:[NSURL URLWithString:@"bundle://pois.geojson"] options:nil];
5
[style addSource:source];
6
7
NGLSymbolStyleLayer *layer = [[NGLSymbolStyleLayer alloc] initWithIdentifier:@"poi-layer" source:source];
8
layer.text = [NGLStyleValue valueWithRawValue:@"{name}"];
9
[style addLayer:layer];
10
11
// If you switched tile servers recently, this ensures that the tiles are rendered using the new provider.
12
}

Swift

1
// Ensure your class adopts NGLMapViewDelegate
2
extension YourViewController: NGLMapViewDelegate {
3
func mapView(_ mapView: NGLMapView, didFinishLoading style: NGLStyle) {
4
// The style is fully loaded here.
5
// Example: add a geojson source and a symbol layer
6
let url = URL(string: "bundle://pois.geojson")!
7
let source = NGLShapeSource(identifier: "pois", url: url, options: nil)
8
style.addSource(source)
9
10
let layer = NGLSymbolStyleLayer(identifier: "poi-layer", source: source)
11
layer.text = NGLStyleValue(rawValue: "{name}")
12
style.addLayer(layer)
13
14
// If you switched tile servers recently, this ensures that the tiles are rendered using the new provider.
15
}
16
}