mapbox / mapbox-gl-draw

Draw tools for mapbox-gl-js
https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/
ISC License
952 stars 593 forks source link

Feature request: cancel selection change #692

Closed IAfanasov closed 4 years ago

IAfanasov commented 7 years ago

I had scenario with validation. User should choose the polygon and fill it's properties. Like name, year and etc. This properties should be validated. I want to disallow user to select other object or clear selection before she correct all validation issues.

mcwhittemore commented 7 years ago

So, the quick answer is to use the draw.modechange event revert back to the state you want the user to be in.

The long answer is that this might be a really good mode modifier function. With custom modes now live, one could write a module that wraps a mode in a validation check.

var defaultDirectSelectMode = MapboxDraw.modes.directSelect;
var validator = require('mapbox-gl-draw-validate-features'); // what needs to be written
var validatorDirectSelectMode = validator(defaultDirectSelectMode, function(some, args) {
  return false; // stay in the same mode
  return true; // continue changing the mode
});

If this was written and published to npm, I'd love to put it in the custom modes docs

kkaefer commented 4 years ago

closing because this is not currently actionable