admin管理员组文章数量:1415119
I am trying to build a custom controller for a map using Mapbox GL JS which includes a Draw polygon functionality. But when I wish to include the Draw polygon as per the Mapbox Documentation, it shows a menu on top right of the screen.
This is how it looks whenever I add the JS shown in /
This is the JS code which works Mapbox GL JS documentation has provided
var draw = new MapboxDraw({
// Instead of showing all the draw tools, show only the line string and delete tools
displayControlsDefault: false,
controls: {
line_string: true,
polygon: true,
point: true,
trash: true
}
});
// Add the draw tool to the map
map.addControl(draw);
I want to build a custom button which does the same function of allowing me to draw over a map.
I wish to use this button and it should open the draw cursor similar to when I click on draw function in their default menu
How can I going about doing this?
I am trying to build a custom controller for a map using Mapbox GL JS which includes a Draw polygon functionality. But when I wish to include the Draw polygon as per the Mapbox Documentation, it shows a menu on top right of the screen.
This is how it looks whenever I add the JS shown in https://docs.mapbox./mapbox-gl-js/example/mapbox-gl-draw/
This is the JS code which works Mapbox GL JS documentation has provided
var draw = new MapboxDraw({
// Instead of showing all the draw tools, show only the line string and delete tools
displayControlsDefault: false,
controls: {
line_string: true,
polygon: true,
point: true,
trash: true
}
});
// Add the draw tool to the map
map.addControl(draw);
I want to build a custom button which does the same function of allowing me to draw over a map.
I wish to use this button and it should open the draw cursor similar to when I click on draw function in their default menu
How can I going about doing this?
Share Improve this question asked Feb 17, 2020 at 16:59 escigsescigs 311 silver badge2 bronze badges1 Answer
Reset to default 7You can apply the drawing mode using draw.changeMode('draw_polygon'). This would trigger the same event as the original button would do. Therefore you can get rid of that.
document.getElementById('button').onclick = function () {
draw.changeMode('draw_polygon');
}
版权声明:本文标题:javascript - How can I use custom HTML buttons to call a Mapbox GL JS Draw Polygon function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745229963a2648778.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论