Skip to content

[BUG] onStyleLoaded is called before style is fully loaded #559

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

Open
albertmoravec opened this issue Mar 18, 2025 · 1 comment
Open

[BUG] onStyleLoaded is called before style is fully loaded #559

albertmoravec opened this issue Mar 18, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@albertmoravec
Copy link
Contributor

albertmoravec commented Mar 18, 2025

Platforms

web

Version of flutter maplibre_gl

0.20.0

Bug Description

onStyleLoaded callback is called before style loading is actually done.
The issue is described more in-depth here: mapbox/mapbox-gl-js/issues/2268.

Steps to Reproduce

Testing

  1. Define an onStyleLoaded callback which adds a new GeoJSON (or possibly other) source immediately after it is called.
  2. Quickly switch between different style definitions (e.g. from basic to satellite map and back) - wait for onStyleLoaded to be called before switching to the next.
  3. Check for the added source's existence after some time.

Expected Results

Source should still be present and not overwritten by newly loaded style.

Actual Results

Source added in onStyleLoaded callback is no longer present, as it was overwritten by the loaded style, even though onStyleLoaded was called earlier.

Code Sample

Only general idea provided, as checking for source existence is currently not possible (I added my own hasSource() implementation to maplibre-gl-web to test this)

In onStyleLoaded:

await controller.addGeoJsonSource(
  'dummy_source',
  {"type": "FeatureCollection", "features": []},
);

Future.delayed(
  const Duration(seconds: 3),
 () async => print('Has source: ${await controller.hasSource('dummy_source')}'),
);
@thanhdt-vietmap
Copy link
Contributor

Maybe I know this bug, it happened on our fork. The problem is that the map loaded the style successfully, but the SDK has not rendered the map. If you add any layer to the map during this time, your app will crash. The solution is native SDK has an onMapRendered callback, and putting your code in this function will not meet any problem. Let me open a PR for this callback.
Ah, I just have experience with Android and iOS SDK, so I don't know if web SDK has this callback @@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants