TileLayer constructor

TileLayer({
  1. Key? key,
  2. String? urlTemplate,
  3. String? fallbackUrl,
  4. @Deprecated('`tileSize` is deprecated. Use `tileDimension` instead.') double? tileSize,
  5. int tileDimension = 256,
  6. double minZoom = 0,
  7. double maxZoom = double.infinity,
  8. int minNativeZoom = 0,
  9. int maxNativeZoom = 19,
  10. bool zoomReverse = false,
  11. double zoomOffset = 0.0,
  12. Map<String, String> additionalOptions = const {},
  13. List<String> subdomains = const ['a', 'b', 'c'],
  14. int keepBuffer = 2,
  15. int panBuffer = 1,
  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. TileBuilder? tileBuilder,
  24. EvictErrorTileStrategy evictErrorTileStrategy = EvictErrorTileStrategy.none,
  25. Stream<void>? reset,
  26. LatLngBounds? tileBounds,
  27. TileUpdateTransformer? tileUpdateTransformer,
  28. String userAgentPackageName = 'unknown',
})

Create a new TileLayer for the FlutterMap widget.

Implementation

TileLayer({
  super.key,
  this.urlTemplate,
  this.fallbackUrl,
  @Deprecated('`tileSize` is deprecated. Use `tileDimension` instead.')
  double? tileSize,
  int tileDimension = 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,
  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,
  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 {
  // If the tile provider doesn't define a User-Agent, we define it here.
  // This is so there's a convienient way for users to specifiy the agent
  // without always having to manually specify a tile provider and headers.
  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;
  // Deprecated assignment
  // ignore: deprecated_member_use_from_same_package
  this.tileSize = tileSize == null
      ? null
      : useSimulatedRetina
          ? (tileSize / 2).floorToDouble()
          : tileSize;
  this.tileDimension =
      useSimulatedRetina ? tileDimension ~/ 2 : tileDimension;
}