mapbox / mapbox/mapbox-gl-draw
Feature request - add `mapExists` to API
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
mapbox-gl-js version: 0.42.2
mapbox-gl-draw version: 1.0.4
Expected Behavior
use of api.add paints the feature to the map
Actual Behavior
Sometimes it paints, sometimes it doesn't
Reason for bug and or feature request
If needed I can try to create a project to reproduce. In my current project, I have behavior that hydrates the map with features, when the mapbox-gl-draw is instantiated; however, there are situations that my features are being added to the store but not being rendered.
The cause: In render.js there is a check, mapExists which executes cleanup() on false. This cleanup clears the changedFeaturesIds object; therefore any object that was added to the store when mapExists is false, is no longer able to be rendered on any consecutive render calls; because they are no longer registered as changed. Hope this makes sense.
The issue is that map.getSource() must have some latency issues, because sometimes they render and sometimes they don't due to map.getSource() returning undefined.
I have a forked version where I added the following to the api:
api.mapExists = function() {
return ctx.map &&
ctx.map.getSource(Constants.sources.HOT) !== undefined;
};
Now my app can check for truthy before executing api.add
Thanks for all your great work.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in render.js and trace how api.add updates the store and how the mapExists check calls cleanup(). Review the API entry points around api.add and the proposed mapExists behavior, then verify that features added before the map source exists can still render once the source is available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100