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

Method getLayer("puck") throws "Layer puck is not in style" #527

Open
AlbertoNoris opened this issue May 2, 2024 · 1 comment
Open

Method getLayer("puck") throws "Layer puck is not in style" #527

AlbertoNoris opened this issue May 2, 2024 · 1 comment

Comments

@AlbertoNoris
Copy link

AlbertoNoris commented May 2, 2024

On iOS (haven't tested Android) when trying to get the position of the user with the provided code in the example

    // wait until the style is loaded
    await state?.style.isStyleLoaded();

    // get the user position from the layer that contains the puck (the blue dot)
    Layer? layer;
    if (Platform.isAndroid) {
      layer = await state?.style.getLayer("mapbox-location-indicator-layer");
    } else {
      layer = await state?.style.getLayer("puck");
    }

    final userLocation = (layer as LocationIndicatorLayer).location;
    return Position(userLocation![1]!, userLocation[0]!);

as soon as the map is created then this error is thrown:

PlatformException (PlatformException(StyleError(rawValue: "Layer puck is not in style"), null, null, null))

Before updating to 1.1.0 from a pre 1.0.0 version this issue wasn't there; trying to get the position slightly after the map creation doesn't yield the Exception.

@evil159
Copy link
Contributor

evil159 commented May 6, 2024

@AlbertoNoris The location indicator layer is not added to the style until the first location update is reported by the platform, to avoid this error you can check if the layer exists in the style before trying to access it - styleLayerExists().

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

No branches or pull requests

2 participants