TileLayer constructor
TileLayer({
- Key? key,
- String? urlTemplate,
- String? fallbackUrl,
- double tileSize = 256,
- double minZoom = 0,
- double maxZoom = double.infinity,
- int minNativeZoom = 0,
- int maxNativeZoom = 19,
- bool zoomReverse = false,
- double zoomOffset = 0.0,
- Map<
String, String> additionalOptions = const {}, - List<
String> subdomains = const ['a', 'b', 'c'], - int keepBuffer = 2,
- int panBuffer = 1,
- @Deprecated('Prefer `MapOptions.backgroundColor`. ' 'This property has been removed simplify interaction when using multiple `TileLayer`s. ' 'This property is deprecated since v6.') Color? backgroundColor,
- ImageProvider<
Object> ? errorImage, - TileProvider? tileProvider,
- bool tms = false,
- WMSTileLayerOptions? wmsOptions,
- TileDisplay tileDisplay = const TileDisplay.fadeIn(),
- bool? retinaMode,
- ErrorTileCallBack? errorTileCallback,
- @Deprecated('Prefer creating a custom `TileProvider` instead. ' 'This option has been deprecated as it is out of scope for the `TileLayer`. ' 'This option is deprecated since v6.') TemplateFunction? templateFunction,
- TileBuilder? tileBuilder,
- EvictErrorTileStrategy evictErrorTileStrategy = EvictErrorTileStrategy.none,
- Stream<
void> ? reset, - LatLngBounds? tileBounds,
- TileUpdateTransformer? tileUpdateTransformer,
- String userAgentPackageName = 'unknown',
Implementation
TileLayer({
super.key,
this.urlTemplate,
this.fallbackUrl,
double tileSize = 256,
double minZoom = 0,
double maxZoom = double.infinity,
int minNativeZoom = 0,
int maxNativeZoom = 19,
this.zoomReverse = false,
double zoomOffset = 0.0,
this.additionalOptions = const {},
this.subdomains = const ['a', 'b', 'c'],
this.keepBuffer = 2,
this.panBuffer = 1,
@Deprecated(
'Prefer `MapOptions.backgroundColor`. '
'This property has been removed simplify interaction when using multiple `TileLayer`s. '
'This property is deprecated since v6.',
)
this.backgroundColor,
this.errorImage,
final TileProvider? tileProvider,
this.tms = false,
this.wmsOptions,
this.tileDisplay = const TileDisplay.fadeIn(),
/// See [RetinaMode] for more information
///
/// Defaults to `false` when `null`.
final bool? retinaMode,
this.errorTileCallback,
@Deprecated(
'Prefer creating a custom `TileProvider` instead. '
'This option has been deprecated as it is out of scope for the `TileLayer`. '
'This option is deprecated since v6.',
)
this.templateFunction,
this.tileBuilder,
this.evictErrorTileStrategy = EvictErrorTileStrategy.none,
this.reset,
this.tileBounds,
TileUpdateTransformer? tileUpdateTransformer,
String userAgentPackageName = 'unknown',
}) : assert(
tileDisplay.when(
instantaneous: (_) => true,
fadeIn: (fadeIn) => fadeIn.duration > Duration.zero,
)!,
'The tile fade in duration needs to be bigger than zero',
),
assert(
urlTemplate == null || wmsOptions == null,
'Cannot specify both `urlTemplate` and `wmsOptions`',
),
tileProvider = tileProvider ?? NetworkTileProvider(),
tileUpdateTransformer =
tileUpdateTransformer ?? TileUpdateTransformers.ignoreTapEvents {
// Debug Logging
if (kDebugMode &&
urlTemplate != null &&
urlTemplate!.contains('{s}.tile.openstreetmap.org')) {
Logger(printer: PrettyPrinter(methodCount: 0)).w(
'\x1B[1m\x1B[3mflutter_map\x1B[0m\nAvoid using subdomains with OSM\'s tile '
'server. Support may be become slow or be removed in future.\nSee '
'https://github.com/openstreetmap/operations/issues/737 for more info.',
);
}
if (kDebugMode &&
retinaMode == null &&
urlTemplate != null &&
urlTemplate!.contains('{r}')) {
Logger(printer: PrettyPrinter(methodCount: 0)).w(
'\x1B[1m\x1B[3mflutter_map\x1B[0m\nThe URL template includes a retina '
"mode placeholder ('{r}') to retrieve native high-resolution\ntiles, "
'which improve appearance especially on high-density displays.\n'
'However, `TileLayer.retinaMode` was left unset, meaning flutter_map '
'will never retrieve these tiles.\nConsider using '
'`RetinaMode.isHighDensity` to toggle this property automatically, '
'otherwise ensure\nit is set appropriately.\n'
'See https://docs.fleaflet.dev/layers/tile-layer#retina-mode for '
'more info.',
);
}
if (kDebugMode && kIsWeb && tileProvider is NetworkTileProvider?) {
Logger(printer: PrettyPrinter(methodCount: 0)).i(
'\x1B[1m\x1B[3mflutter_map\x1B[0m\nConsider installing the official '
"'flutter_map_cancellable_tile_provider' plugin for improved\n"
'performance on the web.\nSee '
'https://pub.dev/packages/flutter_map_cancellable_tile_provider for '
'more info.',
);
}
// Tile Provider Setup
if (!kIsWeb) {
this.tileProvider.headers.putIfAbsent(
'User-Agent', () => 'flutter_map ($userAgentPackageName)');
}
// Retina Mode Setup
resolvedRetinaMode = (retinaMode ?? false)
? wmsOptions == null && (urlTemplate?.contains('{r}') ?? false)
? RetinaMode.server
: RetinaMode.simulation
: RetinaMode.disabled;
final useSimulatedRetina = resolvedRetinaMode == RetinaMode.simulation;
this.maxZoom = useSimulatedRetina && !zoomReverse ? maxZoom - 1 : maxZoom;
this.maxNativeZoom =
useSimulatedRetina && !zoomReverse ? maxNativeZoom - 1 : maxNativeZoom;
this.minZoom =
useSimulatedRetina && zoomReverse ? max(minZoom + 1.0, 0) : minZoom;
this.minNativeZoom = useSimulatedRetina && zoomReverse
? max(minNativeZoom + 1, 0)
: minNativeZoom;
this.zoomOffset = useSimulatedRetina
? (zoomReverse ? zoomOffset - 1.0 : zoomOffset + 1.0)
: zoomOffset;
this.tileSize =
useSimulatedRetina ? (tileSize / 2.0).floorToDouble() : tileSize;
}