Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Markers not displaying on first map display (map doesn't have a size on certain devices). #1334

Closed
5 tasks done
ibrierley opened this issue Aug 3, 2022 · 4 comments · Fixed by #1333
Closed
5 tasks done
Labels
bug This issue reports broken functionality or another error

Comments

@ibrierley
Copy link
Collaborator

What is the bug?

When you look at the example HomePage, there should be 3 markers. Only one displays until you move the map.

(This works fine on the web, but not on some devices, tested on Android Redmi Note 10).

What is the expected behaviour?

All 3 markers should appear.

How can we reproduce this issue?

Just run the example home page.

Do you have a potential solution?

This is the likely issue.

When we run the marker_layer code, we do the following, to try and eliminate drawing markers out of bounds.

if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) {
        continue;
}

However, if we look at the bounds, they are Bounds(CustomPoint (4093.0, 2724.0), CustomPoint (4093.0, 2724.0)) , so one pixel wide. So the markers get rejected apart from the one placed in the middle coincidentally.

The reason for that, is that in map.dart we call getPixelBounds()

Bounds getPixelBounds(double zoom) {
    final mapZoom = zoom;
    final scale = getZoomScale(mapZoom, zoom);
    final pixelCenter = project(center, zoom).floor();
    final halfSize = size / (scale * 2);
    return Bounds(pixelCenter - halfSize, pixelCenter + halfSize);
  }

And here, on first run it has a size of (0.0, 0.0)

So basically any code that calls things like pixelBounds.containsPartialBounds() won't work if it hasn't had chance to get a size (I think this is because the LayoutBuilder in flutter_map_state.dart context/constraints also has no size then, and even things like WidgetsBinding.instance.window.physicalSize returns 0,0).

There's probably some other subtle bugs all around this on first display.

Not sure of the best solution on this, as we've been here before. Maybe we should force FlutterMap to run 2 passes first time around, but then will it draw something wrong on the first pass, then right on the 2nd. Not quite sure of an elegant solution to this one (but there is some possibly boiler plate code that could be removed if we did).

Or possibly something like place it in an Offstage widget that doesn't draw first pass, then move it into view (could actually be a feature to make FlutterMap visible or not ? Not sure, just thinking out loud).

Can you provide any other information?

No response

Platforms Affected

Android

Severity

Minimum: Allows normal functioning

Frequency

Consistently: Always occurs at the same time and location

Requirements

  • I agree to follow this project's Code of Conduct
  • My Flutter/Dart installation is unaltered, and flutter doctor finds no relevant issues
  • I am using the latest stable version of this package
  • I have checked the FAQs section on the documentation website
  • I have checked for similar issues which may be duplicates
@ibrierley ibrierley added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Aug 3, 2022
@JaffaKetchup
Copy link
Member

JaffaKetchup commented Aug 3, 2022

Also can reproduce on my Redmi Note 10 Pro (what are the chances of that!).

@JaffaKetchup JaffaKetchup removed the needs triage This new bug report needs reproducing and prioritizing label Aug 3, 2022
@mootw
Copy link
Collaborator

mootw commented Aug 4, 2022

I have been working on rewriting the state management and now have flutter_map correctly initializing the map variables (other than buildconstraints on initState and the first build correctly gets constraints before building children. This also has the added benefit of not needing variables to be nullable.

does #1333 fix this for you?

I CANNOT replicate using flutter_map-2.2.0

@ibrierley
Copy link
Collaborator Author

Yes, this seems to work ok with latest proposed changes, nice!

Can't find anything worse off (there's just a line 194 print("Skipping due to bounds"); in the marker_layer code that slows down panning slightly on Many Markers, I assume that can just be removed though)

@mootw
Copy link
Collaborator

mootw commented Aug 4, 2022

yeah I left the print in on accident. it's removed now. I will mark the pr as closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants