メインコンテンツまでスキップ

Set a style

When adding a map to an Flutter application using the Maps SDK, the map's style dictates the visual design of the map, including colors, labels, and feature visibility. It also includes information about data sources, and is used by the SDK to fetch the appropriate data necessary to render the map.

By default the Maps SDK for Flutter uses the Mapbox Standard style, which is a versatile and visually appealing map style suitable for many applications. Mapbox Standard offers many configuration options, allowing developers to customize the map's appearance to suit the needs of their application. If a completely unique look and feel is needed for the map, developers can create custom styles using Mapbox Studio, which can then be loaded into the map.

Once a style is loaded, you can continue to manipulate it at runtime, changing the appearance of the map by changing style configurations, adding or removing layers, changing layer properties, and more. This guide explains how to set and configure a style when initializing a map and how to switch styles dynamically during runtime.

Load a style

The Maps SDK provides an embeddable map interface using MapWidget. To render a map in the MapWidget, you will need to determine which style the renderer should use. You can rely on the Mapbox Standard Style which is loaded by default, or you can specify another style.

Mapbox Standard

Mapbox Standard is our general-purpose map style that is designed to be used in a wide range of applications, suitable for most use cases and includes a variety of configuration options to customize the map's appearance.

Mapbox Standard is the default style, and instantiating a MapWidget without specifying any style means your map will use Mapbox Standard.

// Loads Mapbox Standard Style by default.
MapWidget();

Custom styles

You can also create your own custom styles using the Mapbox Studio style editor. Custom styles can be used to create a unique look and feel for your map, tailored to your application's design needs. You can use Mapbox Standard edited in Mapbox Studio or any other style as a base—or start from scratch entirely. Learn how to customize Standard in this tutorial, how to build a style from scratch in this guide or explore our style gallery.

You can specify a style to use when you instantiate a map using a Style URL, a Style Constant, or a Style JSON string.

Load a style using a Style URL

You can specify the initial style URI with MapWidget.styleUri, or load it at runtime using MapboxMap.loadStyleURI:

mapboxMap.loadStyleURI("mapbox://styles/your-mapbox-username/your-custom-style-url");

Load a Mapbox style using a Style Constant

If you are using a Mapbox-designed style, you can use convenience variables instead of the full style URL. This will also make sure you're using the latest version of the style:

Style NameSDK Constant
Mapbox StandardStyle.STANDARD
Mapbox Standard SatelliteStyle.STANDARD_SATELLITE

Legacy Mapbox map styles (no longer maintained by Mapbox)

Style NameSDK Constant
Mapbox StreetsStyle.MAPBOX_STREETS
Mapbox LightStyle.LIGHT
Mapbox DarkStyle.DARK
Mapbox OutdoorsStyle.OUTDOORS
Mapbox SatelliteStyle.SATELLITE
Mapbox Satellite StreetsStyle.SATELLITE_STREETS
MapWidget(styleUri: MapboxStyles.STANDARD_SATELLITE);
Use loadStyleJSON

Though less common, you can also use MapboxMap.loadStyleJson to load a style if you've written your style JSON manually.

Configure a style

Depending on which map style you choose, you have different configuration options available to customize aspects of your style such as fonts, colors, and more.

Mapbox Standard

Mapbox Standard and Mapbox Standard Satellite are our default, all-purpose map styles, and are recommended for most use cases. Unlike our classic styles, Mapbox Standard and Mapbox Standard Satellite provide a limited set of configurations instead of allowing for full manipulation of the style.

Each style can be configured with several options, including light presets, label visibility, feature visibility, color theming, and fonts, and more. You can set these at runtime using the setStyleImportConfigProperty method.

PLAYGROUND
Mapbox Standard Style Playground

Using this interactive tool, you can see in real-time how different configuration options affect the Mapbox Standard or Mapbox Standard Satellite styles.

All configuration properties for Mapbox Standard are also available for Mapbox Standard Satellite except for toggling 3D objects and color theming. To learn more about configuration options, refer to the Mapbox Standard Guide and the Mapbox Standard API Reference Docs.

The following sample code shows how to change the 3D lights from the default preset, day, to another preset, dusk, by setting the lightPreset property. The code also shows how to hide the point of interest labels by setting the showPointOfInterestLabels property to false. For both, the first parameter is the name of the style import, which is basemap for Mapbox Standard.

mapboxMap.style.setStyleImportConfigProperty("basemap", "lightPreset", "dusk");
mapboxMap.style.setStyleImportConfigProperty("basemap", "showPointOfInterestLabels", false);

All configurations are also available in Mapbox Studio, where you can create a custom style that imports Mapbox Standard or Mapbox Standard Satellite and adjust the configurations as needed.

Custom styles

Custom styles can be configured by calling methods to update the properties of the style. The most common configurations are updates to layer properties, such as changing the color of a line or the visibility of a label.

For example, you may want to hide an existing layer by setting its visibility to none, or change the color of a fill layer by setting its fill-color property. Learn more about updating layers in the Work with sources and layers guide.

mapboxMap.style.setStyleURI(MapboxStyles.MAPBOX_STREETS);
mapboxMap.style.setStyleLayerProperty("water", "fill-color", Value.valueOf("#45d9ca"));

This approach requires knowing the ids and types of layers in the style and understanding the properties that can be updated for each layer type. You can explore the properties available for a given layer type in the Mapbox Style Specification.

An alternative approach to adding many runtime configuration changes for a style is to create a custom style in Mapbox Studio. You can make the desired changes in the style editor and load the custom style in your application.

Change to a different style

You can change the style any time after initializing the map using the setStyleURI method.

mapboxMap.style.setStyleURI(MapboxStyles.STANDARD_SATELLITE);

If you added any layers after map initialized, you will need to re-add them after the new style is loaded or use the addPersistentStyleLayer method when adding any layers to the initial style.

このpageは役に立ちましたか?