TileLayer constructor

TileLayer({
  1. Key? key,
  2. String? urlTemplate,
  3. String? fallbackUrl,
  4. double tileSize = 256,
  5. double minZoom = 0,
  6. double maxZoom = double.infinity,
  7. int minNativeZoom = 0,
  8. int maxNativeZoom = 19,
  9. bool zoomReverse = false,
  10. double zoomOffset = 0.0,
  11. Map<String, String> additionalOptions = const {},
  12. List<String> subdomains = const ['a', 'b', 'c'],
  13. int keepBuffer = 2,
  14. int panBuffer = 1,
  15. @Deprecated('Prefer `MapOptions.backgroundColor`. ' 'This property has been removed simplify interaction when using multiple `TileLayer`s. ' 'This property is deprecated since v6.') Color? backgroundColor,
  16. ImageProvider<Object>? errorImage,
  17. TileProvider? tileProvider,
  18. bool tms = false,
  19. WMSTileLayerOptions? wmsOptions,
  20. TileDisplay tileDisplay = const TileDisplay.fadeIn(),
  21. bool? retinaMode,
  22. ErrorTileCallBack? errorTileCallback,
  23. @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,
  24. TileBuilder? tileBuilder,
  25. EvictErrorTileStrategy evictErrorTileStrategy = EvictErrorTileStrategy.none,
  26. Stream<void>? reset,
  27. LatLngBounds? tileBounds,
  28. TileUpdateTransformer? tileUpdateTransformer,
  29. 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;
}