mapbox / mapbox/mapbox-gl-draw
In a custom mode, feature properties are gone when displayFeatures is executed
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: 1.3.0
mapbox-gl-draw version: 1.1.2
Steps to Trigger Behavior
- 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);
}
- Observe that in toDisplayFeatures() the custom properties meta and measurement are gone, the console log looks like this:

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
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 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