Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draw_circle button to MapboxDraw controls #1

Open
zakjan opened this issue Jul 29, 2020 · 3 comments
Open

Add draw_circle button to MapboxDraw controls #1

zakjan opened this issue Jul 29, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@zakjan
Copy link
Owner

zakjan commented Jul 29, 2020

Currently there is no API for adding custom buttons, see mapbox/mapbox-gl-draw#874

@zakjan zakjan added the enhancement New feature or request label Jul 29, 2020
@Aliber009
Copy link

Aliber009 commented Apr 7, 2021

Actually there s one , I will share it with you :
class extendDrawBar {
constructor(opt) {
let ctrl = this;
ctrl.draw = opt.draw;
ctrl.buttons = opt.buttons || [];
ctrl.onAddOrig = opt.draw.onAdd;
ctrl.onRemoveOrig = opt.draw.onRemove;
}
onAdd(map) {
let ctrl = this;
ctrl.map = map;
ctrl.elContainer = ctrl.onAddOrig(map);
ctrl.buttons.forEach((b) => {
ctrl.addButton(b);
});
return ctrl.elContainer;
}
onRemove(map) {
let ctrl = this;
ctrl.buttons.forEach((b) => {
ctrl.removeButton(b);
});
ctrl.onRemoveOrig(map);
}
addButton(opt) {
let ctrl = this;
var elButton = document.createElement('button');
elButton.className = 'mapbox-gl-draw_ctrl-draw-btn';
if (opt.classes instanceof Array) {
opt.classes.forEach((c) => {
elButton.classList.add(c);
});
}
elButton.addEventListener(opt.on, opt.action);
ctrl.elContainer.appendChild(elButton);
opt.elButton = elButton;
}
removeButton(opt) {
opt.elButton.removeEventListener(opt.on, opt.action);
opt.elButton.remove();
}
}
now add the draw bar >>> map.addControl(drawBar) with your button

@zakjan
Copy link
Owner Author

zakjan commented Apr 7, 2021

Thanks, but this is a monkey patch for the entire application with access to MapboxDraw instance. It's not an official plugin API. I can only document this approach in the readme.

@Aliber009
Copy link

yes indeed , if you have any idea how I can change the mode using a simple button , im stuck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants