To use vector tiles in a flutter_map, replace the standard TileLayer with VectorTileLayer. You must first read a map style using StyleReader and then pass the resulting theme, sprites, and tileProviders to the layer.
// 1. Read the style
Future<Style> _readStyle() => StyleReader(
uri: 'https://tiles.stadiamaps.com/styles/osm_bright.json?api_key={key}',
apiKey: stadiaMapsApiKey,
logger: const Logger.console(),
).read();
// 2. Use in FlutterMap
FlutterMap(
mapController: _controller,
options: MapOptions(
center: style.center ?? LatLng(49.246292, -123.116226),
zoom: style.zoom ?? 10,
maxZoom: 22,
interactiveFlags: InteractiveFlag.drag |
InteractiveFlag.flingAnimation |
InteractiveFlag.pinchMove |
InteractiveFlag.pinchZoom |
InteractiveFlag.doubleTapZoom,
),
children: [
VectorTileLayer(
theme: style.theme,
sprites: style.sprites,
tileProviders: style.providers,
),
],
)
FlutterMap(
mapController: _controller,
options: MapOptions(
center: style.center ?? LatLng(49.246292, -123.116226),
zoom: style.zoom ?? 10,
maxZoom: 22,
interactiveFlags: InteractiveFlag.drag |
InteractiveFlag.flingAnimation |
InteractiveFlag.pinchMove |
InteractiveFlag.pinchZoom |
InteractiveFlag.doubleTapZoom,
),
children: [
VectorTileLayer(
theme: style.theme,
sprites: style.sprites,
tileProviders: style.providers,
),
],
)