From 4a3fd3ffc3bc703975297f063740b11dd55e7e5e Mon Sep 17 00:00:00 2001 From: Sebastian Gatscha Date: Thu, 30 Jan 2020 18:14:47 +0100 Subject: [PATCH] add new draw options --- NAMESPACE | 2 + NEWS.md | 5 + R/draw.R | 13 +- R/drawOptions.R | 140 ++++++++++++++++++ .../htmlwidgets/bindings/lfx-draw-bindings.js | 49 +++++- .../build/lfx-draw/lfx-draw-bindings.js | 3 +- man/draw.Rd | 6 +- man/handlersOptions.Rd | 51 +++++++ man/toolbarOptions.Rd | 44 ++++++ 9 files changed, 305 insertions(+), 8 deletions(-) create mode 100644 man/handlersOptions.Rd create mode 100644 man/toolbarOptions.Rd diff --git a/NAMESPACE b/NAMESPACE index 9a3473fb..5ddd9d17 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -57,6 +57,7 @@ export(editToolbarOptions) export(enableMeasurePath) export(enableTileCaching) export(gpsOptions) +export(handlersOptions) export(leafletExtrasDependencies) export(legendOptions) export(makePulseIcon) @@ -80,6 +81,7 @@ export(searchOptions) export(selectedPathOptions) export(setMapWidgetStyle) export(suspendScroll) +export(toolbarOptions) export(weatherIconList) export(weatherIcons) import(leaflet) diff --git a/NEWS.md b/NEWS.md index cf47e265..1b98f2fe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# leaflet.extras 1.1.0 + +## New Features +- The `addDrawToolbar` offers two new options: `handlersOptions` and `toolbarOptions`, with which you can customize the drawing toolbar and the tooltips. + # leaflet.extras 1.0.0 ## leaflet.js diff --git a/R/draw.R b/R/draw.R index 088852f2..753ae07c 100644 --- a/R/draw.R +++ b/R/draw.R @@ -24,6 +24,8 @@ drawDependencies <- function() { #' @param circleMarkerOptions See \code{\link{drawCircleMarkerOptions}}(). Set to FALSE to disable circle marker drawing. #' @param editOptions By default editing is disable. To enable editing pass \code{\link{editToolbarOptions}}(). #' @param singleFeature When set to TRUE, only one feature can be drawn at a time, the previous ones being removed. +#' @param toolbar See \code{\link{toolbarOptions}}. Set to \code{NULL} to take Leaflets default values. +#' @param handlers See \code{\link{handlersOptions}}. Set to \code{NULL} to take Leaflets default values. #' @export #' @rdname draw #' @examples @@ -54,13 +56,18 @@ addDrawToolbar <- function( markerOptions = drawMarkerOptions(), circleMarkerOptions = drawCircleMarkerOptions(), editOptions = FALSE, - singleFeature = FALSE + singleFeature = FALSE, + toolbar = NULL, + handlers = NULL ) { if (!is.null(targetGroup) && !is.null(targetLayerId)) { stop("To edit existing features either specify a targetGroup or a targetLayerId, but not both") } + if (!inherits(toolbar, "list")) toolbar <- NULL + if (!inherits(handlers, "list")) handlers <- NULL + map$dependencies <- c(map$dependencies, drawDependencies()) markerIconFunction <- NULL @@ -89,7 +96,9 @@ addDrawToolbar <- function( marker = markerOptions, circlemarker = circleMarkerOptions, singleFeature = singleFeature)), - edit = editOptions ) + edit = editOptions, + toolbar = toolbar, + handlers = handlers) leaflet::invokeMethod(map, leaflet::getMapData(map), "addDrawToolbar", targetLayerId, targetGroup, options) diff --git a/R/drawOptions.R b/R/drawOptions.R index 87c201cc..8fdeeb56 100644 --- a/R/drawOptions.R +++ b/R/drawOptions.R @@ -236,3 +236,143 @@ editToolbarOptions <- function( allowIntersection = allowIntersection )) } + + +#' Options for editing handlers +#' @description Customize tooltips for \code{\link{addDrawToolbar}} +#' @param polyline List of options for polyline tooltips. +#' @param polygon List of options for polygon tooltips. +#' @param rectangle List of options for rectangle tooltips. +#' @param circle List of options for circle tooltips. +#' @param marker List of options for marker tooltips. +#' @param circlemarker List of options for circlemarker tooltips. +#' @export +#' @examples \dontrun{ +#' library(leaflet) +#' library(leaflet.extras) +#' leaflet() %>% +#' addTiles() %>% +#' addDrawToolbar( +#' handlers = handlersOptions( +#' polyline = list(tooltipStart = "Click It", +#' tooltipCont = "Keep going", +#' tooltipEnd = "Make it stop"), +#' ), +#' polylineOptions = T, rectangleOptions = F, circleOptions = F, +#' polygonOptions = F, markerOptions = F, circleMarkerOptions = F +#' ) +#' } +handlersOptions <- function( + polyline = list( + error = "Error: shape edges cannot cross!", + tooltipStart = "Click to start drawing line.", + tooltipCont = "Click to start drawing line.", + tooltipEnd = "Click to start drawing line."), + polygon = list( + tooltipStart = "Click to start drawing shape.", + tooltipCont = "Click to start drawing shape.", + tooltipEnd = "Click to start drawing shape."), + rectangle = list( + tooltipStart = "Click and drag to draw rectangle."), + circle = list( + tooltipStart = "Click map to place circle marker.", + radius = "Radius"), + marker = list( + tooltipStart = "Click map to place marker."), + circlemarker = list( + tooltipStart = "Click and drag to draw circle.") +) { + leaflet::filterNULL(list( + polyline = list( + error = polyline$error, + tooltip = list( + start = polyline$tooltipStart, + cont = polyline$tooltipCont, + end = polyline$tooltipEnd + )), + polygon = list( + tooltip = list( + start = polygon$tooltipStart, + cont = polygon$tooltipCont, + end = polygon$tooltipEnd + )), + rectangle = list(tooltip = list(start = rectangle$tooltipStart)), + circle = list(radius = circle$radius, + tooltip = list(start = circle$tooltipStart)), + marker = list(tooltip = list(start = marker$tooltipStart)), + circlemarker = list(tooltip = list(start = circlemarker$tooltipStart)) + )) +} + + +#' Options for editing the toolbar +#' @description Customize the toolbar for \code{\link{addDrawToolbar}} +#' @param actions List of options for actions toolbar button. +#' @param finish List of options for finish toolbar button. +#' @param undo List of options for undo toolbar button. +#' @param buttons List of options for buttons toolbar button. +#' @export +#' @examples \dontrun{ +#' library(leaflet) +#' library(leaflet.extras) +#' leaflet() %>% +#' addTiles() %>% +#' addDrawToolbar( +#' toolbar = toolbarOptions( +#' actions = list(text = "STOP"), +#' finish = list(text = "DONE"), +#' buttons = list(polyline = "Draw a sexy polyline", +#' rectangle = "Draw a gigantic rectangle", +#' circlemarker = "Make a nice circle"), +#' ), +#' polylineOptions = T, rectangleOptions = T,circleOptions = T, +#' polygonOptions = F, markerOptions = F, circleMarkerOptions = F +#' ) +#' } +toolbarOptions <- function( + actions = list( + title = "Cancel drawing", + text = "Cancel" + ), + finish = list( + title = "Finish drawing", + text = "Finish" + ), + undo = list( + title = "Delete last point drawn", + text = "Delete last point" + ), + buttons = list( + polyline = "Draw a polyline", + polygon = "Draw a polygon", + rectangle = "Draw a rectangle", + circle = "Draw a circle", + marker = "Draw a marker", + circlemarker = "Draw a circlemarker" + ) +) { + leaflet::filterNULL(list( + actions = list( + title = actions$title, + text = actions$text + ), + finish = list( + title = finish$title, + text = finish$text + ), + undo = list( + title = undo$title, + text = undo$text + ), + buttons = list( + polyline = buttons$polyline, + polygon = buttons$polygon, + rectangle = buttons$rectangle, + circle = buttons$circle, + marker = buttons$marker, + circlemarker = buttons$circlemarker + ) + )) +} + + diff --git a/inst/htmlwidgets/bindings/lfx-draw-bindings.js b/inst/htmlwidgets/bindings/lfx-draw-bindings.js index 450835dc..ed5506cd 100644 --- a/inst/htmlwidgets/bindings/lfx-draw-bindings.js +++ b/inst/htmlwidgets/bindings/lfx-draw-bindings.js @@ -6,8 +6,8 @@ LeafletWidget.methods.addDrawToolbar = function(targetLayerId, targetGroup, opti var map = this; if(map.drawToolbar) { - map.drawToolbar.removeFrom(map); - delete map.drawToobar; + map.drawToolbar.remove(map); + delete map.drawToolbar; } // FeatureGroup that will hold our drawn shapes/markers @@ -68,6 +68,49 @@ LeafletWidget.methods.addDrawToolbar = function(targetLayerId, targetGroup, opti options.edit = editOptions; } + // Set Toolbar / Handlers options if provided. Changes the default values. + if (options && options.toolbar) { + var rtool = options.toolbar; + var tooldef = L.drawLocal.draw.toolbar; + L.drawLocal.draw.toolbar.buttons.polygon = rtool.buttons.polygon ? rtool.buttons.polygon : tooldef.buttons.polygon; + L.drawLocal.draw.toolbar.buttons.polyline = rtool.buttons.polyline ? rtool.buttons.polyline : tooldef.buttons.polyline; + L.drawLocal.draw.toolbar.buttons.rectangle = rtool.buttons.rectangle ? rtool.buttons.rectangle : tooldef.buttons.rectangle; + L.drawLocal.draw.toolbar.buttons.circle = rtool.buttons.circle ? rtool.buttons.circle : tooldef.buttons.circle; + L.drawLocal.draw.toolbar.buttons.marker = rtool.buttons.marker ? rtool.buttons.marker : tooldef.buttons.marker; + L.drawLocal.draw.toolbar.buttons.circlemarker = rtool.buttons.circlemarker ? rtool.buttons.circlemarker : tooldef.buttons.circlemarker; + + L.drawLocal.draw.toolbar.actions.title = rtool.actions.title ? rtool.actions.rectangle : tooldef.actions.title; + L.drawLocal.draw.toolbar.actions.text = rtool.actions.text ? rtool.actions.text : tooldef.actions.text; + + L.drawLocal.draw.toolbar.finish.title = rtool.finish.title ? rtool.finish.rectangle : tooldef.finish.title; + L.drawLocal.draw.toolbar.finish.text = rtool.finish.text ? rtool.finish.text : tooldef.finish.text; + + L.drawLocal.draw.toolbar.undo.title = rtool.undo.title ? rtool.undo.rectangle : tooldef.undo.title; + L.drawLocal.draw.toolbar.undo.text = rtool.undo.text ? rtool.undo.text : tooldef.undo.text; + } + if (options && options.handlers) { + var rhand = options.handlers; + var handldef = L.drawLocal.draw.handlers; + L.drawLocal.draw.handlers.circle.radius = rhand.circle.radius ? rhand.circle.radius : handldef.circle.radius; + L.drawLocal.draw.handlers.circle.tooltip.start = rhand.circle.tooltip.start ? rhand.circle.tooltip.start : handldef.circle.tooltip.start; + + L.drawLocal.draw.handlers.circlemarker.tooltip.start = rhand.circlemarker.tooltip.start ? rhand.circlemarker.tooltip.start : handldef.circlemarker.tooltip.start; + + L.drawLocal.draw.handlers.marker.tooltip.start = rhand.marker.tooltip.start ? rhand.marker.tooltip.start : handldef.marker.tooltip.start; + + L.drawLocal.draw.handlers.polygon.tooltip.start = rhand.polygon.tooltip.start ? rhand.polygon.tooltip.start : handldef.polygon.tooltip.start; + L.drawLocal.draw.handlers.polygon.tooltip.cont = rhand.polygon.tooltip.cont ? rhand.polygon.tooltip.cont : handldef.polygon.tooltip.cont; + L.drawLocal.draw.handlers.polygon.tooltip.end = rhand.polygon.tooltip.end ? rhand.polygon.tooltip.end : handldef.polygon.tooltip.end; + + L.drawLocal.draw.handlers.polyline.error = rhand.polyline.error ? rhand.polyline.error : handldef.polyline.error; + L.drawLocal.draw.handlers.polyline.tooltip.start = rhand.polyline.tooltip.start ? rhand.polyline.tooltip.start : handldef.polyline.tooltip.start; + L.drawLocal.draw.handlers.polyline.tooltip.cont = rhand.polyline.tooltip.cont ? rhand.polyline.tooltip.cont : handldef.polyline.tooltip.cont; + L.drawLocal.draw.handlers.polyline.tooltip.end = rhand.polyline.tooltip.end ? rhand.polyline.tooltip.end : handldef.polyline.tooltip.end; + + L.drawLocal.draw.handlers.rectangle.tooltip.start = rhand.rectangle.tooltip.start ? rhand.rectangle.tooltip.start : handldef.rectangle.tooltip.start; + } + + // Create new Drawing Control map.drawToolbar = new L.Control.Draw(options); map.drawToolbar.addTo(map); @@ -194,7 +237,7 @@ LeafletWidget.methods.removeDrawToolbar = function(clearFeatures) { var map = this; if(map.drawToolbar) { - map.drawToolbar.removeFrom(map); + map.drawToolbar.remove(map); delete map.drawToolbar; } if(map._editableFeatureGroupName && clearFeatures) { diff --git a/inst/htmlwidgets/build/lfx-draw/lfx-draw-bindings.js b/inst/htmlwidgets/build/lfx-draw/lfx-draw-bindings.js index 50fcf216..adfbf01c 100644 --- a/inst/htmlwidgets/build/lfx-draw/lfx-draw-bindings.js +++ b/inst/htmlwidgets/build/lfx-draw/lfx-draw-bindings.js @@ -1,2 +1 @@ -!function(e){var t={};function r(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,a){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:a})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t){LeafletWidget.methods.addDrawToolbar=function(e,t,r){(function(){var a,o=this;if(o.drawToolbar&&(o.drawToolbar.removeFrom(o),delete o.drawToobar),e){if(!(a=o.layerManager.getLayer("geojson",e)))throw"GeoJSON layer with ID "+e+" not Found";o._editableGeoJSONLayerId=e}else t||(t="editableFeatureGroup"),a=o.layerManager.getLayerGroup(t,!0),o._editableFeatureGroupName=t;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 n={};r.edit.remove||(n.remove=!1),r.edit.edit?$.isEmptyObject(r.edit.selectedPathOptions)||(n.edit={},n.edit.selectedPathOptions=r.edit.selectedPathOptions):n.edit=!1,$.isEmptyObject(r.edit.poly)||(n.poly=r.edit.poly),n.featureGroup=a,r.edit=n}o.drawToolbar=new L.Control.Draw(r),o.drawToolbar.addTo(o),o.on(L.Draw.Event.DRAWSTART,function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(o.id+"_draw_start",{feature_type:e.layerType})}),o.on(L.Draw.Event.DRAWSTOP,function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(o.id+"_draw_stop",{feature_type:e.layerType})}),o.on(L.Draw.Event.CREATED,function(e){r.draw.singleFeature&&a.getLayers().length>0&&a.clearLayers();var t=e.layer;a.addLayer(t);var n=L.stamp(t);t.feature={type:"Feature",properties:{_leaflet_id:n,feature_type:e.layerType}},"function"==typeof t.getRadius&&(t.feature.properties.radius=t.getRadius()),HTMLWidgets.shinyMode&&(Shiny.onInputChange(o.id+"_draw_new_feature",t.toGeoJSON()),Shiny.onInputChange(o.id+"_draw_all_features",a.toGeoJSON()))}),o.on(L.Draw.Event.EDITSTART,function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(o.id+"_draw_editstart",!0)}),o.on(L.Draw.Event.EDITSTOP,function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(o.id+"_draw_editstop",!0)}),o.on(L.Draw.Event.EDITED,function(e){var t=e.layers;t.eachLayer(function(e){var t=L.stamp(e);e.feature||(e.feature={type:"Feature"}),e.feature.properties||(e.feature.properties={}),e.feature.properties._leaflet_id=t,e.feature.properties.layerId=e.options.layerId,"function"==typeof e.getRadius&&(e.feature.properties.radius=e.getRadius())}),HTMLWidgets.shinyMode&&(Shiny.onInputChange(o.id+"_draw_edited_features",t.toGeoJSON()),Shiny.onInputChange(o.id+"_draw_all_features",a.toGeoJSON()))}),o.on(L.Draw.Event.DELETESTART,function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(o.id+"_draw_deletestart",!0)}),o.on(L.Draw.Event.DELETESTOP,function(e){HTMLWidgets.shinyMode&&Shiny.onInputChange(o.id+"_draw_deletestop",!0)}),o.on(L.Draw.Event.DELETED,function(e){var t=e.layers;t.eachLayer(function(e){var t=L.stamp(e);e.feature||(e.feature={type:"Feature"}),e.feature.properties||(e.feature.properties={}),e.feature.properties._leaflet_id=t,e.feature.properties.layerId=e.options.layerId,"function"==typeof e.getRadius&&(e.feature.properties.radius=e.getRadius())}),HTMLWidgets.shinyMode&&(Shiny.onInputChange(o.id+"_draw_deleted_features",t.toGeoJSON()),Shiny.onInputChange(o.id+"_draw_all_features",a.toGeoJSON()))})}).call(this)},LeafletWidget.methods.removeDrawToolbar=function(e){(function(){var t=this;(t.drawToolbar&&(t.drawToolbar.removeFrom(t),delete t.drawToolbar),t._editableFeatureGroupName&&e)&&t.layerManager.getLayerGroup(t._editableFeatureGroupName,!1).clearLayers();t._editableFeatureGroupName=null,t._editableGeoJSONLayerId&&e&&t.layerManager.removeLayer("geojson",t._editableGeoJSONLayerId),t._editableGeoJSONLayerId=null}).call(this)},LeafletWidget.methods.getDrawnItems=function(){var e;return this._editableGeoJSONLayerId?e=this.layerManager.getLayer("geojson",this._editableGeoJSONLayerId):this._editableFeatureGroupName&&(e=this.layerManager.getLayerGroup(this._editableFeatureGroupName,!1)),e?e.toGeoJSON():null}}]); -//# sourceMappingURL=lfx-draw-bindings.js.map \ No newline at end of file +!function(t){var e={};function r(o){if(e[o])return e[o].exports;var a=e[o]={i:o,l:!1,exports:{}};return t[o].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:o})},r.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e){LeafletWidget.methods.addDrawToolbar=function(t,e,r){(function(){var o,a=this;if(a.drawToolbar&&(a.drawToolbar.removeFrom(a),delete a.drawToobar),t){if(!(o=a.layerManager.getLayer("geojson",t)))throw"GeoJSON layer with ID "+t+" not Found";a._editableGeoJSONLayerId=t}else e||(e="editableFeatureGroup"),o=a.layerManager.getLayerGroup(e,!0),a._editableFeatureGroupName=e;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 n={};r.edit.remove||(n.remove=!1),r.edit.edit?$.isEmptyObject(r.edit.selectedPathOptions)||(n.edit={},n.edit.selectedPathOptions=r.edit.selectedPathOptions):n.edit=!1,$.isEmptyObject(r.edit.poly)||(n.poly=r.edit.poly),n.featureGroup=o,r.edit=n}if(r&&r.toolbar){var l=r.toolbar,i=L.drawLocal.draw.toolbar;L.drawLocal.draw.toolbar.buttons.polygon=l.buttons.polygon?l.buttons.polygon:i.buttons.polygon,L.drawLocal.draw.toolbar.buttons.polyline=l.buttons.polyline?l.buttons.polyline:i.buttons.polyline,L.drawLocal.draw.toolbar.buttons.rectangle=l.buttons.rectangle?l.buttons.rectangle:i.buttons.rectangle,L.drawLocal.draw.toolbar.buttons.circle=l.buttons.circle?l.buttons.circle:i.buttons.circle,L.drawLocal.draw.toolbar.buttons.marker=l.buttons.marker?l.buttons.marker:i.buttons.marker,L.drawLocal.draw.toolbar.buttons.circlemarker=l.buttons.circlemarker?l.buttons.circlemarker:i.buttons.circlemarker,L.drawLocal.draw.toolbar.actions.title=l.actions.title?l.actions.rectangle:i.actions.title,L.drawLocal.draw.toolbar.actions.text=l.actions.text?l.actions.text:i.actions.text,L.drawLocal.draw.toolbar.finish.title=l.finish.title?l.finish.rectangle:i.finish.title,L.drawLocal.draw.toolbar.finish.text=l.finish.text?l.finish.text:i.finish.text,L.drawLocal.draw.toolbar.undo.title=l.undo.title?l.undo.rectangle:i.undo.title,L.drawLocal.draw.toolbar.undo.text=l.undo.text?l.undo.text:i.undo.text}if(r&&r.handlers){var d=r.handlers,s=L.drawLocal.draw.handlers;L.drawLocal.draw.handlers.circle.radius=d.circle.radius?d.circle.radius:s.circle.radius,L.drawLocal.draw.handlers.circle.tooltip.start=d.circle.tooltip.start?d.circle.tooltip.start:s.circle.tooltip.start,L.drawLocal.draw.handlers.circlemarker.tooltip.start=d.circlemarker.tooltip.start?d.circlemarker.tooltip.start:s.circlemarker.tooltip.start,L.drawLocal.draw.handlers.marker.tooltip.start=d.marker.tooltip.start?d.marker.tooltip.start:s.marker.tooltip.start,L.drawLocal.draw.handlers.polygon.tooltip.start=d.polygon.tooltip.start?d.polygon.tooltip.start:s.polygon.tooltip.start,L.drawLocal.draw.handlers.polygon.tooltip.cont=d.polygon.tooltip.cont?d.polygon.tooltip.cont:s.polygon.tooltip.cont,L.drawLocal.draw.handlers.polygon.tooltip.end=d.polygon.tooltip.end?d.polygon.tooltip.end:s.polygon.tooltip.end,L.drawLocal.draw.handlers.polyline.error=d.polyline.error?d.polyline.error:s.polyline.error,L.drawLocal.draw.handlers.polyline.tooltip.start=d.polyline.tooltip.start?d.polyline.tooltip.start:s.polyline.tooltip.start,L.drawLocal.draw.handlers.polyline.tooltip.cont=d.polyline.tooltip.cont?d.polyline.tooltip.cont:s.polyline.tooltip.cont,L.drawLocal.draw.handlers.polyline.tooltip.end=d.polyline.tooltip.end?d.polyline.tooltip.end:s.polyline.tooltip.end,L.drawLocal.draw.handlers.rectangle.tooltip.start=d.rectangle.tooltip.start?d.rectangle.tooltip.start:s.rectangle.tooltip.start}a.drawToolbar=new L.Control.Draw(r),a.drawToolbar.addTo(a),a.on(L.Draw.Event.DRAWSTART,function(t){HTMLWidgets.shinyMode&&Shiny.onInputChange(a.id+"_draw_start",{feature_type:t.layerType})}),a.on(L.Draw.Event.DRAWSTOP,function(t){HTMLWidgets.shinyMode&&Shiny.onInputChange(a.id+"_draw_stop",{feature_type:t.layerType})}),a.on(L.Draw.Event.CREATED,function(t){r.draw.singleFeature&&o.getLayers().length>0&&o.clearLayers();var e=t.layer;o.addLayer(e);var n=L.stamp(e);e.feature={type:"Feature",properties:{_leaflet_id:n,feature_type:t.layerType}},"function"==typeof e.getRadius&&(e.feature.properties.radius=e.getRadius()),HTMLWidgets.shinyMode&&(Shiny.onInputChange(a.id+"_draw_new_feature",e.toGeoJSON()),Shiny.onInputChange(a.id+"_draw_all_features",o.toGeoJSON()))}),a.on(L.Draw.Event.EDITSTART,function(t){HTMLWidgets.shinyMode&&Shiny.onInputChange(a.id+"_draw_editstart",!0)}),a.on(L.Draw.Event.EDITSTOP,function(t){HTMLWidgets.shinyMode&&Shiny.onInputChange(a.id+"_draw_editstop",!0)}),a.on(L.Draw.Event.EDITED,function(t){var e=t.layers;e.eachLayer(function(t){var e=L.stamp(t);t.feature||(t.feature={type:"Feature"}),t.feature.properties||(t.feature.properties={}),t.feature.properties._leaflet_id=e,t.feature.properties.layerId=t.options.layerId,"function"==typeof t.getRadius&&(t.feature.properties.radius=t.getRadius())}),HTMLWidgets.shinyMode&&(Shiny.onInputChange(a.id+"_draw_edited_features",e.toGeoJSON()),Shiny.onInputChange(a.id+"_draw_all_features",o.toGeoJSON()))}),a.on(L.Draw.Event.DELETESTART,function(t){HTMLWidgets.shinyMode&&Shiny.onInputChange(a.id+"_draw_deletestart",!0)}),a.on(L.Draw.Event.DELETESTOP,function(t){HTMLWidgets.shinyMode&&Shiny.onInputChange(a.id+"_draw_deletestop",!0)}),a.on(L.Draw.Event.DELETED,function(t){var e=t.layers;e.eachLayer(function(t){var e=L.stamp(t);t.feature||(t.feature={type:"Feature"}),t.feature.properties||(t.feature.properties={}),t.feature.properties._leaflet_id=e,t.feature.properties.layerId=t.options.layerId,"function"==typeof t.getRadius&&(t.feature.properties.radius=t.getRadius())}),HTMLWidgets.shinyMode&&(Shiny.onInputChange(a.id+"_draw_deleted_features",e.toGeoJSON()),Shiny.onInputChange(a.id+"_draw_all_features",o.toGeoJSON()))})}).call(this)},LeafletWidget.methods.removeDrawToolbar=function(t){(function(){var e=this;e.drawToolbar&&(e.drawToolbar.remove(e),delete e.drawToolbar),e._editableFeatureGroupName&&t&&e.layerManager.getLayerGroup(e._editableFeatureGroupName,!1).clearLayers(),e._editableFeatureGroupName=null,e._editableGeoJSONLayerId&&t&&e.layerManager.removeLayer("geojson",e._editableGeoJSONLayerId),e._editableGeoJSONLayerId=null}).call(this)},LeafletWidget.methods.getDrawnItems=function(){var t;return this._editableGeoJSONLayerId?t=this.layerManager.getLayer("geojson",this._editableGeoJSONLayerId):this._editableFeatureGroupName&&(t=this.layerManager.getLayerGroup(this._editableFeatureGroupName,!1)),t?t.toGeoJSON():null}}]); \ No newline at end of file diff --git a/man/draw.Rd b/man/draw.Rd index 6daf32f2..96b02374 100644 --- a/man/draw.Rd +++ b/man/draw.Rd @@ -13,7 +13,7 @@ addDrawToolbar(map, targetLayerId = NULL, targetGroup = NULL, rectangleOptions = drawRectangleOptions(), markerOptions = drawMarkerOptions(), circleMarkerOptions = drawCircleMarkerOptions(), editOptions = FALSE, - singleFeature = FALSE) + singleFeature = FALSE, toolbar = NULL, handlers = NULL) removeDrawToolbar(map, clearFeatures = FALSE) } @@ -45,6 +45,10 @@ You can either set layerId or group or none but not both.} \item{singleFeature}{When set to TRUE, only one feature can be drawn at a time, the previous ones being removed.} +\item{toolbar}{See \code{\link{toolbarOptions}}. Set to \code{NULL} to take Leaflets default values.} + +\item{handlers}{See \code{\link{handlersOptions}}. Set to \code{NULL} to take Leaflets default values.} + \item{clearFeatures}{whether to clear the map of drawn features.} } \description{ diff --git a/man/handlersOptions.Rd b/man/handlersOptions.Rd new file mode 100644 index 00000000..949c43dd --- /dev/null +++ b/man/handlersOptions.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/drawOptions.R +\name{handlersOptions} +\alias{handlersOptions} +\title{Options for editing handlers} +\usage{ +handlersOptions(polyline = list(error = + "Error: shape edges cannot cross!", tooltipStart = + "Click to start drawing line.", tooltipCont = "Click to start drawing line.", + tooltipEnd = "Click to start drawing line."), polygon = list(tooltipStart = + "Click to start drawing shape.", tooltipCont = + "Click to start drawing shape.", tooltipEnd = + "Click to start drawing shape."), rectangle = list(tooltipStart = + "Click and drag to draw rectangle."), circle = list(tooltipStart = + "Click map to place circle marker.", radius = "Radius"), + marker = list(tooltipStart = "Click map to place marker."), + circlemarker = list(tooltipStart = "Click and drag to draw circle.")) +} +\arguments{ +\item{polyline}{List of options for polyline tooltips.} + +\item{polygon}{List of options for polygon tooltips.} + +\item{rectangle}{List of options for rectangle tooltips.} + +\item{circle}{List of options for circle tooltips.} + +\item{marker}{List of options for marker tooltips.} + +\item{circlemarker}{List of options for circlemarker tooltips.} +} +\description{ +Customize tooltips for \code{\link{addDrawToolbar}} +} +\examples{ +\dontrun{ +library(leaflet) +library(leaflet.extras) +leaflet() \%>\% +addTiles() \%>\% + addDrawToolbar( + handlers = handlersOptions( + polyline = list(tooltipStart = "Click It", + tooltipCont = "Keep going", + tooltipEnd = "Make it stop"), + ), + polylineOptions = T, rectangleOptions = F, circleOptions = F, + polygonOptions = F, markerOptions = F, circleMarkerOptions = F + ) +} +} diff --git a/man/toolbarOptions.Rd b/man/toolbarOptions.Rd new file mode 100644 index 00000000..82d50e02 --- /dev/null +++ b/man/toolbarOptions.Rd @@ -0,0 +1,44 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/drawOptions.R +\name{toolbarOptions} +\alias{toolbarOptions} +\title{Options for editing the toolbar} +\usage{ +toolbarOptions(actions = list(title = "Cancel drawing", text = "Cancel"), + finish = list(title = "Finish drawing", text = "Finish"), + undo = list(title = "Delete last point drawn", text = "Delete last point"), + buttons = list(polyline = "Draw a polyline", polygon = "Draw a polygon", + rectangle = "Draw a rectangle", circle = "Draw a circle", marker = + "Draw a marker", circlemarker = "Draw a circlemarker")) +} +\arguments{ +\item{actions}{List of options for actions toolbar button.} + +\item{finish}{List of options for finish toolbar button.} + +\item{undo}{List of options for undo toolbar button.} + +\item{buttons}{List of options for buttons toolbar button.} +} +\description{ +Customize the toolbar for \code{\link{addDrawToolbar}} +} +\examples{ +\dontrun{ +library(leaflet) +library(leaflet.extras) +leaflet() \%>\% + addTiles() \%>\% + addDrawToolbar( + toolbar = toolbarOptions( + actions = list(text = "STOP"), + finish = list(text = "DONE"), + buttons = list(polyline = "Draw a sexy polyline", + rectangle = "Draw a gigantic rectangle", + circlemarker = "Make a nice circle"), + ), + polylineOptions = T, rectangleOptions = T,circleOptions = T, + polygonOptions = F, markerOptions = F, circleMarkerOptions = F + ) +} +}