mapbox / mapbox/mapbox-gl-draw

In a custom mode, feature properties are gone when displayFeatures is executed

Open
#925 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api bug
Dominant language
JavaScript
Stars
1.1k
Forks
612
Avg merge
8d 9h
Merged PRs (30d)
5

Description

mapbox-gl-js version: 1.3.0
mapbox-gl-draw version: 1.1.2

Steps to Trigger Behavior
  1. Create a custom mode. Override onclick method to add a point feature:
DrawSingleMeasurementLine.onClick = function(state, e) {
  // `this.newFeature` takes geojson and makes a DrawFeature
  var point = this.newFeature({
    type: 'Feature',
    properties: {
      meta: 'currentPosition',
      measurement: `100000000000000 km`
    },
    geometry: {
      type: 'Point',
      coordinates: [e.lngLat.lng, e.lngLat.lat]
    }
  });
  this.addFeature(point); // puts the point on the map
};

DrawSingleMeasurementLine.toDisplayFeatures = function(state, geojson, display) {
  console.log(geojson);
  display(geojson);
}
  1. Observe that in toDisplayFeatures() the custom properties meta and measurement are gone, the console log looks like this:
    image
Expected Behavior

Features added in a custom mode have all their properties persisted.
At this stage I can only fix this by setting the properties again in toDisplayFeatures, but this method is only executed when the mode is active. So, when the user deactivates the mode, the custom properties are gone and my feature doesn't render properly.
So it seems that addFeature() only saves the known properties.

Actual Behavior

Any custom feature properties are not persisting when adding to the map.

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 by reproducing the custom mode using newFeature, addFeature, and toDisplayFeatures as shown, and inspect the feature properties before and after displayFeatures runs and the mode is deactivated. Done means custom properties such as meta and measurement persist and the feature still renders correctly outside the active mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.