Reputation: 85
I want to use a custom mode in Mapbox Draw. I declare the draw object like this:
var draw = new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: false,
line_string: true,
point: false,
trash: true,
},
modes: Object.assign({
custom_mode: CustomMode,
}, MapboxDraw.modes),
});
Then I want to change the mode:
map.on('load', function () {
draw.changeMode("custom_mode");
map.addControl(draw, 'bottom-right');
});
Result: Error: Cannot read property 'changeMode' of undefined. But I can log the draw object just before the changeMode() call. What is the problem here?
Upvotes: 1
Views: 3447
Reputation: 257
In your load function add map.addControl above draw.changeMode("custom_mode")
Upvotes: 2
Reputation: 244
You need to add your object first
map.addControl(draw, 'top-left')
Upvotes: 4