import{a as e}from"./chunk-0359b4ed.js";class t{constructor(){this.defaultOptions={type:"point",multiple:!1,combine:!1,delete:!1,mode:"draw"}}async create(t,r){let l=e(r.mapId);if(!l)throw"Draw action map not found";let n=document.querySelector("gl-draw-toolbar");return n&&r.toolbarLabel&&(n.label=r.toolbarLabel),l.drawOptions=this.getControlOptions(r),l.drawing=!0,t&&l.draw.set(t),await new Promise(e=>{let t=()=>{l.drawing=!1,e(),n.removeEventListener("glDrawCancel",t),n.removeEventListener("glDrawConfirm",r)},r=()=>{let t=l.draw.getAll();l.drawing=!1,e(t),n.removeEventListener("glDrawConfirm",r),n.removeEventListener("glDrawConfirm",r)};n.addEventListener("glDrawCancel",t),n.addEventListener("glDrawConfirm",r)})}getControlOptions(e){let t=Object.assign({},this.defaultOptions,e||{}),r="simple_select";"direct"===t.mode&&(r="direct_select"),"draw"===t.mode&&("point"===t.type&&(r="draw_point"),"line"===t.type&&(r="draw_line_string"),"polygon"===t.type&&(r="draw_polygon"));let l={controls:{point:t.multiple&&"point"===t.type,line_string:t.multiple&&"line"===t.type,polygon:t.multiple&&"polygon"===t.type,trash:t.delete,combine_features:t.multiple&&t.combine,uncombine_features:t.multiple&&t.combine},defaultMode:r};return t.styles&&(l.styles=t.styles),l}static get is(){return"gl-draw-controller"}static get properties(){return{create:{method:!0}}}}export{t as GlDrawController};