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.75k stars 860 forks source link

[BUG] Tiles sometimes do not load until extra event #1813

Open coogle opened 9 months ago

coogle commented 9 months ago

What is the bug?

I'm not sure what exactly to report as the bug, but I have a situation where I am using an animation to move my map programmatically using the following code. The animation works pretty well, but at the end of the animation I end up with a totally gray map until I interact with it again (e.g. slightly zoom out or move the map by dragging).

All of the other layers render except the tile layer. I'm not seeing any network traffic downloading the tiles, but that said when the map does render after manual intervention it loads instantly (so it already had the tiles).

    void _smoothMoveMapTo(Location destination, double destZoom)
    {
        final latTween = Tween<double>(
            begin: context.read<MapBloc>().mapController.center.latitude,
            end: destination.latitude
        );

        final lonTween = Tween<double>(
            begin: context.read<MapBloc>().mapController.center.longitude,
            end: destination.longitude
        );

        final zoomTween = Tween<double>(
            begin: context.read<MapBloc>().mapController.camera.zoom,
            end: destZoom
        );

        final animation = CurvedAnimation(
            parent: _animationCtl,
            curve: Curves.fastOutSlowIn
        );

        _animationCtl.addListener(() => context.read<MapBloc>()
            .mapController.move(
                Location(latTween.evaluate(animation), lonTween.evaluate(animation)),
                zoomTween.evaluate(animation)
            )
        );

        _animationCtl.forward(from: 0);
    }

How can we reproduce it?

See provided animation controller which moves a map.

Do you have a potential solution?

As a workaround, or perhaps to fix a bug in my code because I missed something, I'm trying to figure out how to trigger whatever is happening when I manually interact with the map after moving to my destination to actually redraw it. Notably, I've tried ending the animation with one last move ... including on a slight delay .. to no effect.

Platforms

Flutter Web

Severity

Minimum: Allows normal functioning

josxha commented 9 months ago

As far as I know, the tile layer checks if tiles need to be purged or loaded when a MapEventWithMove is emitted. move, rotate and so on all trigger a child object of this event and therefore update the tiles.


I'm sorry but I'm not sure if I can reproduce your described problem with your code snipped.

However in the example app if you trigger a second animation before the first has ended, the tiles won't be loaded. Could this be related to your described issue?

https://github.com/fleaflet/flutter_map/assets/34318751/cc5e9800-cf69-43bd-85e8-5a4bc1b5936a

You can try it out yourself on https://demo.fleaflet.dev/map_controller_animated

coogle commented 9 months ago

That's actually exactly what I am experiencing.. but I'm not sure how I'd be calling the animation twice! Seeing as this is in the demo, does that mean there isn't really a fix available?

josxha commented 9 months ago

If both has the same cause it's probably the best to check in your app if any animations is going on before starting a second animation. I'm still not sure why exactly this bug occurs, my guess would be somewhere in the tile manager.

I'm sorry to say but I don't think that there will be an fix any time soon because all resources are currently on performance tweaks and gestures. However we are happy to accept pull requests if you find the time to investigate. (:

josxha commented 9 months ago

@coogle Btw you could try the flutter_map_animations plugin. It's written by a flutter_map maintainer. Maybe the problem doesn't occur when using it.

coogle commented 9 months ago

I'll check out the plugin, thanks for the suggestion! I agree it's def. related to the Tiles specifically because in my situation I have multiple custom layers which render just fine post-animation.. it's only the tile layers that break. If I happen to figure out what's wrong I'll throw up a PR but I'm under a gun right now so it's more likely I'll just skip the animation for now until I get some more breathing room.

JaffaKetchup commented 9 months ago

There's some similarities to #1808's broken fix. I bet if that issue is fixed (tiles not loading after prune), this issue will be fixed as well.

shrijanRegmi commented 7 months ago

I am using flutter_map_animations and I am having the exact same issue.

Albert221 commented 5 months ago

I have the same as in the https://github.com/fleaflet/flutter_map/issues/1813#issue-2103948335 and https://github.com/fleaflet/flutter_map/issues/1813#issuecomment-1913562337, after I call MapController.move then I see no tiles, only after making a gesture on the map the tiles do load. Flutter 3.19.5, both iOS and Android.

My workaround as I'm also using the flutter_map_animations is using the AnimatedMapController.animateTo with zero duration.

JaffaKetchup commented 2 months ago

Although this bug occurs rarely, I have assigned P1, as fixing this may help to fix a number of other bugs.

JaffaKetchup commented 1 month ago

When #1943 is merged, this issue will still prevent proper functioning of reset.

JaffaKetchup commented 1 month ago

1602 should also be checked after a fix to this issue.