mapbox / mapbox-gl-draw

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

Override specific functions of modes #728

Closed divya1c closed 4 years ago

divya1c commented 6 years ago

Hi!

Is there a functionality by which I can override one of the functions of the simple select mode? I want to change only the trash() of SimpleSelect mode and keep everything the same.

Thanks!

eddydg commented 6 years ago

When you want to add a custom mode, you generally do:

const modes = MapboxDraw.modes;
modes.my_custom_mode = MyCustomMode;
const Draw = new MapboxDraw({ modes });

So maybe you could do something like this:

const modes = MapboxDraw.modes;
modes.simple_select.onTrash = ...
const Draw = new MapboxDraw({ modes });

Or just create your own custom mode, copy/paste simple_select and do your stuff.

mcwhittemore commented 6 years ago

The example that @eddydg provided should work in this case. If it does, can you submit a PR to update the custom mode docs to talk about this?