LeafletWidget.methods.addDrawToolbar=function(e,a,r){function t(e,a,r,t,o){return function(n){if(HTMLWidgets.shinyMode){var d=$.extend({id:a,category:o,".nonce":Math.random()},null!==r?{group:r}:null,n.target._latlngs?{latlngs:n.target._latlngs.flat()}:n.target._latlng,void 0!==n.target._mRadius?{radius:n.target._mRadius}:{});Shiny.onInputChange(e+"_"+t,d)}}}(function(){var o,n=this;if(n.drawToolbar&&(n.drawToolbar.remove(n),delete n.drawToolbar),e){if(!(o=n.layerManager.getLayer("geojson",e)))throw"GeoJSON layer with ID "+e+" not Found";n._editableGeoJSONLayerId=e}else a||(a="editableFeatureGroup"),o=n.layerManager.getLayerGroup(a,!0),n._editableFeatureGroupName=a;if(r&&r.draw&&r.draw.marker&&r.draw.marker.markerIcon&&r.draw.marker.markerIconFunction&&(r.draw.marker.icon=r.draw.marker.markerIconFunction(r.draw.marker.markerIcon)),!$.isEmptyObject(r.edit)){var d={};if(r.edit.remove||(d.remove=!1),r.edit.edit?$.isEmptyObject(r.edit.selectedPathOptions)||(d.edit={},d.edit.selectedPathOptions=r.edit.selectedPathOptions):d.edit=!1,$.isEmptyObject(r.edit.poly)||(d.poly=r.edit.poly),d.featureGroup=o,r.edit=d,r&&r.edittoolbar){var i=r.edittoolbar,l=L.drawLocal.edit.toolbar;L.drawLocal.edit.toolbar.buttons=Object.assign({},l.buttons,i.buttons),L.drawLocal.edit.toolbar.actions=Object.assign({},l.actions,i.actions)}if(r&&r.edithandlers){var s=r.edithandlers,w=L.drawLocal.edit.handlers;L.drawLocal.edit.handlers.edit=Object.assign({},w.buttons,s.edit),L.drawLocal.edit.handlers.remove=Object.assign({},w.actions,s.remove)}}if(r&&r.toolbar){var u=r.toolbar,p=L.drawLocal.draw.toolbar;L.drawLocal.draw.toolbar.buttons=Object.assign({},p.buttons,u.buttons),L.drawLocal.draw.toolbar.actions=Object.assign({},p.actions,u.actions),L.drawLocal.draw.toolbar.finish=Object.assign({},p.finish,u.finish),L.drawLocal.draw.toolbar.undo=Object.assign({},p.undo,u.undo)}if(r&&r.handlers){var c=r.handlers,y=L.drawLocal.draw.handlers;L.drawLocal.draw.handlers.circle=Object.assign({},y.circle,c.circle),L.drawLocal.draw.handlers.circlemarker=Object.assign({},y.circlemarker,c.circlemarker),L.drawLocal.draw.handlers.marker=Object.assign({},y.marker,c.marker),L.drawLocal.draw.handlers.polygon=Object.assign({},y.polygon,c.polygon),L.drawLocal.draw.handlers.polyline=Object.assign({},y.polyline,c.polyline),L.drawLocal.draw.handlers.rectangle=Object.assign({},y.rectangle,c.rectangle),L.drawLocal.draw.handlers.simpleshape=Object.assign({},y.simpleshape,c.simpleshape)}n.drawToolbar=new L.Control.Draw(r),n.drawToolbar.eventHandler={},n.drawToolbar.addTo(n),n.drawToolbar.eventHandler.onDrawStart=function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(n.id+"_draw_start",{feature_type:e.layerType,nonce:Math.random()})},n.on(L.Draw.Event.DRAWSTART,n.drawToolbar.eventHandler.onDrawStart),n.drawToolbar.eventHandler.onDrawStop=function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(n.id+"_draw_stop",{feature_type:e.layerType,nonce:Math.random()})},n.on(L.Draw.Event.DRAWSTOP,n.drawToolbar.eventHandler.onDrawStop),n.drawToolbar.eventHandler.onCreated=function(e){r.draw.singleFeature&&o.getLayers().length>0&&o.clearLayers();var d=e.layer;o.addLayer(d);var i=L.stamp(d);if(d.feature={type:"Feature",properties:{_leaflet_id:i,feature_type:e.layerType}},"function"==typeof d.getRadius&&(d.feature.properties.radius=d.getRadius()),HTMLWidgets.shinyMode){var l=e.layerType;["rectangle","polygon","circle"].includes(l)?l="shape":"circlemarker"===l&&(l="marker"),d.on("click",t(n.id,i,a,l+"_draw_click",l),n),d.on("mouseover",t(n.id,i,a,l+"_draw_mouseover",l),n),d.on("mouseout",t(n.id,i,a,l+"_draw_mouseout",l),n),Shiny.onInputChange(n.id+"_draw_new_feature",d.toGeoJSON(),{priority:"event"}),Shiny.onInputChange(n.id+"_draw_all_features",o.toGeoJSON(),{priority:"event"})}},n.on(L.Draw.Event.CREATED,n.drawToolbar.eventHandler.onCreated),n.drawToolbar.eventHandler.onEditstart=function(){HTMLWidgets.shinyMode&&Shiny.onInputChange(n.id+"_draw_editstart",!0,{priority:"event"})},n.on(L.Draw.Event.EDITSTART,n.drawToolbar.eventHandler.onEditstart),n.drawToolbar.eventHandler.onEditstop=function(){HTMLWidgets.shinyMode&&Shiny.onInputChange(n.id+"_draw_editstop",!0,{priority:"event"})},n.on(L.Draw.Event.EDITSTOP,n.drawToolbar.eventHandler.onEditstop),n.drawToolbar.eventHandler.onEdited=function(e){var a=e.layers;a.eachLayer((function(e){var a=L.stamp(e);e.feature||(e.feature={type:"Feature"}),e.feature.properties||(e.feature.properties={}),e.feature.properties._leaflet_id=a,e.feature.properties.layerId=e.options.layerId,"function"==typeof e.getRadius&&(e.feature.properties.radius=e.getRadius())})),HTMLWidgets.shinyMode&&(Shiny.onInputChange(n.id+"_draw_edited_features",a.toGeoJSON(),{priority:"event"}),Shiny.onInputChange(n.id+"_draw_all_features",o.toGeoJSON(),{priority:"event"}))},n.on(L.Draw.Event.EDITED,n.drawToolbar.eventHandler.onEdited),n.drawToolbar.eventHandler.onDeletestart=function(){HTMLWidgets.shinyMode&&Shiny.onInputChange(n.id+"_draw_deletestart",!0,{priority:"event"})},n.on(L.Draw.Event.DELETESTART,n.drawToolbar.eventHandler.onDeletestart),n.drawToolbar.eventHandler.onDeletestop=function(){HTMLWidgets.shinyMode&&Shiny.onInputChange(n.id+"_draw_deletestop",!0,{priority:"event"})},n.on(L.Draw.Event.DELETESTOP,n.drawToolbar.eventHandler.onDeletestop),n.drawToolbar.eventHandler.onDeleted=function(e){var a=e.layers;a.eachLayer((function(e){var a=L.stamp(e);e.feature||(e.feature={type:"Feature"}),e.feature.properties||(e.feature.properties={}),e.feature.properties._leaflet_id=a,e.feature.properties.layerId=e.options.layerId,"function"==typeof e.getRadius&&(e.feature.properties.radius=e.getRadius())})),HTMLWidgets.shinyMode&&(Shiny.onInputChange(n.id+"_draw_deleted_features",a.toGeoJSON(),{priority:"event"}),Shiny.onInputChange(n.id+"_draw_all_features",o.toGeoJSON(),{priority:"event"}))},n.on(L.Draw.Event.DELETED,n.drawToolbar.eventHandler.onDeleted)}).call(this)},LeafletWidget.methods.removeDrawToolbar=function(e){(function(){var a=this;a.drawToolbar&&(a.off(L.Draw.Event.DRAWSTART,a.drawToolbar.eventHandler.onDrawStart),a.off(L.Draw.Event.DRAWSTOP,a.drawToolbar.eventHandler.onDrawStop),a.off(L.Draw.Event.CREATED,a.drawToolbar.eventHandler.onCreated),a.off(L.Draw.Event.EDITSTART,a.drawToolbar.eventHandler.onEditstart),a.off(L.Draw.Event.EDITSTOP,a.drawToolbar.eventHandler.onEditstop),a.off(L.Draw.Event.EDITED,a.drawToolbar.eventHandler.onEdited),a.off(L.Draw.Event.DELETESTART,a.drawToolbar.eventHandler.onDeletestart),a.off(L.Draw.Event.DELETESTOP,a.drawToolbar.eventHandler.onDeletestop),a.off(L.Draw.Event.DELETED,a.drawToolbar.eventHandler.onDeleted),a.drawToolbar.remove(a),delete a.drawToolbar),a._editableFeatureGroupName&&e&&a.layerManager.getLayerGroup(a._editableFeatureGroupName,!1).clearLayers(),a._editableFeatureGroupName=null,a._editableGeoJSONLayerId&&e&&a.layerManager.removeLayer("geojson",a._editableGeoJSONLayerId),a._editableGeoJSONLayerId=null}).call(this)},LeafletWidget.methods.getDrawnItems=function(){var e,a=this;return a._editableGeoJSONLayerId?e=a.layerManager.getLayer("geojson",a._editableGeoJSONLayerId):a._editableFeatureGroupName&&(e=a.layerManager.getLayerGroup(a._editableFeatureGroupName,!1)),e?e.toGeoJSON():null};