Skip to content

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

@ibrierley

Description

@ibrierley

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue reports broken functionality or another error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions