fleaflet / flutter_map

A versatile mapping package for Flutter. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
https://pub.dev/packages/flutter_map
BSD 3-Clause "New" or "Revised" License
2.76k stars 863 forks source link

[FEATURE] loadingTileDisplay for TileLayer #1980

Closed edeetee closed 1 month ago

edeetee commented 1 month ago

What do you want implemented?

Fallback to show a custom tile while tile is loading.

For my use case, I have a tile server serving transparent tiles. The tiles are mostly content:

Screenshot 2024-10-19 at 6 11 42 PM

When I load new tiles, the map doesn't render anything where it hasn't yet loaded:

Screenshot 2024-10-19 at 6 12 33 PM

It would be ideal if I had some way to provide a custom tile that can render content in the loading area. I would render with the transparent red I am using elsewhere.

For context, here is my layer code, containing an Opacity widget:

class NavigationAvailabilityOverlay extends ConsumerWidget {
  const NavigationAvailabilityOverlay({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Opacity(
      opacity: 0.5,
      child: TileLayer(
        tileProvider: CancellableNetworkTileProvider(),
        tileUpdateTransformer: TileUpdateTransformers.throttle(
          const Duration(milliseconds: 500),
        ),
        urlTemplate:
            "$devOrigin/routing/availability_tile.png?z={z}&y={y}&x={x}",
        tileDisplay: const TileDisplay.instantaneous(),
        maxNativeZoom: 22,
      ),
    );
  }
}

What other alternatives are available?

I could add a background layer but this wouldn't work with the transparent tiles.

Can you provide any other information?

I could be interested in implementing a pr if someone can give me some guidance to where I should start in the TileLayer code.

Severity

Annoying: Currently have to use workarounds

josxha commented 1 month ago

Hi @edeetee, this functionality is already possible using the tileBuilder. Return your loading widget when tile.loadFinishedAt is null.