mapbox / mapbox/mapbox-gl-draw

Feature request - add `mapExists` to API

Open
#755 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api bug rendering
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.