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

style.addSource throws a PlatformException but style.getSource does not return the existing source #838

Open
Daeon97 opened this issue Jan 21, 2025 · 2 comments

Comments

@Daeon97
Copy link

Daeon97 commented Jan 21, 2025

I have

late final Source? source;

try {
  source = await style.getSource(
    'sourceId',
  );
} catch (_) {
    source = null;
}

Which returns a null on the ID sourceId. However when I try to add the source using the same ID sourceId

final geoJsonFeatureCollection = ...

final newSource = GeoJsonSource(
  id: 'sourceId',
  data: json.encode(
    geoJsonFeatureCollection,
  ),
);

await style.addSource(
  newSource,
);

I get a PlatformException(0, Source sourceId already exists, null, null)

I can't seem to get why this may be happening. Any pointers will be highly appreciated

PS: I am currently using version 2.3.0 of this library

@Daeon97
Copy link
Author

Daeon97 commented Jan 21, 2025

I have modified my code to use a try {...} catch(...) {...} block at the point where the PlatformException is thrown. I now have

try {
  await style.addSource(
    newSource,
  );
  } catch (_) {
  await style.removeStyleSource(
    'sourceId',
  );
  
  await style.addSource(
    newSource,
  );
}

However the line

await style.removeStyleSource(
  'sourceId',
);

throws a PlatformException(0, Source sourceId is not in style, null, null)

But if sourceId is not in style why is

await style.addSource(
  newSource,
);

throwing a PlatformException(0, Source sourceId already exists, null, null) in the first place. These are 2 contradictory error messages. I have no idea what is happening here

@Daeon97
Copy link
Author

Daeon97 commented Jan 21, 2025

I just upgraded to the latest version of this library as of now, Tuesday January 21st 2025 which is version 2.5.1. I am still experiencing this problem. I have also verified that this issue is happening on both Android and iOS

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

1 participant