flutter_map Integration

Stores also have the method getTileProvider(). This is the point of integration with flutter_map, providing browse caching through a custom image provider. This TileProvider can then be passed to the TileLayer.tileProvider parameter.

import 'package:flutter_map/flutter_map.dart';

class MapView extends StatefulWidget {
    late final tileProvider = FMTCStore('storeName').getTileProvider();
    
    Widget build(BuildContext context) {
        return FlutterMap(
            // options: MapOptions(),
            children: [
                TileLayer(
                    // Other config parameters
                    tileProvider: tileProvider,
                ),
            ],
        );
    }
}

Avoid getting the TileProvider from within the build method, especially if the widget is rebuilt frequently.

It can cause unnecessary errors and worsened performance.

Tile Provider Settings

This method (and others) optionally take a FMTCTileProviderSettings. These configure the behaviour of the tile provider. Defaults to the settings specified in the , or the package default (see table below) if that is not specified.

FMTCTileProviderSettings can take the following arguments:

Cache Behavior

This enumerable contains 3 values, which are used to dictate which logic should be used to store and retrieve tiles from the store.

Obscuring Query Parameters

Since v3, FMTC relies on URL equality to find tiles within a store during browsing. This method is therefore necessary in some cases where the URL contains query parameters.

If the URL's query parameters (the key-value pairs list found after the '?') contains a value that may change between fetches, such as an API key, use obscuredQueryParams.

This method strips specified keys and values from the query parameters, and avoids storing them in the database.

Pass it the list of query keys who's values need to be omitted from storage. For example, 'api_key' would remove the 'api_key', and any other characters until the next key-value pair, or the end of the URL, as seen below:

https://tile.myserver.com/{z}/{x}/{y}?api_key=001239876&mode=dark
https://tile.myserver.com/{z}/{x}/{y}?&mode=dark

Do not depend on this method to remove secret information from a URL.

Prefer sending any information (as discussed above) through the HTTP headers. This may improve performance and reliability, and can be considered good practise anyhow.

Check If A Tile Is Cached

Last updated

© Luka Stillingfleet (JaffaKetchup)