Getting A Tile Provider

See 4. Connect to 'flutter_map' in the Quickstart guide for an example.

To integrate caching (known as 'browse caching' in FMTC), FMTC provides FMTCTileProvider, which can be set in TileLayer.tileProvider. The tile provider can communicate with the cache and get tiles from the network.

link

To know which stores to use from the cache, one or more store names may be specified, each with a BrowseStoreStrategy.

Additionally, the argument otherStoresBehavior may be used to set the BrowseStoreStrategy for all unspecified stores. If null, then no unspecified stores will be used.

BrowseStoreStrategy

The BrowseStoreStrategy determines when tiles should be written to a store during browse caching. There are 3 available stratefies:

  1. read Only read tiles from the associated store

  2. readUpdate In addition to reading tiles, update existing tiles, but don't cache any new ones

  3. readUpdateCreate Read, update, and create tiles

Specifying Stores

Avoid getting/constructing the TileProvider from within the builder, especially if the widget is rebuilt frequently.

Using A Single Specified Store

To get an instance of the tile provider when only using a single store (except for otherStoresBehavior), use the following method:

final tileProvider = const FMTCStore('storeName').getTileProvider(
    storeStrategy: BrowseStoreStrategy.readUpdateCreate, // (optional, default)
    // Other options...
);

Using Multiple Specified Stores

To get an instance of the tile provider when using multiple stores, use the following method:

final tileProvider = FMTCTileProvider.multipleStores(
    storeNames: {
        'storeName': BrowseStoreStrategy.readUpdateCreate,
        'differentStoreName': BrowseStoreStrategy.readUpdateCreate,
    },
    // Other options...
);

Using All Stores

To get an instance of the tile provider that will use all stores with the same StoreReadWriteBehavior, use the following method:

final tileProvider = FMTCTileProvider.allStores(
    allStoresStrategy: BrowseStoreStrategy.readUpdateCreate,
    // Other options...
);

Last updated

© Luka Stillingfleet (JaffaKetchup)