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.68k stars 848 forks source link

[BUG] Map tiles from local storage not loading when internet speed is poor #1888

Closed hardikJoshi123 closed 1 month ago

hardikJoshi123 commented 1 month ago

What is the bug?

i am loding tails from local. but in my phone internet speed is very slow that time tails are not loading. if i am offline or i have good internet speed that time it's working fine

This my code :-

                  TileLayer(
                        maxZoom: maxZoom,
                        minZoom: minZoom,
                        backgroundColor: Colors.transparent,
                        tms: true,
                        tileProvider: map.FileTileProvider(),
                        urlTemplate: "/var/mobile/Containers/Data/Application/BF3C27D4-4EA1-46D2-9132-EC7076D9540C/Documents/Imittos_Full/Imittos_Full/{z}/{x}/{y}.webp",
                        tileBuilder: tileBuilder,
                      )

   Widget tileBuilder(BuildContext context, Widget tileWidget, map.TileImage tile) {
          final coords = tile.coordinates;

          return Container(
            decoration: BoxDecoration(
              border: grid ? Border.all() : null,
            ),
            child: Stack(
              fit: StackFit.passthrough,
              children: [
                tileWidget,
                if (loadingTime || showCoords)
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      if (showCoords)
                        Text(
                          '${coords.x.floor()} : ${coords.y.floor()} : ${coords.z.floor()}',
                          style: Theme.of(context).textTheme.headlineSmall,
                        ),
                      if (loadingTime)
                        Text(
                          tile.loadFinishedAt == null
                              ? 'Loading'
                          // sometimes result is negative which shouldn't happen, abs() corrects it
                              : '${(tile.loadFinishedAt!.millisecond - tile.loadStarted!.millisecond).abs()} ms',
                          style: Theme.of(context).textTheme.headlineSmall,
                        ),
                    ],
                  ),
              ],
            ),
          );
        }

How can we reproduce it?

  1. when i open map all tiles loaded if internet connectivity is good. But the problem here when I am at mountain having very weak signals / network connectivity, the app stuck and tiles are not loading (As per my screenshot below)

  2. form start internet is not good (poor) that time same issue facing. tiles are not loading

image_2024_05_23T06_57_30_711Z image_2024_05_23T06_57_38_977Z (1)

if internet is Good then tiles is loading and look like :- ImportedPhoto_1716448598050

Do you have a potential solution?

No response

Platforms

Android and iOS

Severity

Minimum: Allows normal functioning

JaffaKetchup commented 1 month ago

If a tile has failed, they will only be retried when the map moves enough for them to get a prune and load cycle in. The Internet is required to load the tiles, although caching plugins are available.

hardikJoshi123 commented 1 month ago

@JaffaKetchup The main problem here its loading map tiles properly if I do airplane mode and device do not have network connectivity at all. No any issues and concerns are produced from users. The problem is only when users are on mountains with weak signals. They are giving complains if they try by enabling airplanes mode, everything seems fine.

JaffaKetchup commented 1 month ago

Oh, apologies I completely missed the local part. Are you also trying to load online tiles when the network is available? The FileTileProvider is completely independent and not influenced by the network, so it's likely something else.

hardikJoshi123 commented 1 month ago

@JaffaKetchup Thanks for the prompt response. It would be really helpful.

I am adding 2 childrens. 1) First one is to load google map tiles 2) another widget is to load map tiles form local storage. This might causing an issue? (I've added code below)

Screenshot 2024-05-24 at 7 48 11 PM
JaffaKetchup commented 1 month ago

I'm not sure what's causing the issue here, but I can't see that it would be FM. If you can get an MRE working, please ping me and I'll be happy to look into this!