Skip to content

feat: show a background grid while map tiles load - #2259

Open
ben-milanko wants to merge 1 commit into
fleaflet:masterfrom
ben-milanko:codex/loading-grid
Open

feat: show a background grid while map tiles load#2259
ben-milanko wants to merge 1 commit into
fleaflet:masterfrom
ben-milanko:codex/loading-grid

Conversation

@ben-milanko

Copy link
Copy Markdown
Contributor

Empty map areas currently show a flat background while tiles load. Add a subtle grid beneath all map layers, enabled by default with 64 logical pixel cells at integer zoom levels. It follows panning, zooming, and rotation, and opaque tiles cover it as they fade in. Existing fallback tiles continue to cover the grid while replacement tiles load.

Loading grid behind partially rendered map tiles

Expose MapOptions.backgroundGridColor and MapOptions.backgroundGridSpacing for customization. Setting backgroundGridColor: null restores the plain background. Fully transparent map backgrounds remain transparent. When disabled, the background uses the existing plain ColoredBox without a grid painter or camera dependency.

This intentionally changes the default map appearance. The grid is a background decoration, so it also remains visible through transparent tiles and in areas without tiles. The Tile Builder example includes a toggle, and the API documentation describes these behaviors.

Validation:

  • All 148 tests pass on the clean upstream-based branch, including 8 new tests for rendered grid pixels, partial loading, fade-in, fallback tiles, camera movement, customization, transparency, and gestures.
  • Analysis passes for the library, tests, and example page; formatting checks pass for all changed Dart files.
  • Tested with Flutter 3.41.9 / Dart 3.11.5. Minimum-supported-SDK validation remains for CI.

Developed and checked with OpenAI Codex; the validation listed above ran locally.

@JaffaKetchup JaffaKetchup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for contributing! There are a few things to follow up on, but overall I think this is a nice addition.

(For completeness, it might be worth mentioning the old plugin which added a latlng grid layer, but that's a different purpose and also isn't updated to the latest versions, so it's mostly irrelevant here.)


class TileBuilderPageState extends State<TileBuilderPage> {
bool enableGrid = true;
bool showBackgroundGrid = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong place to demo this functionality.

Since it will be enabled by default, and it is minimally different, I don't think any example is necessary.

/// Set to `null` to disable it. A fully transparent [backgroundColor] also
/// disables the grid.
///
/// Enabled by default with a subtle black line color (`0x14000000`).

@JaffaKetchup JaffaKetchup Sep 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea that a transparent backgroundColor automatically disables the grid.

However, this we should also automatically adjust the colour of the grid based on the background colour (to improve DX). Maybe by converting the background color into HSL, then ± the lightness value by maybe 10% (or something similar) based on whether the lightness is less than or more than 50%.

This means that null now means auto-calculate, not disabled. Therefore, another switch is required to enable/disable the grid. Therefore, there's two options:

  • Use a sub-options class/object called BackgroundGridOptions - then if the parameter backgroundGrid is null, it's disabled, but the default is a const BackgroundGridOptions() which is enabled and automatic colour and default grid spacing
  • Convert the whole grid into a layer - the obvious drawback of this is it requires adding manually even though the grid behaviour is a nice improvement that I would imagine would be welcomed (if even noticed) by most users, and it breaks the semantics by having the background configured in two different places

I think it's worth keeping it in the options, even though it technically is more like another layer. So the first option is probably the best, but willing to hear otherwise from anyone :) (@fleaflet/maintainers ?)

if (gridColor == null || gridColor.a == 0 || color.a == 0) {
return ColoredBox(color: color);
}
final camera = MapCamera.of(context);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this should be the first line in build.

return RepaintBoundary(
child: ColoredBox(
color: color,
child: IgnorePointer(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: what is the point in this IgnorePointer? There might be one, I just can't find any difference with or without?

Comment thread README.md
Comment on lines +5 to +9
Maps show a subtle background grid while tiles load. It moves with the map and
is covered as tiles render. Customize it with `MapOptions.backgroundGridColor`
and `MapOptions.backgroundGridSpacing`, or set `backgroundGridColor: null` to
use a plain background. Fully transparent map backgrounds remain transparent.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't add documentation into the README. I'll add it into the docs later if merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants