mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

Feature request - add `mapExists` to API

Open locomotif opened this issue 8 years ago • 1 comments

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.

locomotif avatar Mar 13 '18 19:03 locomotif

@locomotif - I'm ok with adding this if you have an inbound PR. Lets name it isReady to imply the purpose a bit better and please remember to add tests and docs. Thanks!

mcwhittemore avatar Mar 14 '18 16:03 mcwhittemore