├── .bowerrc ├── javascript ├── src │ ├── global │ │ ├── leaflet.js │ │ ├── shiny.js │ │ ├── jquery.js │ │ ├── proj4leaflet.js │ │ └── htmlwidgets.js │ ├── cluster-layer-store.js │ ├── util.js │ ├── control-store.js │ ├── crs_utils.js │ ├── dataframe.js │ └── mipmapper.js └── tests │ └── test-dataframe.js ├── tests ├── test-all.R ├── testthat.R └── testit │ ├── test-utils.R │ ├── test-icon.R │ ├── test-measure.R │ ├── test-legend.R │ └── test-colors.R ├── data ├── providers.rda └── providers.details.rda ├── inst ├── extdata │ ├── gadmCHE.rds │ ├── breweries91.rds │ └── atlStorms2005.rds ├── legacy │ ├── examples │ │ ├── choropleth │ │ │ ├── DESCRIPTION │ │ │ ├── Rplots.pdf │ │ │ ├── shinyapps │ │ │ │ └── jcheng │ │ │ │ │ └── choropleth3.dcf │ │ │ ├── ui.R │ │ │ ├── global.R │ │ │ └── server.R │ │ ├── geojson │ │ │ └── ui.R │ │ └── population │ │ │ ├── www │ │ │ └── styles.css │ │ │ └── ui.R │ └── www │ │ └── images │ │ ├── layers.png │ │ ├── layers-2x.png │ │ ├── marker-icon.png │ │ ├── marker-icon-2x.png │ │ └── marker-shadow.png ├── htmlwidgets │ ├── lib │ │ ├── leaflet │ │ │ ├── images │ │ │ │ ├── 1px.png │ │ │ │ ├── layers.png │ │ │ │ ├── layers-2x.png │ │ │ │ ├── marker-icon.png │ │ │ │ ├── marker-icon-2x.png │ │ │ │ └── marker-shadow.png │ │ │ └── .bower.json │ │ ├── Leaflet.label │ │ │ ├── images │ │ │ │ └── death.png │ │ │ └── leaflet.label.css │ │ ├── leaflet-measure │ │ │ ├── images │ │ │ │ ├── cancel.png │ │ │ │ ├── check.png │ │ │ │ ├── focus.png │ │ │ │ ├── rulers.png │ │ │ │ ├── start.png │ │ │ │ ├── trash.png │ │ │ │ ├── check_@2X.png │ │ │ │ ├── focus_@2X.png │ │ │ │ ├── start_@2X.png │ │ │ │ ├── trash_@2X.png │ │ │ │ ├── cancel_@2X.png │ │ │ │ └── rulers_@2X.png │ │ │ └── leaflet-measure.css │ │ ├── leaflet-providers │ │ │ ├── CONTRIBUTING.md │ │ │ ├── bower.json │ │ │ ├── .bower.json │ │ │ ├── license.md │ │ │ ├── package.json │ │ │ ├── css │ │ │ │ └── gh-fork-ribbon.ie.css │ │ │ └── README.md │ │ ├── leafletfix │ │ │ └── leafletfix.css │ │ └── leaflet-omnivore │ │ │ └── package.json │ ├── plugins │ │ ├── Leaflet-MiniMap │ │ │ ├── images │ │ │ │ ├── toggle.png │ │ │ │ └── toggle.svg │ │ │ ├── Control.MiniMap.min.css │ │ │ ├── Minimap-binding.js │ │ │ └── Control.MiniMap.css │ │ ├── Leaflet.awesome-markers │ │ │ ├── fonts │ │ │ │ ├── ionicons.eot │ │ │ │ ├── ionicons.ttf │ │ │ │ ├── ionicons.woff │ │ │ │ ├── FontAwesome.otf │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ │ └── glyphicons-halflings-regular.woff │ │ │ ├── images │ │ │ │ ├── markers-soft.png │ │ │ │ ├── markers-matte.png │ │ │ │ ├── markers-plain.png │ │ │ │ ├── markers-shadow.png │ │ │ │ ├── markers-matte@2x.png │ │ │ │ ├── markers-shadow@2x.png │ │ │ │ └── markers-soft@2x.png │ │ │ ├── leaflet.awesome-markers.min.js │ │ │ └── leaflet.awesome-markers.css │ │ ├── leaflet-locationfilter │ │ │ ├── img │ │ │ │ ├── filter-icon.png │ │ │ │ ├── move-handle.png │ │ │ │ └── resize-handle.png │ │ │ └── locationfilter-bindings.js │ │ ├── leaflet-providers-plugin │ │ │ └── leaflet-providers-plugin.js │ │ ├── Leaflet.SimpleGraticule │ │ │ ├── L.SimpleGraticule.css │ │ │ └── SimpleGraticule-binding.js │ │ ├── Leaflet.Graticule │ │ │ ├── Graticule-binding.js │ │ │ └── L.Graticule.js │ │ ├── Leaflet.Terminator │ │ │ └── Terminator-binding.js │ │ ├── Leaflet.markercluster │ │ │ ├── MarkerCluster.css │ │ │ ├── MIT-LICENCE.txt │ │ │ └── MarkerCluster.Default.css │ │ └── Leaflet.EasyButton │ │ │ ├── LICENSE │ │ │ ├── EasyButton-binding.js │ │ │ └── easy-button.css │ └── leaflet.yaml └── examples │ ├── graticule.R │ ├── terminator.R │ ├── simpleGraticule.R │ ├── leaflet-measure.R │ ├── providers-shiny.R │ ├── providers-digitalglobe.R │ ├── shiny-markercluster.R │ ├── legend.R │ ├── emptyData.R │ ├── geojson.R │ ├── providers.R │ ├── shiny.R │ ├── easyButton.R │ ├── highlight-polygons.R │ ├── icons.R │ ├── polygon-colors.R │ ├── marker-clustering.R │ ├── awesomeMarkers.R │ └── test.json ├── .gitignore ├── R ├── normalize-map.R ├── package.R ├── normalize-SharedData.R ├── selection.R ├── data.R ├── controls.R ├── shiny.R ├── dependencies.R ├── plugin-omnivore.R ├── plugin-graticule.R ├── plugin-terminator.R ├── scalebar.R ├── plugin-simplegraticule.R ├── methods.R ├── plugin-providers.R └── normalize-sf.R ├── .Rbuildignore ├── man ├── getMapData.Rd ├── filterNULL.Rd ├── leaflet-imports.Rd ├── providers.Rd ├── expandLimits.Rd ├── providers.details.Rd ├── previewColors.Rd ├── iconList.Rd ├── expandLimitsBbox.Rd ├── evalFormula.Rd ├── awesomeIconList.Rd ├── validateCoords.Rd ├── leafletDependencies.Rd ├── showGroup.Rd ├── deprecated.Rd ├── derivePoints.Rd ├── derivePolygons.Rd ├── addTerminator.Rd ├── mapOptions.Rd ├── addGraticule.Rd ├── addSimpleGraticule.Rd ├── map-shiny.Rd ├── dispatch.Rd ├── addScaleBar.Rd ├── addProviderTiles.Rd ├── makeAwesomeIcon.Rd ├── map-methods.Rd ├── awesomeIcons.Rd ├── makeIcon.Rd ├── addLayersControl.Rd ├── easyButton.Rd ├── leafletProxy.Rd ├── addAwesomeMarkers.Rd ├── remove.Rd ├── addMeasure.Rd └── addRasterImage.Rd ├── .travis.yml ├── leaflet.Rproj ├── data-raw └── providerNames.R ├── .eslintrc.json ├── package.json ├── README.md ├── Gruntfile.js ├── DESCRIPTION └── NEWS /.bowerrc: -------------------------------------------------------------------------------- 1 | {"directory": "inst/htmlwidgets/lib"} -------------------------------------------------------------------------------- /javascript/src/global/leaflet.js: -------------------------------------------------------------------------------- 1 | export default global.L; 2 | -------------------------------------------------------------------------------- /javascript/src/global/shiny.js: -------------------------------------------------------------------------------- 1 | export default global.Shiny; 2 | -------------------------------------------------------------------------------- /tests/test-all.R: -------------------------------------------------------------------------------- 1 | library(testit) 2 | test_pkg('leaflet') 3 | -------------------------------------------------------------------------------- /javascript/src/global/jquery.js: -------------------------------------------------------------------------------- 1 | export default global.jQuery; 2 | -------------------------------------------------------------------------------- /javascript/src/global/proj4leaflet.js: -------------------------------------------------------------------------------- 1 | export default global.L.Proj; 2 | -------------------------------------------------------------------------------- /javascript/src/global/htmlwidgets.js: -------------------------------------------------------------------------------- 1 | export default global.HTMLWidgets; 2 | -------------------------------------------------------------------------------- /data/providers.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/data/providers.rda -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(leaflet) 3 | 4 | test_check("leaflet") 5 | -------------------------------------------------------------------------------- /inst/extdata/gadmCHE.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/extdata/gadmCHE.rds -------------------------------------------------------------------------------- /data/providers.details.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/data/providers.details.rda -------------------------------------------------------------------------------- /inst/extdata/breweries91.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/extdata/breweries91.rds -------------------------------------------------------------------------------- /inst/legacy/examples/choropleth/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Title: Choropleths with Shiny and Leaflet 2 | DisplayMode: Showcase -------------------------------------------------------------------------------- /inst/extdata/atlStorms2005.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/extdata/atlStorms2005.rds -------------------------------------------------------------------------------- /inst/legacy/www/images/layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/legacy/www/images/layers.png -------------------------------------------------------------------------------- /inst/legacy/www/images/layers-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/legacy/www/images/layers-2x.png -------------------------------------------------------------------------------- /inst/legacy/www/images/marker-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/legacy/www/images/marker-icon.png -------------------------------------------------------------------------------- /inst/legacy/examples/choropleth/Rplots.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/legacy/examples/choropleth/Rplots.pdf -------------------------------------------------------------------------------- /inst/legacy/www/images/marker-icon-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/legacy/www/images/marker-icon-2x.png -------------------------------------------------------------------------------- /inst/legacy/www/images/marker-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/legacy/www/images/marker-shadow.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet/images/1px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet/images/1px.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet/images/layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet/images/layers.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet/images/layers-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet/images/layers-2x.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/Leaflet.label/images/death.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/Leaflet.label/images/death.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet/images/marker-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet/images/marker-icon.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/cancel.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/check.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/focus.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/rulers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/rulers.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/start.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/trash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/trash.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet/images/marker-icon-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet/images/marker-icon-2x.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet/images/marker-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet/images/marker-shadow.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/check_@2X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/check_@2X.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/focus_@2X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/focus_@2X.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/start_@2X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/start_@2X.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/trash_@2X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/trash_@2X.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/cancel_@2X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/cancel_@2X.png -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/images/rulers_@2X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/lib/leaflet-measure/images/rulers_@2X.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet-MiniMap/images/toggle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet-MiniMap/images/toggle.png -------------------------------------------------------------------------------- /inst/legacy/examples/choropleth/shinyapps/jcheng/choropleth3.dcf: -------------------------------------------------------------------------------- 1 | name: choropleth3 2 | account: jcheng 3 | bundleId: 17723 4 | url: http://jcheng.shinyapps.io/choropleth3 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | node_modules 5 | inst/htmlwidgets/sources 6 | *.swp 7 | inst/examples/rsconnect 8 | inst/examples/*.html 9 | R/tags 10 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/ionicons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/ionicons.eot -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/ionicons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/ionicons.ttf -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/leaflet-locationfilter/img/filter-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/leaflet-locationfilter/img/filter-icon.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/leaflet-locationfilter/img/move-handle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/leaflet-locationfilter/img/move-handle.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/ionicons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/ionicons.woff -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/leaflet-locationfilter/img/resize-handle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/leaflet-locationfilter/img/resize-handle.png -------------------------------------------------------------------------------- /R/normalize-map.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | metaData.map <- function(obj) { 3 | obj 4 | } 5 | 6 | #' @export 7 | polygonData.map <- function(obj) { 8 | polygonData(cbind(obj$x, obj$y)) 9 | } 10 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-soft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-soft.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-matte.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-matte.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-plain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-plain.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-shadow.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-matte@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-matte@2x.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-shadow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-shadow@2x.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-soft@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/images/markers-soft@2x.png -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lchiffon/leaflet/master/inst/htmlwidgets/plugins/Leaflet.awesome-markers/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /inst/legacy/examples/geojson/ui.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | shinyUI(fluidPage( 4 | leafletMap("map", 600, 400, options = list( 5 | center = c(47.6659641734893, -122.376078869215), 6 | zoom = 13 7 | )), 8 | htmlOutput("details") 9 | )) 10 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/leaflet-providers-plugin/leaflet-providers-plugin.js: -------------------------------------------------------------------------------- 1 | LeafletWidget.methods.addProviderTiles = function(provider, layerId, group, options) { 2 | this.layerManager.addLayer(L.tileLayer.provider(provider, options), "tile", layerId, group); 3 | }; 4 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^inst/csv 5 | ^inst/examples 6 | \.bower\.json$ 7 | \.bowerrc$ 8 | ^docs/ 9 | ^\.eslintrc\.json$ 10 | ^Gruntfile\.js$ 11 | ^javascript$ 12 | ^package\.json$ 13 | ^node_modules$ 14 | 15 | ^data-raw$ 16 | -------------------------------------------------------------------------------- /R/package.R: -------------------------------------------------------------------------------- 1 | #' @importFrom magrittr %>% 2 | #' @export %>% 3 | #' @importFrom htmlwidgets JS 4 | #' @importFrom grDevices col2rgb rgb 5 | #' @importFrom methods substituteDirect 6 | #' @importFrom stats na.omit quantile 7 | #' @importFrom utils getFromNamespace packageVersion 8 | #' @export JS 9 | NULL 10 | -------------------------------------------------------------------------------- /man/getMapData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/leaflet.R 3 | \name{getMapData} 4 | \alias{getMapData} 5 | \title{returns the map's data} 6 | \usage{ 7 | getMapData(map) 8 | } 9 | \arguments{ 10 | \item{map}{the map} 11 | } 12 | \description{ 13 | returns the map's data 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/testit/test-utils.R: -------------------------------------------------------------------------------- 1 | library(testit) 2 | 3 | res = evalFormula(structure(list(1, ~x, ~x + 1), class = 'FOO'), data.frame(x = 2)) 4 | 5 | assert( 6 | 'evalFormula() does not discard the class of a list', 7 | identical(class(res), c('FOO')) 8 | ) 9 | 10 | assert( 11 | 'evalFormula() evaluates formulae in a list', 12 | res[[2]] == 2, res[[3]] == 3 13 | ) 14 | -------------------------------------------------------------------------------- /man/filterNULL.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{filterNULL} 4 | \alias{filterNULL} 5 | \title{remove NULL elements from a list} 6 | \usage{ 7 | filterNULL(x) 8 | } 9 | \arguments{ 10 | \item{x}{A list whose NULL elements will be filtered} 11 | } 12 | \description{ 13 | remove NULL elements from a list 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/leaflet-imports.Rd: -------------------------------------------------------------------------------- 1 | \name{leaflet-imports} 2 | \alias{JS} 3 | \alias{\%>\%} 4 | \docType{import} 5 | \title{Objects imported from other packages} 6 | \description{ 7 | These objects are imported from other packages. Follow the links to their documentation. 8 | \describe{ 9 | \item{htmlwidgets}{\code{\link[htmlwidgets:JS]{JS}}} 10 | \item{magrittr}{\code{\link[magrittr:\%>\%]{\%>\%}}} 11 | }} 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | sudo: required 3 | cache: packages 4 | dist: trusty 5 | 6 | before_install: 7 | - sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable --yes 8 | - sudo apt-get --yes --force-yes update -qq 9 | - sudo apt-get install --yes libudunits2-dev libproj-dev libgeos-dev libgdal-dev 10 | 11 | notifications: 12 | email: 13 | on_success: change 14 | on_failure: change 15 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.SimpleGraticule/L.SimpleGraticule.css: -------------------------------------------------------------------------------- 1 | .leaflet-grid-label .gridlabel-vert { 2 | margin-left: 8px; 3 | -webkit-transform: rotate(90deg); 4 | transform: rotate(90deg); 5 | } 6 | 7 | .leaflet-grid-label .gridlabel-vert, 8 | .leaflet-grid-label .gridlabel-horiz { 9 | padding-left:2px; 10 | text-shadow: -2px 0 #FFFFFF, 0 2px #FFFFFF, 2px 0 #FFFFFF, 0 -2px #FFFFFF; 11 | } 12 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-providers/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | So you want to add a layer? 2 | ======= 3 | 4 | Yay! go add it to the leaflet-providers.js as long as it follows the following 5 | rules: 6 | 7 | - Don't violate a providers TOS (if it exists, include a link to it) 8 | - Don't pre-populate api keys with working keys. 9 | - It should be a basic tile source, no exteral libraries etc. 10 | - The owner hasn't asked us to remove it (hasn't happened yet) -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.Graticule/Graticule-binding.js: -------------------------------------------------------------------------------- 1 | LeafletWidget.methods.addGraticule = function(interval, sphere, style, 2 | layerId, group, options) { 3 | (function() { 4 | this.layerManager.addLayer( 5 | L.graticule($.extend({ 6 | interval: interval, 7 | sphere: sphere, 8 | style: style 9 | }, options || {})), 10 | 'shape', layerId, group); 11 | }).call(this); 12 | }; 13 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.Terminator/Terminator-binding.js: -------------------------------------------------------------------------------- 1 | LeafletWidget.methods.addTerminator = function(resolution, time, 2 | layerId, group, options) { 3 | (function() { 4 | this.layerManager.addLayer( 5 | L.terminator($.extend({ 6 | resolution: resolution, 7 | time: time, 8 | group: group 9 | }, options || {})), 10 | 'shape', layerId, group); 11 | }).call(this); 12 | }; 13 | 14 | 15 | -------------------------------------------------------------------------------- /R/normalize-SharedData.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | metaData.sharedData <- function(obj) { 3 | obj$data(withSelection = TRUE, withFilter = FALSE, withKey = TRUE) 4 | } 5 | 6 | #' @export 7 | pointData.SharedData <- function(obj) { 8 | pointData(obj$data(withSelection = FALSE, withFilter = FALSE, withKey = FALSE)) 9 | } 10 | 11 | #' @export 12 | polygonData.SharedData <- function(obj) { 13 | polygonData(obj$data(withSelection = FALSE, withFilter = FALSE, withKey = FALSE)) 14 | } 15 | -------------------------------------------------------------------------------- /man/providers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-providers.R 3 | \docType{data} 4 | \name{providers} 5 | \alias{providers} 6 | \title{Providers} 7 | \format{A list of characters} 8 | \source{ 9 | \url{https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js} 10 | } 11 | \usage{ 12 | providers 13 | } 14 | \description{ 15 | List of all providers with their variations 16 | } 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /inst/examples/graticule.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | # Default 3 | l <- leaflet() %>% addTiles() %>% setView(0,0,2) 4 | 5 | #' Default Graticule 6 | l %>% addGraticule() 7 | 8 | #'
9 | #' Custom Params 10 | l %>% addGraticule(interval = 40, style = list(color='#FF0000', weight=1)) 11 | 12 | #'
13 | #' on a toggleable Layer 14 | l %>% 15 | addGraticule(group="graticule") %>% 16 | addLayersControl( 17 | overlayGroups = c("graticule"), 18 | options = layersControlOptions(collapsed = FALSE) 19 | ) 20 | -------------------------------------------------------------------------------- /leaflet.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --with-keep.source 21 | PackageCheckArgs: --as-cran --no-manual --run-donttest 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /man/expandLimits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{expandLimits} 4 | \alias{expandLimits} 5 | \title{Notifies the map of new latitude/longitude of items of interest on the map} 6 | \usage{ 7 | expandLimits(map, lat, lng) 8 | } 9 | \arguments{ 10 | \item{map}{map object} 11 | 12 | \item{lat}{vector of latitudes} 13 | 14 | \item{lng}{vector of longitudes} 15 | } 16 | \description{ 17 | Notifies the map of new latitude/longitude of items of interest on the map 18 | } 19 | 20 | -------------------------------------------------------------------------------- /man/providers.details.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-providers.R 3 | \docType{data} 4 | \name{providers.details} 5 | \alias{providers.details} 6 | \title{Providers Details} 7 | \format{A list of lists (JSON)} 8 | \source{ 9 | \url{https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js} 10 | } 11 | \usage{ 12 | providers.details 13 | } 14 | \description{ 15 | List of all providers with their variations and additional info 16 | } 17 | \keyword{datasets} 18 | 19 | -------------------------------------------------------------------------------- /man/previewColors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colors.R 3 | \name{previewColors} 4 | \alias{previewColors} 5 | \title{Color previewing utility} 6 | \usage{ 7 | previewColors(pal, values) 8 | } 9 | \arguments{ 10 | \item{pal}{A color mapping function, like those returned from \code{\link{colorNumeric}}, et al} 11 | 12 | \item{values}{A set of values to preview colors for} 13 | } 14 | \value{ 15 | An HTML-based list of the colors and values 16 | } 17 | \description{ 18 | Color previewing utility 19 | } 20 | 21 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.SimpleGraticule/SimpleGraticule-binding.js: -------------------------------------------------------------------------------- 1 | LeafletWidget.methods.addSimpleGraticule = function(interval, showOriginLabel, 2 | redraw, hidden, zoomIntervals, layerId, group) { 3 | (function() { 4 | this.layerManager.addLayer( 5 | L.simpleGraticule({ 6 | interval: interval, 7 | showOriginLabel: showOriginLabel, 8 | redraw: redraw, 9 | hidden: hidden, 10 | zoomIntervals: zoomIntervals 11 | }), 12 | 'shape', layerId, group); 13 | }).call(this); 14 | }; 15 | -------------------------------------------------------------------------------- /man/iconList.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{iconList} 4 | \alias{iconList} 5 | \title{Make icon set} 6 | \usage{ 7 | iconList(...) 8 | } 9 | \arguments{ 10 | \item{...}{icons created from \code{\link{makeIcon}()}} 11 | } 12 | \description{ 13 | Make icon set 14 | } 15 | \examples{ 16 | 17 | iconSet = iconList( 18 | red = makeIcon("leaf-red.png", iconWidth=32, iconHeight=32), 19 | green = makeIcon("leaf-green.png", iconWidth=32, iconHeight=32) 20 | ) 21 | 22 | iconSet[c('red', 'green', 'red')] 23 | } 24 | 25 | -------------------------------------------------------------------------------- /man/expandLimitsBbox.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{expandLimitsBbox} 4 | \alias{expandLimitsBbox} 5 | \title{Same as expandLimits, but takes a polygon (that presumably has a bbox attr) 6 | rather than lat/lng.} 7 | \usage{ 8 | expandLimitsBbox(map, poly) 9 | } 10 | \arguments{ 11 | \item{map}{map object} 12 | 13 | \item{poly}{A spatial object representing a polygon.} 14 | } 15 | \description{ 16 | Same as expandLimits, but takes a polygon (that presumably has a bbox attr) 17 | rather than lat/lng. 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tests/testit/test-icon.R: -------------------------------------------------------------------------------- 1 | library(testit) 2 | 3 | icons <- c("leaf-green.png", "leaf-red.png") 4 | m <- leaflet(data = data.frame(color = sample.int(2, 30, replace = TRUE))) %>% 5 | addMarkers(1:30, 30:1, icon = icons( 6 | iconUrl = ~icons[color], 7 | shadowUrl = c("leaf-shadow.png"), 8 | iconWidth = 38, iconHeight = 95, iconAnchorX = 22, iconAnchorY = 94, 9 | shadowWidth = 50, shadowHeight = 64, shadowAnchorX = 4, shadowAnchorY = 62 10 | )) 11 | assert( 12 | 'icon deduping works', 13 | identical(length(m$x$calls[[1]]$args[[3]]$iconUrl$data), 2L), 14 | TRUE 15 | ) 16 | -------------------------------------------------------------------------------- /man/evalFormula.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{evalFormula} 4 | \alias{evalFormula} 5 | \title{Evaluate list members that are formulae, using the map data as the environment 6 | (if provided, otherwise the formula environment)} 7 | \usage{ 8 | evalFormula(list, data) 9 | } 10 | \arguments{ 11 | \item{list}{with members as formulae} 12 | 13 | \item{data}{map data} 14 | } 15 | \description{ 16 | Evaluate list members that are formulae, using the map data as the environment 17 | (if provided, otherwise the formula environment) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /man/awesomeIconList.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-awesomeMarkers.R 3 | \name{awesomeIconList} 4 | \alias{awesomeIconList} 5 | \title{Make awesome-icon set} 6 | \usage{ 7 | awesomeIconList(...) 8 | } 9 | \arguments{ 10 | \item{...}{icons created from \code{\link{makeAwesomeIcon}()}} 11 | } 12 | \description{ 13 | Make awesome-icon set 14 | } 15 | \examples{ 16 | 17 | iconSet = awesomeIconList( 18 | home = makeAwesomeIcon(icon='Home', library='fa'), 19 | flag = makeAwesomeIcon(icon='Flag', library='fa') 20 | ) 21 | 22 | iconSet[c('home', 'flag')] 23 | } 24 | 25 | -------------------------------------------------------------------------------- /inst/examples/terminator.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | # Default Resolution 3 | leaflet() %>% addTiles() %>% addTerminator() 4 | 5 | # Custom Resolutions 6 | leaflet() %>% addTiles() %>% addTerminator(resolution=1) 7 | leaflet() %>% addTiles() %>% addTerminator(resolution=100) 8 | 9 | # Custom Resolution + Custom Date and on a toggleable Layer 10 | leaflet() %>% addTiles() %>% 11 | addTerminator(resolution=10, 12 | time='2013-06-20T21:00:00Z', 13 | group="daylight") %>% 14 | addLayersControl( 15 | overlayGroups = c("daylight"), 16 | options = layersControlOptions(collapsed = FALSE) 17 | ) 18 | -------------------------------------------------------------------------------- /inst/examples/simpleGraticule.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | # Default 3 | l <- leaflet() %>% addTiles() %>% setView(0,0,1) 4 | 5 | #' Default simple Graticule 6 | l %>% addSimpleGraticule() 7 | 8 | #'
9 | #' Custom Params 10 | l %>% addSimpleGraticule(interval = 40, showOriginLabel = F) 11 | 12 | #'
13 | #' Custom Resolution + Custom Date and on a toggleable Layer 14 | l %>% 15 | addSimpleGraticule(interval=40, 16 | showOriginLabel = F, 17 | group="graticule") %>% 18 | addLayersControl( 19 | overlayGroups = c("graticule"), 20 | options = layersControlOptions(collapsed = FALSE) 21 | ) 22 | -------------------------------------------------------------------------------- /inst/examples/leaflet-measure.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | leaf <- leaflet() %>% 4 | addTiles() 5 | 6 | #'
7 | #' Default Behavior 8 | leaf %>% 9 | # central park 10 | fitBounds(-73.9, 40.75, -73.95,40.8) %>% 11 | addMeasure() 12 | 13 | #'
14 | #' Customization 15 | leaf %>% 16 | # Berling, Germany with German localization 17 | fitBounds(13.76134, 52.675499, 13.0884, 52.33812) %>% 18 | addMeasure( 19 | position = "bottomleft", 20 | primaryLengthUnit = "meters", 21 | primaryAreaUnit = "sqmeters", 22 | activeColor = "#3D535D", 23 | completedColor = "#7D4479", 24 | localization='de' 25 | ) 26 | -------------------------------------------------------------------------------- /man/validateCoords.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{validateCoords} 4 | \alias{validateCoords} 5 | \title{Utility function to check if a coordinates is valid} 6 | \usage{ 7 | validateCoords(lng, lat, funcName, warn = T) 8 | } 9 | \arguments{ 10 | \item{lng}{vector with longitude values} 11 | 12 | \item{lat}{vector with latitude values} 13 | 14 | \item{funcName}{Name of calling function} 15 | 16 | \item{warn}{A boolean. Whether to generate a warning message if there are rows with missing/invalid data} 17 | } 18 | \description{ 19 | Utility function to check if a coordinates is valid 20 | } 21 | 22 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-providers/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaflet-providers", 3 | "version": "1.1.15", 4 | "homepage": "https://github.com/leaflet-extras/leaflet-providers", 5 | "description": "An extension to Leaflet that contains configurations for various free tile providers.", 6 | "dependencies": { 7 | "leaflet": "~0.7.3" 8 | }, 9 | "main": "leaflet-providers.js", 10 | "keywords": [ 11 | "leaflet", 12 | "stamen", 13 | "osm" 14 | ], 15 | "license": "BSD-2-Clause", 16 | "ignore": [ 17 | "**/.*", 18 | "node_modules", 19 | "bower_components", 20 | "test", 21 | "tests", 22 | "preview", 23 | "*.html" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /man/leafletDependencies.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dependencies.R 3 | \docType{data} 4 | \name{leafletDependencies} 5 | \alias{leafletDependencies} 6 | \title{Various leaflet dependency functions for use in downstream packages} 7 | \format{An object of class \code{list} of length 13.} 8 | \usage{ 9 | leafletDependencies 10 | } 11 | \description{ 12 | Various leaflet dependency functions for use in downstream packages 13 | } 14 | \examples{ 15 | \dontrun{ 16 | addBootStrap <- function(map) { 17 | map$dependencies <- c(map$dependencies, leafletDependencies$bootstrap()) 18 | map 19 | } 20 | } 21 | } 22 | \keyword{datasets} 23 | 24 | -------------------------------------------------------------------------------- /inst/legacy/examples/population/www/styles.css: -------------------------------------------------------------------------------- 1 | @import url(//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600); 2 | 3 | body { 4 | overflow-y: scroll; 5 | padding-bottom: 20px; 6 | } 7 | 8 | body { 9 | font-family: Source Sans Pro; 10 | color: #444; 11 | font-weight: 300; 12 | } 13 | 14 | #map { 15 | position: absolute; 16 | top: 0; 17 | left: 0; 18 | right: 0; 19 | bottom: 400; 20 | } 21 | 22 | #data table { 23 | width: 100%; 24 | } 25 | #data td+td { 26 | width: 80px; 27 | } 28 | 29 | .container-fluid { 30 | padding-top: 400px; 31 | } 32 | 33 | #desc { font-size: 16px; } 34 | 35 | #desc span { 36 | color: #944; 37 | font-weight: 400; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /man/showGroup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{showGroup} 4 | \alias{hideGroup} 5 | \alias{showGroup} 6 | \title{Show or hide layer groups} 7 | \usage{ 8 | showGroup(map, group) 9 | 10 | hideGroup(map, group) 11 | } 12 | \arguments{ 13 | \item{map}{the map to modify} 14 | 15 | \item{group}{character vector of one or more group names to show or hide} 16 | } 17 | \description{ 18 | Hide groups of layers without removing them from the map entirely. Groups are 19 | created using the \code{group} parameter that is included on most layer 20 | adding functions. 21 | } 22 | \seealso{ 23 | \code{\link{addLayersControl}} to allow users to show/hide layer 24 | groups interactively 25 | } 26 | 27 | -------------------------------------------------------------------------------- /inst/htmlwidgets/leaflet.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | - name: jquery 3 | version: 1.12.4 4 | src: "htmlwidgets/lib/jquery" 5 | script: jquery.min.js 6 | - name: leaflet 7 | version: 0.7.7 8 | src: "htmlwidgets/lib/leaflet" 9 | script: leaflet.js 10 | stylesheet: leaflet.css 11 | - name: leafletfix 12 | version: 1.0.0 13 | src: "htmlwidgets/lib/leafletfix" 14 | stylesheet: leafletfix.css 15 | - name: leaflet-label 16 | version: 0.2.2 17 | src: "htmlwidgets/lib/Leaflet.label" 18 | script: leaflet.label.js 19 | stylesheet: leaflet.label.css 20 | - name: Proj4Leaflet 21 | version: 0.7.2 22 | src: "htmlwidgets/plugins/Proj4Leaflet" 23 | script: 24 | - proj4-compressed.js 25 | - proj4leaflet.js 26 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leafletfix/leafletfix.css: -------------------------------------------------------------------------------- 1 | /* Work around CSS properties introduced on img by bootstrap */ 2 | img.leaflet-tile { 3 | padding: 0; 4 | margin: 0; 5 | border-radius: 0; 6 | border: none; 7 | } 8 | .info { 9 | padding: 6px 8px; 10 | font: 14px/16px Arial, Helvetica, sans-serif; 11 | background: white; 12 | background: rgba(255,255,255,0.8); 13 | box-shadow: 0 0 15px rgba(0,0,0,0.2); 14 | border-radius: 5px; 15 | } 16 | .legend { 17 | line-height: 18px; 18 | color: #555; 19 | } 20 | .legend svg text { 21 | fill: #555; 22 | } 23 | .legend svg line { 24 | stroke: #555; 25 | } 26 | .legend i { 27 | width: 18px; 28 | height: 18px; 29 | float: left; 30 | margin-right: 8px; 31 | opacity: 0.7; 32 | } 33 | -------------------------------------------------------------------------------- /data-raw/providerNames.R: -------------------------------------------------------------------------------- 1 | # The JSON was extracted and fixed from ... 2 | # https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js 3 | 4 | providers.details <- jsonlite::fromJSON( 5 | './inst/htmlwidgets/lib/leaflet-providers/providers.json') 6 | 7 | variants <- purrr::map(providers.details, ~ names(.$variants)) 8 | 9 | providers <- purrr::map(names(providers.details), function(provider) { 10 | if(is.null(variants[[provider]])) { 11 | provider 12 | } else { 13 | c(provider, stringr::str_c(provider,'.',variants[[provider]])) 14 | } 15 | }) %>% purrr::flatten_chr() 16 | 17 | providers <- setNames(as.list(providers), providers) 18 | 19 | devtools::use_data(providers.details, overwrite = TRUE) 20 | devtools::use_data(providers, overwrite = TRUE) 21 | 22 | 23 | -------------------------------------------------------------------------------- /inst/examples/providers-shiny.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(leaflet) 3 | 4 | ui <- fluidPage( 5 | fluidRow( 6 | column( 7 | 3, 8 | selectInput( 9 | "providerName", 10 | "Tile set", 11 | c("Stamen.Toner", 12 | "Stamen.TonerLite", 13 | "Stamen.Watercolor") 14 | ) 15 | ), 16 | column( 17 | 9, 18 | leafletOutput("map") 19 | 20 | ) 21 | ) 22 | ) 23 | 24 | server <- function(input, output, session) { 25 | output$map <- renderLeaflet({ 26 | leaflet() %>% addTiles(layerId = "tiles") %>% setView(0, 0, 1) 27 | }) 28 | 29 | observeEvent(input$providerName, { 30 | leafletProxy("map", session) %>% 31 | addProviderTiles(input$providerName, layerId = "tiles") 32 | }) 33 | } 34 | 35 | shinyApp(ui, server) 36 | -------------------------------------------------------------------------------- /man/deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/legacy.R 3 | \name{createLeafletMap} 4 | \alias{createLeafletMap} 5 | \alias{leafletMap} 6 | \title{Legacy functions} 7 | \usage{ 8 | createLeafletMap(session, outputId) 9 | 10 | leafletMap(outputId, width, height, 11 | initialTileLayer = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", 12 | initialTileLayerAttribution = NULL, options = NULL) 13 | } 14 | \arguments{ 15 | \item{session, outputId}{Deprecated} 16 | 17 | \item{width, height, initialTileLayer, initialTileLayerAttribution, options}{Deprecated} 18 | } 19 | \description{ 20 | These functions are provided for backwards compatibility with the first 21 | iteration of the leaflet bindings 22 | (\url{https://github.com/jcheng5/leaflet-shiny}). 23 | } 24 | 25 | -------------------------------------------------------------------------------- /R/selection.R: -------------------------------------------------------------------------------- 1 | locationFilter2Dependencies <- function() { 2 | list( 3 | htmltools::htmlDependency( 4 | "leaflet-locationfilter2", 5 | "0.1.0", 6 | system.file("htmlwidgets/plugins/leaflet-locationfilter", package = "leaflet"), 7 | script = c("locationfilter.js", "locationfilter-bindings.js"), 8 | stylesheet = c("locationfilter.css") 9 | ) 10 | ) 11 | } 12 | 13 | addSelect <- function(map, data = getMapData(map)) { 14 | map$dependencies <- c(map$dependencies, 15 | leafletEasyButtonDependencies(), 16 | locationFilter2Dependencies()) 17 | map <- addIonIcon(map) 18 | 19 | invokeMethod(map, data, "addSelect", 20 | getCrosstalkOptions(data)[["ctGroup"]] 21 | ) 22 | } 23 | 24 | removeSelect <- function(map) { 25 | invokeMethod(map, NULL, "removeSelect") 26 | } 27 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es6": true 5 | }, 6 | "extends": "eslint:recommended", 7 | "parserOptions": { 8 | "sourceType": "module" 9 | }, 10 | "rules": { 11 | "indent": [ 12 | "error", 13 | 2 14 | ], 15 | "linebreak-style": [ 16 | "error", 17 | "unix" 18 | ], 19 | "quotes": [ 20 | "error", 21 | "double" 22 | ], 23 | "no-undef": [ 24 | "error" 25 | ], 26 | 27 | "no-console": "warn", 28 | "no-unused-vars": ["error", {"args": "none"}], 29 | "semi": "error", 30 | "no-extra-semi": "error", 31 | "indent": ["error", 2] 32 | }, 33 | "globals": { 34 | "global": true 35 | } 36 | } -------------------------------------------------------------------------------- /tests/testit/test-measure.R: -------------------------------------------------------------------------------- 1 | library(testit) 2 | 3 | # did the dependency get added? 4 | assert( 5 | !is.na(Position( 6 | function(dep) dep$name == "leaflet-measure" 7 | , addMeasure(leaflet())$dependencies 8 | )) 9 | ) 10 | 11 | # did the call get added? 12 | assert( 13 | !is.na(Position( 14 | function(cl) cl$method == "addMeasure" 15 | , addMeasure(leaflet())$x$calls 16 | )) 17 | ) 18 | 19 | # were options added as expected 20 | assert( 21 | Filter( 22 | function(cl) cl$method == "addMeasure" 23 | , addMeasure(leaflet(), position = "bottomleft")$x$calls 24 | )[[1]]$args[[1]]$position == "bottomleft" 25 | ) 26 | 27 | # are null options removed 28 | # were options added as expected 29 | assert( 30 | !("position" %in% names(Filter( 31 | function(cl) cl$method == "addMeasure" 32 | , addMeasure(leaflet(), position = NULL )$x$calls 33 | )[[1]]$args[[1]])) 34 | ) 35 | -------------------------------------------------------------------------------- /javascript/src/cluster-layer-store.js: -------------------------------------------------------------------------------- 1 | import { asArray } from "./util"; 2 | 3 | export default class ClusterLayerStore { 4 | constructor(group) { 5 | this._layers = {}; 6 | this._group = group; 7 | } 8 | 9 | add(layer, id) { 10 | if (typeof(id) !== "undefined" && id !== null) { 11 | if (this._layers[id]) { 12 | this._group.removeLayer(this._layers[id]); 13 | } 14 | this._layers[id] = layer; 15 | } 16 | this._group.addLayer(layer); 17 | } 18 | 19 | remove(id) { 20 | if (typeof(id) === "undefined" || id === null) { 21 | return; 22 | } 23 | 24 | id = asArray(id); 25 | for (let i = 0; i < id.length; i++) { 26 | if (this._layers[id[i]]) { 27 | this._group.removeLayer(this._layers[id[i]]); 28 | delete this._layers[id[i]]; 29 | } 30 | } 31 | } 32 | 33 | clear() { 34 | this._layers = {}; 35 | this._group.clearLayers(); 36 | } 37 | } -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.markercluster/MarkerCluster.css: -------------------------------------------------------------------------------- 1 | .leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow { 2 | -webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in; 3 | -moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in; 4 | -o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in; 5 | transition: transform 0.3s ease-out, opacity 0.3s ease-in; 6 | } 7 | 8 | .leaflet-cluster-spider-leg { 9 | /* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */ 10 | -webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in; 11 | -moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in; 12 | -o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in; 13 | transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in; 14 | } 15 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaflet", 3 | "version": "0.7.3", 4 | "description": "JavaScript library for mobile-friendly interactive maps", 5 | "main": [ 6 | "dist/leaflet.js", 7 | "dist/leaflet.css", 8 | "dist/leaflet-src.js", 9 | "dist/images/layers-2x.png", 10 | "dist/images/layers.png", 11 | "dist/images/marker-icon-2x.png", 12 | "dist/images/marker-icon.png", 13 | "dist/images/marker-shadow.png" 14 | ], 15 | "ignore": [ 16 | ".*", 17 | "CHANGELOG.json", 18 | "FAQ.md", 19 | "debug", 20 | "spec", 21 | "src", 22 | "build" 23 | ], 24 | "homepage": "https://github.com/Leaflet/Leaflet", 25 | "_release": "0.7.3", 26 | "_resolution": { 27 | "type": "version", 28 | "tag": "v0.7.3", 29 | "commit": "8a5fdfc6e3db2807b8f0dd617474e4ab2949142b" 30 | }, 31 | "_source": "git://github.com/Leaflet/Leaflet.git", 32 | "_target": "~0.7.3", 33 | "_originalSource": "leaflet" 34 | } -------------------------------------------------------------------------------- /javascript/src/util.js: -------------------------------------------------------------------------------- 1 | export function log(message) { 2 | /* eslint-disable no-console */ 3 | if (console && console.log) console.log(message); 4 | /* eslint-enable no-console */ 5 | } 6 | 7 | export function recycle(values, length, inPlace) { 8 | if (length === 0 && !inPlace) 9 | return []; 10 | 11 | if (!(values instanceof Array)) { 12 | if (inPlace) { 13 | throw new Error("Can't do in-place recycling of a non-Array value"); 14 | } 15 | values = [values]; 16 | } 17 | if (typeof(length) === "undefined") 18 | length = values.length; 19 | 20 | let dest = inPlace ? values : []; 21 | let origLength = values.length; 22 | while (dest.length < length) { 23 | dest.push(values[dest.length % origLength]); 24 | } 25 | if (dest.length > length) { 26 | dest.splice(length, dest.length - length); 27 | } 28 | return dest; 29 | } 30 | 31 | export function asArray(value) { 32 | if (value instanceof Array) 33 | return value; 34 | else 35 | return [value]; 36 | } 37 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-providers/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaflet-providers", 3 | "version": "1.0.27", 4 | "homepage": "https://github.com/leaflet-extras/leaflet-providers", 5 | "description": "An extension to Leaflet that contains configurations for various free tile providers.", 6 | "dependencies": { 7 | "leaflet": "~0.7.3" 8 | }, 9 | "main": "leaflet-providers.js", 10 | "keywords": [ 11 | "leaflet", 12 | "stamen", 13 | "osm" 14 | ], 15 | "license": "BSD-2-Clause", 16 | "ignore": [ 17 | "**/.*", 18 | "node_modules", 19 | "bower_components", 20 | "test", 21 | "tests", 22 | "preview", 23 | "*.html" 24 | ], 25 | "_release": "1.0.27", 26 | "_resolution": { 27 | "type": "version", 28 | "tag": "1.0.27", 29 | "commit": "cd61a578f5fc77c0ef65270a9069c80fb59907a5" 30 | }, 31 | "_source": "git://github.com/leaflet-extras/leaflet-providers.git", 32 | "_target": "~1.0.27", 33 | "_originalSource": "leaflet-providers", 34 | "_direct": true 35 | } -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' City and town intercensal US population estimates (2000-2010) 2 | #' 3 | #' Intercensal estimates of the resident population for Incorporated Places and 4 | #' Minor Civil Divisions: April 1, 2000 to July 1, 2010. 5 | #' @docType data 6 | #' @format A data frame containing \code{City}, \code{State}, \code{Lat}, 7 | #' \code{Long}, and population estimates from 2000 to 2010 (columns 8 | #' \code{Pop2000} to \code{Pop2010}). 9 | #' @source The US Census Bureau: 10 | #' \url{http://www.census.gov/popest/data/intercensal/cities/cities2010.html} 11 | #' @noRd 12 | #' @examples library(leaflet) 13 | #' str(uspop2000) 14 | #' p = uspop2000$Pop2010 15 | #' p = (p - min(p))/(max(p) - min(p)) 16 | #' plot(Lat ~ Long, data = uspop2000, cex = sqrt(p), asp = 1, col = rgb(1, 0, 0, .3)) 17 | 18 | if(FALSE){ 19 | uspop2000 = NULL 20 | if (file.exists('inst/csv/uspop2000.csv')) { 21 | uspop2000 = read.csv( 22 | text = readLines('inst/csv/uspop2000.csv', encoding = 'UTF-8'), 23 | stringsAsFactors = FALSE 24 | ) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /inst/examples/providers-digitalglobe.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | mapbox.tileIds <- list('Recent Imagery with Streets'='digitalglobe.nal0mpda', 3 | 'Recent Imagery'='digitalglobe.nal0g75k', 4 | 'Street Map'='digitalglobe.nako6329', 5 | 'Terrain Map'='digitalglobe.nako1fhg') 6 | 7 | m <- leaflet() %>% setView(0,0,1) 8 | 9 | names(mapbox.tileIds) %>% 10 | purrr::walk(function(x) { 11 | m <<- m %>% 12 | addProviderTiles(providers$MapBox, group = x, 13 | options = providerTileOptions( 14 | detectRetina = TRUE, 15 | # id and accessToken are Mapbox specific options 16 | id = mapbox.tileIds[[x]] , 17 | accessToken = Sys.getenv('DIGITALGLOBE_API_KEY') 18 | )) 19 | }) 20 | 21 | m %>% 22 | setView(-77.0353, 38.8895, 15) %>% 23 | addLayersControl( 24 | baseGroups = names(mapbox.tileIds), 25 | options = layersControlOptions(collapsed = FALSE) 26 | ) 27 | -------------------------------------------------------------------------------- /man/derivePoints.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/normalize.R 3 | \name{derivePoints} 4 | \alias{derivePoints} 5 | \title{Given a data object and lng/lat arguments (which may be NULL [meaning infer 6 | from data], formula [which should be evaluated with respect to the data], or 7 | vector data [which should be used as-is]) return a lng/lat data frame.} 8 | \usage{ 9 | derivePoints(data, lng = NULL, lat = NULL, missingLng = missing(lng), 10 | missingLat = missing(lat), funcName = "f") 11 | } 12 | \arguments{ 13 | \item{data}{map data} 14 | 15 | \item{lng}{longitude} 16 | 17 | \item{lat}{latitude} 18 | 19 | \item{missingLng}{whether lng is missing} 20 | 21 | \item{missingLat}{whether lat is missing} 22 | 23 | \item{funcName}{Name of calling function (for logging)} 24 | } 25 | \description{ 26 | Given a data object and lng/lat arguments (which may be NULL [meaning infer 27 | from data], formula [which should be evaluated with respect to the data], or 28 | vector data [which should be used as-is]) return a lng/lat data frame. 29 | } 30 | 31 | -------------------------------------------------------------------------------- /man/derivePolygons.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/normalize.R 3 | \name{derivePolygons} 4 | \alias{derivePolygons} 5 | \title{Given a data object and lng/lat arguments (which may be NULL [meaning infer 6 | from data], formula [which should be evaluated with respect to the data], or 7 | vector data [which should be used as-is]) return a spatial object} 8 | \usage{ 9 | derivePolygons(data, lng = NULL, lat = NULL, missingLng = missing(lng), 10 | missingLat = missing(lat), funcName = "f") 11 | } 12 | \arguments{ 13 | \item{data}{map data} 14 | 15 | \item{lng}{longitude} 16 | 17 | \item{lat}{latitude} 18 | 19 | \item{missingLng}{whether lng is missing} 20 | 21 | \item{missingLat}{whether lat is missing} 22 | 23 | \item{funcName}{Name of calling function (for logging)} 24 | } 25 | \description{ 26 | Given a data object and lng/lat arguments (which may be NULL [meaning infer 27 | from data], formula [which should be evaluated with respect to the data], or 28 | vector data [which should be used as-is]) return a spatial object 29 | } 30 | 31 | -------------------------------------------------------------------------------- /inst/examples/shiny-markercluster.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(leaflet) 3 | 4 | shinyApp( 5 | ui = fluidPage( 6 | leafletOutput('map1'), 7 | actionButton('add', 'Add marker cluster'), 8 | actionButton('clear', 'Clear marker cluster'), 9 | selectizeInput('remove1', 'Remove markers', rownames(quakes), multiple = TRUE) 10 | ), 11 | server = function(input, output, session) { 12 | output$map1 = renderLeaflet({ 13 | leaflet() %>% addTiles() %>% setView(180, -24, 4) 14 | }) 15 | observeEvent(input$add, { 16 | leafletProxy('map1') %>% addMarkers( 17 | data = quakes, 18 | popup = ~sprintf('magnitude = %s', mag), layerId = rownames(quakes), 19 | clusterOptions = markerClusterOptions(), clusterId = 'cluster1' 20 | ) 21 | }) 22 | observeEvent(input$clear, { 23 | leafletProxy('map1') %>% clearMarkerClusters() 24 | }) 25 | observe({ 26 | leafletProxy('map1') %>% removeMarkerFromCluster(input$remove1, 'cluster1') 27 | }) 28 | observe({ 29 | print(input$map1_marker_click) 30 | }) 31 | } 32 | ) 33 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.EasyButton/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Daniel Montague 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /man/addTerminator.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-terminator.R 3 | \name{addTerminator} 4 | \alias{addTerminator} 5 | \title{Add a daylight layer on top of the map} 6 | \usage{ 7 | addTerminator(map, resolution = 2, time = NULL, layerId = NULL, 8 | group = NULL, options = pathOptions(pointerEvents = "none", clickable = 9 | FALSE)) 10 | } 11 | \arguments{ 12 | \item{map}{a map widget object} 13 | 14 | \item{resolution}{the step size at which the terminator points are computed. 15 | The step size is 1 degree/resolution, i.e. higher resolution values have 16 | smaller step sizes and more points in the polygon. The default value is 2.} 17 | 18 | \item{time}{Time} 19 | 20 | \item{layerId}{the layer id} 21 | 22 | \item{group}{the name of the group this layer belongs to.} 23 | 24 | \item{options}{the path options for the daynight layer} 25 | } 26 | \description{ 27 | See \url{https://github.com/joergdietrich/Leaflet.Terminator} 28 | } 29 | \examples{ 30 | library(leaflet) 31 | 32 | leaf <- leaflet() \%>\% 33 | addTiles() \%>\% 34 | addTerminator() 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /inst/examples/legend.R: -------------------------------------------------------------------------------- 1 | # !formatR 2 | library(leaflet) 3 | # a manual legend 4 | leaflet() %>% addTiles() %>% addLegend( 5 | position = 'bottomright', 6 | colors = rgb(t(col2rgb(palette())) / 255), 7 | labels = palette(), opacity = 1, 8 | title = 'An Obvious Legend' 9 | ) 10 | 11 | # an automatic legend derived from the color palette 12 | df = local({ 13 | n = 300; x = rnorm(n); y = rnorm(n) 14 | z = sqrt(x^2 + y^2); z[sample(n, 10)] = NA 15 | data.frame(x, y, z) 16 | }) 17 | pal = colorNumeric('OrRd', df$z) 18 | leaflet(df) %>% 19 | addCircleMarkers(~x, ~y, color = ~pal(z)) %>% 20 | addLegend(pal = pal, values = ~z) 21 | 22 | # format legend labels 23 | df = data.frame(x = rnorm(100), y = rexp(100, 2), z = runif(100)) 24 | pal = colorBin('PuOr', df$z, bins = c(0, .1, .4, .9, 1)) 25 | leaflet(df) %>% 26 | addCircleMarkers(~x, ~y, color = ~pal(z)) %>% 27 | addLegend(pal = pal, values = ~z) 28 | 29 | leaflet(df) %>% 30 | addCircleMarkers(~x, ~y, color = ~pal(z)) %>% 31 | addLegend(pal = pal, values = ~z, labFormat = labelFormat( 32 | prefix = '(', suffix = ')%', between = ', ', 33 | transform = function(x) 100 * x 34 | )) 35 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.EasyButton/EasyButton-binding.js: -------------------------------------------------------------------------------- 1 | getEasyButton = function(button) { 2 | 3 | var options = {}; 4 | 5 | options.position = button.position; 6 | 7 | // only add ID if provided 8 | if(button.id) { 9 | options.id = button.id; 10 | } 11 | 12 | // if custom states provided use that 13 | // else use provided icon and onClick 14 | if(button.states) { 15 | options.states = button.states; 16 | return L.easyButton(options); 17 | } else { 18 | return L.easyButton(button.icon, button.onClick, 19 | button.title, options ); 20 | } 21 | }; 22 | 23 | LeafletWidget.methods.addEasyButton = function(button) { 24 | getEasyButton(button).addTo(this); 25 | }; 26 | 27 | LeafletWidget.methods.addEasyButtonBar = function(buttons, position, id) { 28 | 29 | var options = {}; 30 | 31 | options.position = position; 32 | 33 | // only add ID if provided 34 | if(id) { 35 | options.id = id; 36 | } 37 | 38 | var easyButtons = []; 39 | for(var i=0; i < buttons.length; i++) { 40 | easyButtons[i] = getEasyButton(buttons[i]); 41 | } 42 | L.easyBar(easyButtons).addTo(this); 43 | 44 | }; 45 | -------------------------------------------------------------------------------- /man/mapOptions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/leaflet.R 3 | \name{mapOptions} 4 | \alias{mapOptions} 5 | \title{Set options on a leaflet map object} 6 | \usage{ 7 | mapOptions(map, zoomToLimits = c("always", "first", "never")) 8 | } 9 | \arguments{ 10 | \item{map}{A map widget object created from \code{\link{leaflet}()}} 11 | 12 | \item{zoomToLimits}{Controls whether the map is zooms to the limits of the 13 | elements on the map. This is useful for interactive applications where the 14 | map data is updated. If \code{"always"} (the default), the map always 15 | re-zooms when new data is received; if \code{"first"}, it zooms to the 16 | elements on the first rendering, but does not re-zoom for subsequent data; 17 | if \code{"never"}, it never re-zooms, not even for the first rendering.} 18 | } 19 | \description{ 20 | Set options on a leaflet map object 21 | } 22 | \examples{ 23 | # Don't auto-zoom to the objects (can be useful in interactive applications) 24 | leaflet() \%>\% 25 | addTiles() \%>\% 26 | addPopups(174.7690922, -36.8523071, 'R was born here!') \%>\% 27 | mapOptions(zoomToLimits = "first") 28 | } 29 | 30 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.markercluster/MIT-LICENCE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2012 David Leaver 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /javascript/src/control-store.js: -------------------------------------------------------------------------------- 1 | export default class ControlStore { 2 | 3 | constructor(map) { 4 | this._controlsNoId = []; 5 | this._controlsById = {}; 6 | this._map = map; 7 | } 8 | 9 | add(control, id, html) { 10 | if (typeof(id) !== "undefined" && id !== null) { 11 | if (this._controlsById[id]) { 12 | this._map.removeControl(this._controlsById[id]); 13 | } 14 | this._controlsById[id] = control; 15 | } else { 16 | this._controlsNoId.push(control); 17 | } 18 | this._map.addControl(control); 19 | } 20 | 21 | remove(id) { 22 | if (this._controlsById[id]) { 23 | let control = this._controlsById[id]; 24 | this._map.removeControl(control); 25 | delete this._controlsById[id]; 26 | } 27 | } 28 | 29 | clear() { 30 | for (let i = 0; i < this._controlsNoId.length; i++) { 31 | let control = this._controlsNoId[i]; 32 | this._map.removeControl(control); 33 | } 34 | this._controlsNoId = []; 35 | 36 | for (let key in this._controlsById) { 37 | let control = this._controlsById[key]; 38 | this._map.removeControl(control); 39 | } 40 | this._controlsById = {}; 41 | } 42 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaflet-r-package", 3 | "version": "0.0.0", 4 | "description": "", 5 | "main": "javascript/src/index.js", 6 | "directories": { 7 | "man": "man", 8 | "test": "tests" 9 | }, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/rstudio/leaflet.git" 16 | }, 17 | "author": "", 18 | "license": "GPL-3.0", 19 | "bugs": { 20 | "url": "https://github.com/rstudio/leaflet/issues" 21 | }, 22 | "homepage": "https://github.com/rstudio/leaflet#readme", 23 | "devDependencies": { 24 | "babel": "^6.5.2", 25 | "babel-preset-es2015": "^6.6.0", 26 | "babel-plugin-transform-es2015-modules-commonjs": "^6.14.0", 27 | "babel-register": "^6.14.0", 28 | "babelify": "^7.3.0", 29 | "browserify": "^13.0.0", 30 | "eslint": "^2.9.0", 31 | "grunt": "^1.0.1", 32 | "grunt-babel": "^6.0.0", 33 | "grunt-browserify": "^5.0.0", 34 | "grunt-contrib-watch": "^1.0.0", 35 | "grunt-eslint": "^18.1.0", 36 | "grunt-mocha-test": "^0.12.7", 37 | "mocha": "^2.4.5", 38 | "source-map-support": "^0.4.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /R/controls.R: -------------------------------------------------------------------------------- 1 | #' @param html the content of the control. May be provided as string or as HTML 2 | #' generated with Shiny/htmltools tags 3 | #' @param position position of control: 'topleft', 'topright', 'bottomleft', or 4 | #' 'bottomright' 5 | #' @param className extra CSS classes to append to the control, space separated 6 | #' 7 | #' @describeIn map-layers Add arbitrary HTML controls to the map 8 | #' @export 9 | addControl <- function( 10 | map, html, position = c('topleft', 'topright', 'bottomleft', 'bottomright'), 11 | layerId = NULL, className = "info legend", data = getMapData(map) 12 | ) { 13 | 14 | position = match.arg(position) 15 | 16 | deps = htmltools::resolveDependencies(htmltools::findDependencies(html)) 17 | html = as.character(html) 18 | 19 | map$dependencies = c(map$dependencies, deps) 20 | invokeMethod(map, data, 'addControl', html, position, layerId, className) 21 | } 22 | 23 | #' @export 24 | #' @rdname remove 25 | removeControl <- function(map, layerId) { 26 | invokeMethod(map, NULL, 'removeControl', layerId) 27 | } 28 | 29 | #' @export 30 | #' @rdname remove 31 | clearControls <- function(map) { 32 | invokeMethod(map, NULL, 'clearControls') 33 | } 34 | 35 | -------------------------------------------------------------------------------- /R/shiny.R: -------------------------------------------------------------------------------- 1 | #' Wrapper functions for using \pkg{leaflet} in \pkg{shiny} 2 | #' 3 | #' Use \code{leafletOutput()} to create a UI element, and \code{renderLeaflet()} 4 | #' to render the map widget. 5 | #' @inheritParams htmlwidgets::shinyWidgetOutput 6 | #' @param width,height the width and height of the map (see 7 | #' \code{\link[htmlwidgets]{shinyWidgetOutput}}) 8 | #' @rdname map-shiny 9 | #' @export 10 | #' @examples # !formatR 11 | #' \donttest{library(leaflet) 12 | #' library(shiny) 13 | #' app = shinyApp( 14 | #' ui = fluidPage(leafletOutput('myMap')), 15 | #' server = function(input, output) { 16 | #' map = leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17) 17 | #' output$myMap = renderLeaflet(map) 18 | #' } 19 | #' ) 20 | #' 21 | #' if (interactive()) print(app)} 22 | leafletOutput <- function(outputId, width = "100%", height = 400) { 23 | htmlwidgets::shinyWidgetOutput(outputId, "leaflet", width, height, "leaflet") 24 | } 25 | 26 | #' @rdname map-shiny 27 | #' @export 28 | renderLeaflet <- function(expr, env = parent.frame(), quoted = FALSE) { 29 | if (!quoted) expr = substitute(expr) # force quoted 30 | htmlwidgets::shinyRenderWidget(expr, leafletOutput, env, quoted = TRUE) 31 | } 32 | -------------------------------------------------------------------------------- /man/addGraticule.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-graticule.R 3 | \name{addGraticule} 4 | \alias{addGraticule} 5 | \title{Add a Graticule on the map 6 | see \url{https://github.com/turban/Leaflet.Graticule}} 7 | \usage{ 8 | addGraticule(map, interval = 20, sphere = FALSE, style = list(color = 9 | "#333", weight = 1), layerId = NULL, group = NULL, 10 | options = pathOptions(pointerEvents = "none", clickable = FALSE)) 11 | } 12 | \arguments{ 13 | \item{map}{a map widget object} 14 | 15 | \item{interval}{The spacing in map units between horizontal and vertical lines.} 16 | 17 | \item{sphere}{boolean. Default FALSE} 18 | 19 | \item{style}{path options for the generated lines. See \url{http://leafletjs.com/reference.html#path-options}} 20 | 21 | \item{layerId}{the layer id} 22 | 23 | \item{group}{the name of the group this layer belongs to.} 24 | 25 | \item{options}{the path options for the graticule layer} 26 | } 27 | \description{ 28 | Add a Graticule on the map 29 | see \url{https://github.com/turban/Leaflet.Graticule} 30 | } 31 | \examples{ 32 | library(leaflet) 33 | 34 | leaf <- leaflet() \%>\% 35 | addTiles() \%>\% 36 | addGraticule() 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /javascript/tests/test-dataframe.js: -------------------------------------------------------------------------------- 1 | import DataFrame from "./dataframe"; 2 | import assert from "assert"; 3 | 4 | describe("DataFrame", () => { 5 | let speed = [4, 4, 7, 7, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 20, 20, 20, 20, 20, 22, 23, 24, 24, 24, 24, 25]; 6 | let dist = [2, 10, 4, 22, 16, 10, 18, 26, 34, 17, 28, 14, 20, 24, 28, 26, 34, 34, 46, 26, 36, 60, 80, 20, 26, 54, 32, 40, 32, 40, 50, 42, 56, 76, 84, 36, 46, 68, 32, 48, 52, 56, 64, 66, 54, 70, 92, 93, 120, 85]; 7 | let df = new DataFrame(); 8 | df.col("speed", speed) 9 | .col("dist", dist) 10 | .col("color", ["yellow", "red"]) 11 | .cbind({ 12 | "Make" : ["Toyota", "Cadillac", "BMW"], 13 | "Model" : ["Corolla", "CTS", "435i"] 14 | }); 15 | 16 | it("can index into rows", () => { 17 | assert.equal(df.get(9, "speed"), 11); 18 | assert.equal(df.get(9, "dist"), 17); 19 | }); 20 | 21 | it("recycles column values", () => { 22 | assert.equal(df.get(9, "color"), "red"); 23 | }); 24 | 25 | it("recycles when cbinding", () => { 26 | assert.equal(df.get(9, "Make"), "Toyota"); 27 | assert.equal(df.get(9, "Model"), "Corolla"); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /R/dependencies.R: -------------------------------------------------------------------------------- 1 | #' Various leaflet dependency functions for use in downstream packages 2 | #' @examples \dontrun{ 3 | #' addBootStrap <- function(map) { 4 | #' map$dependencies <- c(map$dependencies, leafletDependencies$bootstrap()) 5 | #' map 6 | #' } 7 | #' } 8 | #' @export 9 | leafletDependencies <- list( 10 | markerCluster = function() {markerClusterDependencies()}, 11 | awesomeMarkers = function(){leafletAwesomeMarkersDependencies()}, 12 | bootstrap = function(){leafletAmBootstrapDependencies()}, 13 | fontawesome = function(){leafletAmFontAwesomeDependencies()}, 14 | ionicon = function(){leafletAmIonIconDependencies()}, 15 | omnivore = function(){leafletOmnivoreDependencies()}, 16 | # the ones below are not really expected to be used directly 17 | # but are included for completeness sake. 18 | graticule = function(){leafletGraticuleDependencies()}, 19 | simpleGraticule = function(){leafletSimpleGraticuleDependencies()}, 20 | easyButton = function(){leafletEasyButtonDependencies()}, 21 | measure = function(){leafletMeasureDependencies()}, 22 | terminator = function(){leafletTerminatorDependencies()}, 23 | minimap = function(){leafletMiniMapDependencies()}, 24 | providers = function(){leafletProviderDependencies()} 25 | ) 26 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.EasyButton/easy-button.css: -------------------------------------------------------------------------------- 1 | .leaflet-bar button, 2 | .leaflet-bar button:hover { 3 | background-color: #fff; 4 | border: none; 5 | border-bottom: 1px solid #ccc; 6 | width: 26px; 7 | height: 26px; 8 | line-height: 26px; 9 | display: block; 10 | text-align: center; 11 | text-decoration: none; 12 | color: black; 13 | } 14 | 15 | .leaflet-bar button { 16 | background-position: 50% 50%; 17 | background-repeat: no-repeat; 18 | overflow: hidden; 19 | display: block; 20 | } 21 | 22 | .leaflet-bar button:hover { 23 | background-color: #f4f4f4; 24 | } 25 | 26 | .leaflet-bar button:first-of-type { 27 | border-top-left-radius: 4px; 28 | border-top-right-radius: 4px; 29 | } 30 | 31 | .leaflet-bar button:last-of-type { 32 | border-bottom-left-radius: 4px; 33 | border-bottom-right-radius: 4px; 34 | border-bottom: none; 35 | } 36 | 37 | .leaflet-bar.disabled, 38 | .leaflet-bar button.disabled { 39 | cursor: default; 40 | pointer-events: none; 41 | opacity: .4; 42 | } 43 | 44 | .easy-button-button .button-state{ 45 | display: block; 46 | width: 100%; 47 | height: 100%; 48 | position: relative; 49 | } 50 | 51 | 52 | .leaflet-touch .leaflet-bar button { 53 | width: 30px; 54 | height: 30px; 55 | line-height: 30px; 56 | } 57 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-providers/license.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Leaflet Providers contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | _THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE._ -------------------------------------------------------------------------------- /man/addSimpleGraticule.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-simplegraticule.R 3 | \name{addSimpleGraticule} 4 | \alias{addSimpleGraticule} 5 | \title{Add a simple Graticule on the map 6 | see \url{https://github.com/ablakey/Leaflet.SimpleGraticule}} 7 | \usage{ 8 | addSimpleGraticule(map, interval = 20, showOriginLabel = TRUE, 9 | redraw = "move", hidden = FALSE, zoomIntervals = list(), 10 | layerId = NULL, group = NULL) 11 | } 12 | \arguments{ 13 | \item{map}{a map widget object} 14 | 15 | \item{interval}{The spacing in map units between horizontal and vertical lines.} 16 | 17 | \item{showOriginLabel}{true Whether or not to show '(0,0)' at the origin.} 18 | 19 | \item{redraw}{on which map event to redraw the graticule. On move is default but moveend can be smoother.} 20 | 21 | \item{hidden}{hide on start} 22 | 23 | \item{zoomIntervals}{use different intervals in different zoom levels. If not specified, all zoom levels use value in interval option.} 24 | 25 | \item{layerId}{the layer id} 26 | 27 | \item{group}{the name of the group this layer belongs to.} 28 | } 29 | \description{ 30 | Add a simple Graticule on the map 31 | see \url{https://github.com/ablakey/Leaflet.SimpleGraticule} 32 | } 33 | \examples{ 34 | library(leaflet) 35 | 36 | leaflet() \%>\% 37 | addTiles() \%>\% 38 | addSimpleGraticule() 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /man/map-shiny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shiny.R 3 | \name{leafletOutput} 4 | \alias{leafletOutput} 5 | \alias{renderLeaflet} 6 | \title{Wrapper functions for using \pkg{leaflet} in \pkg{shiny}} 7 | \usage{ 8 | leafletOutput(outputId, width = "100\%", height = 400) 9 | 10 | renderLeaflet(expr, env = parent.frame(), quoted = FALSE) 11 | } 12 | \arguments{ 13 | \item{outputId}{output variable to read from} 14 | 15 | \item{width, height}{the width and height of the map (see 16 | \code{\link[htmlwidgets]{shinyWidgetOutput}})} 17 | 18 | \item{expr}{An expression that generates an HTML widget} 19 | 20 | \item{env}{The environment in which to evaluate \code{expr}.} 21 | 22 | \item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This 23 | is useful if you want to save an expression in a variable.} 24 | } 25 | \description{ 26 | Use \code{leafletOutput()} to create a UI element, and \code{renderLeaflet()} 27 | to render the map widget. 28 | } 29 | \examples{ 30 | # !formatR 31 | \donttest{library(leaflet) 32 | library(shiny) 33 | app = shinyApp( 34 | ui = fluidPage(leafletOutput('myMap')), 35 | server = function(input, output) { 36 | map = leaflet() \%>\% addTiles() \%>\% setView(-93.65, 42.0285, zoom = 17) 37 | output$myMap = renderLeaflet(map) 38 | } 39 | ) 40 | 41 | if (interactive()) print(app)} 42 | } 43 | 44 | -------------------------------------------------------------------------------- /inst/legacy/examples/choropleth/ui.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | shinyUI(fluidPage( 4 | 5 | # Add a little CSS to make the map background pure white 6 | tags$head(tags$style(" 7 | #showcase-code-position-toggle, #showcase-sxs-code { display: none; } 8 | .floater { background-color: white; padding: 8px; opacity: 0.7; border-radius: 6px; box-shadow: 0 0 15px rgba(0,0,0,0.2); } 9 | ")), 10 | 11 | leafletMap( 12 | "map", "100%", 500, 13 | # By default OpenStreetMap tiles are used; we want nothing in this case 14 | #initialTileLayer = NULL, 15 | #initialTileLayerAttribution = NULL, 16 | options=list( 17 | center = c(40, -98.85), 18 | zoom = 4, 19 | maxBounds = list(list(17, -180), list(59, 180)) 20 | ) 21 | ), 22 | 23 | absolutePanel( 24 | right = 30, top = 10, width = 200, class = "floater", 25 | 26 | h4("US Population Density"), 27 | uiOutput("stateInfo") 28 | ), 29 | 30 | absolutePanel( 31 | right = 30, top = 280, style = "", class = "floater", 32 | tags$table( 33 | mapply(function(from, to, color) { 34 | tags$tr( 35 | tags$td(tags$div( 36 | style = sprintf("width: 16px; height: 16px; background-color: %s;", color) 37 | )), 38 | tags$td(from, "-", to) 39 | ) 40 | }, densityRanges$from, densityRanges$to, palette, SIMPLIFY=FALSE) 41 | ) 42 | ) 43 | )) 44 | -------------------------------------------------------------------------------- /man/dispatch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{dispatch} 4 | \alias{dispatch} 5 | \alias{invokeMethod} 6 | \title{Extension points for plugins} 7 | \usage{ 8 | dispatch(map, funcName, leaflet = stop(paste(funcName, 9 | "requires a map proxy object")), leaflet_proxy = stop(paste(funcName, 10 | "does not support map proxy objects"))) 11 | 12 | invokeMethod(map, data, method, ...) 13 | } 14 | \arguments{ 15 | \item{map}{a map object, as returned from \code{\link{leaflet}} or 16 | \code{\link{leafletProxy}}} 17 | 18 | \item{funcName}{the name of the function that the user called that caused 19 | this \code{dispatch} call; for error message purposes} 20 | 21 | \item{leaflet}{an action to be performed if the map is from 22 | \code{\link{leaflet}}} 23 | 24 | \item{leaflet_proxy}{an action to be performed if the map is from 25 | \code{\link{leafletProxy}}} 26 | 27 | \item{data}{a data object that will be used when evaluating formulas in 28 | \code{...}} 29 | 30 | \item{method}{the name of the JavaScript method to invoke} 31 | 32 | \item{...}{unnamed arguments to be passed to the JavaScript method} 33 | } 34 | \value{ 35 | \code{dispatch} returns the value of \code{leaflet} or 36 | \code{leaflet_proxy}, or an error. \code{invokeMethod} returns the 37 | \code{map} object that was passed in, possibly modified. 38 | } 39 | \description{ 40 | Extension points for plugins 41 | } 42 | 43 | -------------------------------------------------------------------------------- /inst/examples/emptyData.R: -------------------------------------------------------------------------------- 1 | library(dplyr) 2 | library(leaflet) 3 | library(sp) 4 | 5 | # Markers with empty data 6 | 7 | leaflet(quakes[FALSE,]) %>% addMarkers() 8 | leaflet(quakes[FALSE,]) %>% addAwesomeMarkers() 9 | leaflet(quakes[FALSE,]) %>% addCircleMarkers() 10 | leaflet(quakes[FALSE,]) %>% addCircles() 11 | 12 | # Markers with missing data 13 | # NewYork has missing Long 14 | cities <- read.csv(textConnection(" 15 | City,Lat,Long,Pop 16 | Boston,42.3601,-71.0589,645966 17 | Hartford,41.7627,-72.6743,125017 18 | New York City,40.7127,NA,8406000 19 | Philadelphia,39.9500,-75.1667,1553000 20 | Pittsburgh,40.4397,-79.9764,305841 21 | Providence,41.8236,-71.4222,177994")) 22 | 23 | leaflet(cities) %>% addTiles() %>% addMarkers() 24 | leaflet(cities) %>% addTiles() %>% addAwesomeMarkers() 25 | leaflet(cities) %>% addTiles() %>% addCircleMarkers() 26 | leaflet(cities) %>% addTiles() %>% addCircles(radius = ~sqrt(Pop) * 30) 27 | leaflet(cities) %>% addTiles() %>% addPopups(popup=~as.character(City)) 28 | 29 | # Polylines with empty data 30 | 31 | coords <- matrix(c(1,2,3,4), nrow=2) 32 | line <- Line(coords) 33 | sp_lines <- SpatialLines(list(Lines(list(line), ID=1))) 34 | sp_lines_df <- sp::SpatialLinesDataFrame(sp_lines, data=data.frame(x=1)) 35 | 36 | # This works ok 37 | sp_lines_df %>% leaflet() %>% addPolylines() 38 | 39 | # Subset the data to get SpatialLinesDataFrame without data 40 | sub_df <- sp_lines_df[sp_lines_df$x > 1,] 41 | 42 | sub_df %>% leaflet() %>% addPolylines() 43 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-providers/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaflet-providers", 3 | "version": "1.1.15", 4 | "description": "An extension to Leaflet that contains configurations for various free tile providers.", 5 | "main": "leaflet-providers.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/leaflet-extras/leaflet-providers.git" 9 | }, 10 | "scripts": { 11 | "test": "npm run lint && npm run testsuite", 12 | "testsuite": "mocha-phantomjs tests/index.html", 13 | "lint": "eslint --config .eslintrc leaflet-providers.js index.html preview/*.js preview/*.html tests/*", 14 | "min": "uglifyjs leaflet-providers.js -mc -o leaflet-providers.min.js", 15 | "release": "mversion patch -m" 16 | }, 17 | "license": "BSD-2-Clause", 18 | "bugs": { 19 | "url": "https://github.com/leaflet-extras/leaflet-providers/issues" 20 | }, 21 | "files": [ 22 | "leaflet-providers.js", 23 | "README.md", 24 | "CHANGELOG.md", 25 | "licence.md" 26 | ], 27 | "devDependencies": { 28 | "chai": "^2.3.0", 29 | "eslint": "^2.7.0", 30 | "eslint-plugin-html": "^1.4.0", 31 | "mocha": "^2.2.4", 32 | "mocha-phantomjs": "^3.5.3", 33 | "mversion": "^1.3.0", 34 | "phantomjs": "1.9.7-15", 35 | "uglify-js": "^2.4.15" 36 | }, 37 | "autoupdate": { 38 | "source": "git", 39 | "target": "git://github.com/leaflet-extras/leaflet-providers.git", 40 | "basePath": "/", 41 | "files": [ 42 | "leaflet-providers.js" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /R/plugin-omnivore.R: -------------------------------------------------------------------------------- 1 | leafletOmnivoreDependencies <- function() { 2 | list( 3 | htmltools::htmlDependency( 4 | "leaflet-omnivore", 5 | "0.3.3", 6 | system.file("htmlwidgets/lib/leaflet-omnivore", package = "leaflet"), 7 | script = "leaflet-omnivore.min.js" 8 | ) 9 | ) 10 | } 11 | 12 | 13 | #' @param topojson a TopoJSON list, or character vector of length 1 14 | #' @describeIn map-layers Add TopoJSON layers to the map 15 | #' @export 16 | addTopoJSON <- function(map, topojson, layerId = NULL, group = NULL, 17 | stroke = TRUE, 18 | color = "#03F", 19 | weight = 5, 20 | opacity = 0.5, 21 | fill = TRUE, 22 | fillColor = color, 23 | fillOpacity = 0.2, 24 | dashArray = NULL, 25 | smoothFactor = 1.0, 26 | noClip = FALSE, 27 | options = pathOptions() 28 | ) { 29 | map$dependencies <- c(map$dependencies, leafletOmnivoreDependencies()) 30 | options = c(options, list( 31 | stroke = stroke, color = color, weight = weight, opacity = opacity, 32 | fill = fill, fillColor = fillColor, fillOpacity = fillOpacity, 33 | dashArray = dashArray, smoothFactor = smoothFactor, noClip = noClip 34 | )) 35 | invokeMethod(map, getMapData(map), 'addTopoJSON', topojson, layerId, group, options) 36 | } 37 | 38 | #' @rdname remove 39 | #' @export 40 | removeTopoJSON <- function(map, layerId) { 41 | invokeMethod(map, getMapData(map), 'removeTopoJSON', layerId) 42 | } 43 | 44 | #' @rdname remove 45 | #' @export 46 | clearTopoJSON <- function(map) { 47 | invokeMethod(map, NULL, 'clearTopoJSON') 48 | } 49 | -------------------------------------------------------------------------------- /man/addScaleBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scalebar.R 3 | \name{addScaleBar} 4 | \alias{addScaleBar} 5 | \alias{removeScaleBar} 6 | \alias{scaleBarOptions} 7 | \title{Add or remove a scale bar} 8 | \usage{ 9 | addScaleBar(map, position = c("topright", "bottomright", "bottomleft", 10 | "topleft"), options = scaleBarOptions()) 11 | 12 | scaleBarOptions(maxWidth = 100, metric = TRUE, imperial = TRUE, 13 | updateWhenIdle = TRUE) 14 | 15 | removeScaleBar(map) 16 | } 17 | \arguments{ 18 | \item{map}{the map to add the scale bar to} 19 | 20 | \item{position}{position of control: 'topleft', 'topright', 'bottomleft', or 21 | 'bottomright'} 22 | 23 | \item{options}{a list of additional options, intended to be provided by 24 | a call to \code{scaleBarOptions}} 25 | 26 | \item{maxWidth}{maximum width of the control in pixels (default 100)} 27 | 28 | \item{metric}{if \code{TRUE} (the default), show a scale bar in metric units 29 | (m/km)} 30 | 31 | \item{imperial}{if \code{TRUE} (the default), show a scale bar in imperial 32 | units (ft/mi)} 33 | 34 | \item{updateWhenIdle}{if \code{FALSE} (the default), the scale bar is always 35 | up-to-date (updated on \code{move}). If \code{TRUE}, the control is updated 36 | on \code{moveend}.} 37 | } 38 | \description{ 39 | Uses Leaflet's built-in 40 | \href{http://leafletjs.com/reference.html#control-scale}{scale bar} 41 | feature to add a scale bar. 42 | } 43 | \examples{ 44 | \donttest{ 45 | leaflet() \%>\% 46 | addTiles() \%>\% 47 | addScaleBar() 48 | } 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /R/plugin-graticule.R: -------------------------------------------------------------------------------- 1 | leafletGraticuleDependencies <- function() { 2 | list( 3 | htmltools::htmlDependency( 4 | "leaflet-graticule", 5 | "0.1.0", 6 | system.file("htmlwidgets/plugins/Leaflet.Graticule", package = "leaflet"), 7 | script = c("L.Graticule.js", "Graticule-binding.js") 8 | ) 9 | ) 10 | } 11 | 12 | #' Add a Graticule on the map 13 | #' see \url{https://github.com/turban/Leaflet.Graticule} 14 | #' 15 | #' @param map a map widget object 16 | #' @param interval The spacing in map units between horizontal and vertical lines. 17 | #' @param sphere boolean. Default FALSE 18 | #' @param style path options for the generated lines. See \url{http://leafletjs.com/reference.html#path-options} 19 | #' @param layerId the layer id 20 | #' @param group the name of the group this layer belongs to. 21 | #' @param options the path options for the graticule layer 22 | #' @examples 23 | #' library(leaflet) 24 | #' 25 | #' leaf <- leaflet() %>% 26 | #' addTiles() %>% 27 | #' addGraticule() 28 | #' 29 | #' @export 30 | addGraticule <- function( 31 | map, 32 | interval = 20, 33 | sphere = FALSE, 34 | style = list(color= '#333', weight= 1), 35 | layerId = NULL, 36 | group=NULL, 37 | options = pathOptions(pointerEvents="none", clickable=FALSE) # Default unclickable 38 | ) { 39 | map$dependencies <- c(map$dependencies, leafletGraticuleDependencies()) 40 | invokeMethod( 41 | map, 42 | getMapData(map), 43 | 'addGraticule', 44 | interval, 45 | sphere, 46 | style, 47 | layerId, 48 | group, 49 | options 50 | ) 51 | } 52 | -------------------------------------------------------------------------------- /R/plugin-terminator.R: -------------------------------------------------------------------------------- 1 | leafletTerminatorDependencies <- function() { 2 | list( 3 | htmltools::htmlDependency( 4 | "leaflet-terminator", 5 | "0.1.0", 6 | system.file("htmlwidgets/plugins/Leaflet.Terminator", package = "leaflet"), 7 | script = c("L.Terminator.js", "Terminator-binding.js") 8 | ) 9 | ) 10 | } 11 | 12 | #' Add a daylight layer on top of the map 13 | #' 14 | #' See \url{https://github.com/joergdietrich/Leaflet.Terminator} 15 | #' 16 | #' @param map a map widget object 17 | #' @param resolution the step size at which the terminator points are computed. 18 | #' The step size is 1 degree/resolution, i.e. higher resolution values have 19 | #' smaller step sizes and more points in the polygon. The default value is 2. 20 | #' @param time Time 21 | #' @param layerId the layer id 22 | #' @param group the name of the group this layer belongs to. 23 | #' @param options the path options for the daynight layer 24 | #' @examples 25 | #' library(leaflet) 26 | #' 27 | #' leaf <- leaflet() %>% 28 | #' addTiles() %>% 29 | #' addTerminator() 30 | #' 31 | #' @export 32 | addTerminator <- function( 33 | map, 34 | resolution = 2, 35 | time = NULL, 36 | layerId = NULL, 37 | group=NULL, 38 | options = pathOptions(pointerEvents="none", clickable=FALSE) # Default unclickable 39 | ) { 40 | map$dependencies <- c(map$dependencies, leafletTerminatorDependencies()) 41 | invokeMethod( 42 | map, 43 | getMapData(map), 44 | 'addTerminator', 45 | resolution, 46 | time, 47 | layerId, 48 | group, 49 | options 50 | ) 51 | } 52 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.markercluster/MarkerCluster.Default.css: -------------------------------------------------------------------------------- 1 | .marker-cluster-small { 2 | background-color: rgba(181, 226, 140, 0.6); 3 | } 4 | .marker-cluster-small div { 5 | background-color: rgba(110, 204, 57, 0.6); 6 | } 7 | 8 | .marker-cluster-medium { 9 | background-color: rgba(241, 211, 87, 0.6); 10 | } 11 | .marker-cluster-medium div { 12 | background-color: rgba(240, 194, 12, 0.6); 13 | } 14 | 15 | .marker-cluster-large { 16 | background-color: rgba(253, 156, 115, 0.6); 17 | } 18 | .marker-cluster-large div { 19 | background-color: rgba(241, 128, 23, 0.6); 20 | } 21 | 22 | /* IE 6-8 fallback colors */ 23 | .leaflet-oldie .marker-cluster-small { 24 | background-color: rgb(181, 226, 140); 25 | } 26 | .leaflet-oldie .marker-cluster-small div { 27 | background-color: rgb(110, 204, 57); 28 | } 29 | 30 | .leaflet-oldie .marker-cluster-medium { 31 | background-color: rgb(241, 211, 87); 32 | } 33 | .leaflet-oldie .marker-cluster-medium div { 34 | background-color: rgb(240, 194, 12); 35 | } 36 | 37 | .leaflet-oldie .marker-cluster-large { 38 | background-color: rgb(253, 156, 115); 39 | } 40 | .leaflet-oldie .marker-cluster-large div { 41 | background-color: rgb(241, 128, 23); 42 | } 43 | 44 | .marker-cluster { 45 | background-clip: padding-box; 46 | border-radius: 20px; 47 | } 48 | .marker-cluster div { 49 | width: 30px; 50 | height: 30px; 51 | margin-left: 5px; 52 | margin-top: 5px; 53 | 54 | text-align: center; 55 | border-radius: 15px; 56 | font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif; 57 | } 58 | .marker-cluster span { 59 | line-height: 30px; 60 | } -------------------------------------------------------------------------------- /inst/legacy/examples/population/ui.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | library(ShinyDash) 3 | 4 | shinyUI(fluidPage( 5 | tags$head(tags$link(rel='stylesheet', type='text/css', href='styles.css')), 6 | leafletMap( 7 | "map", "100%", 400, 8 | initialTileLayer = "//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png", 9 | initialTileLayerAttribution = HTML('Maps by Mapbox'), 10 | options=list( 11 | center = c(37.45, -93.85), 12 | zoom = 4, 13 | maxBounds = list(list(17, -180), list(59, 180)) 14 | ) 15 | ), 16 | fluidRow( 17 | column(8, offset=3, 18 | h2('Population of US cities'), 19 | htmlWidgetOutput( 20 | outputId = 'desc', 21 | HTML(paste( 22 | 'The map is centered at , ', 23 | 'with a zoom level of .
', 24 | 'Top out of visible cities are displayed.' 25 | )) 26 | ) 27 | ) 28 | ), 29 | hr(), 30 | fluidRow( 31 | column(3, 32 | selectInput('year', 'Year', c(2000:2010), 2010), 33 | selectInput('maxCities', 'Maximum cities to display', choices=c( 34 | 5, 25, 50, 100, 200, 500, 2000, 5000, 10000, All = 100000 35 | ), selected = 100) 36 | ), 37 | column(4, 38 | h4('Visible cities'), 39 | tableOutput('data') 40 | ), 41 | column(5, 42 | h4(id='cityTimeSeriesLabel', class='shiny-text-output'), 43 | plotOutput('cityTimeSeries', width='100%', height='250px') 44 | ) 45 | ) 46 | )) -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet-MiniMap/Control.MiniMap.min.css: -------------------------------------------------------------------------------- 1 | .leaflet-control-minimap{border:rgba(255,255,255,1) solid;box-shadow:0 1px 5px rgba(0,0,0,.65);border-radius:3px;background:#f8f8f9;transition:all .6s}.leaflet-control-minimap a{background-color:rgba(255,255,255,1);background-repeat:no-repeat;z-index:99999;transition:all .6s}.leaflet-control-minimap a.minimized-bottomright{-webkit-transform:rotate(180deg);transform:rotate(180deg);border-radius:0}.leaflet-control-minimap a.minimized-topleft{-webkit-transform:rotate(0deg);transform:rotate(0deg);border-radius:0}.leaflet-control-minimap a.minimized-bottomleft{-webkit-transform:rotate(270deg);transform:rotate(270deg);border-radius:0}.leaflet-control-minimap a.minimized-topright{-webkit-transform:rotate(90deg);transform:rotate(90deg);border-radius:0}.leaflet-control-minimap-toggle-display{background-image:url(images/toggle.svg);background-size:cover;position:absolute;border-radius:3px 0 0}.leaflet-oldie .leaflet-control-minimap-toggle-display{background-image:url(images/toggle.png)}.leaflet-control-minimap-toggle-display-bottomright{bottom:0;right:0}.leaflet-control-minimap-toggle-display-topleft{top:0;left:0;-webkit-transform:rotate(180deg);transform:rotate(180deg)}.leaflet-control-minimap-toggle-display-bottomleft{bottom:0;left:0;-webkit-transform:rotate(90deg);transform:rotate(90deg)}.leaflet-control-minimap-toggle-display-topright{top:0;right:0;-webkit-transform:rotate(270deg);transform:rotate(270deg)}.leaflet-oldie .leaflet-control-minimap{border:1px solid #999}.leaflet-oldie .leaflet-control-minimap a{background-color:#fff}.leaflet-oldie .leaflet-control-minimap a.minimized{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=2)} -------------------------------------------------------------------------------- /man/addProviderTiles.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-providers.R 3 | \name{addProviderTiles} 4 | \alias{addProviderTiles} 5 | \alias{providerTileOptions} 6 | \title{Add a tile layer from a known map provider} 7 | \usage{ 8 | addProviderTiles(map, provider, layerId = NULL, group = NULL, 9 | options = providerTileOptions()) 10 | 11 | providerTileOptions(errorTileUrl = "", noWrap = FALSE, opacity = NULL, 12 | zIndex = NULL, unloadInvisibleTiles = NULL, updateWhenIdle = NULL, 13 | detectRetina = FALSE, reuseTiles = FALSE, ...) 14 | } 15 | \arguments{ 16 | \item{map}{the map to add the tile layer to} 17 | 18 | \item{provider}{the name of the provider (see 19 | \url{http://leaflet-extras.github.io/leaflet-providers/preview/} and 20 | \url{https://github.com/leaflet-extras/leaflet-providers})} 21 | 22 | \item{layerId}{the layer id to assign} 23 | 24 | \item{group}{the name of the group the newly created layers should belong to 25 | (for \code{\link{clearGroup}} and \code{\link{addLayersControl}} purposes). 26 | Human-friendly group names are permitted--they need not be short, 27 | identifier-style names.} 28 | 29 | \item{options}{tile options} 30 | 31 | \item{errorTileUrl, noWrap, opacity, zIndex, unloadInvisibleTiles, updateWhenIdle, detectRetina, reuseTiles}{the tile layer options; see 32 | \url{http://leafletjs.com/reference.html#tilelayer}} 33 | 34 | \item{...}{named parameters to add to the options} 35 | } 36 | \value{ 37 | modified map object 38 | } 39 | \description{ 40 | Add a tile layer from a known map provider 41 | } 42 | \examples{ 43 | leaflet() \%>\% 44 | addProviderTiles("Stamen.Watercolor") \%>\% 45 | addProviderTiles("Stamen.TonerHybrid") 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /man/makeAwesomeIcon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-awesomeMarkers.R 3 | \name{makeAwesomeIcon} 4 | \alias{makeAwesomeIcon} 5 | \title{Make Awesome Icon} 6 | \usage{ 7 | makeAwesomeIcon(icon = "home", library = "glyphicon", 8 | markerColor = "blue", iconColor = "white", spin = FALSE, 9 | extraClasses = NULL, squareMarker = FALSE, iconRotate = 0, 10 | fontFamily = "monospace", text = NULL) 11 | } 12 | \arguments{ 13 | \item{icon}{Name of the icon} 14 | 15 | \item{library}{Which icon library. Default \code{'glyphicon'}, other possible 16 | values are \code{'fa'} (fontawesome) or \code{'ion'} (ionicons).} 17 | 18 | \item{markerColor}{Possible values are \code{'red'}, \code{'darkred'}, \code{'lightred'}, \code{'orange'}, 19 | \code{'beige'}, \code{'green'}, \code{'darkgreen'}, \code{'lightgreen'}, \code{'blue'}, 20 | \code{'darkblue'}, \code{'lightblue'}, \code{'purple'}, \code{'darkpurple'}, \code{'pink'}, 21 | \code{'cadetblue'}, \code{'white'}, \code{'gray'}, \code{'lightgray'}, \code{'black'}} 22 | 23 | \item{iconColor}{The color to use for the icon itself. Use any CSS-valid 24 | color (hex, rgba, etc.) or a named web color.} 25 | 26 | \item{spin}{If \code{TRUE}, make the icon spin (only works when \code{library 27 | = 'fa'})} 28 | 29 | \item{extraClasses}{Additional css classes to include on the icon.} 30 | 31 | \item{squareMarker}{Whether to use a sqare marker.} 32 | 33 | \item{iconRotate}{Rotate the icon by a given angle.} 34 | 35 | \item{fontFamily}{Used when \code{text} option is specified.} 36 | 37 | \item{text}{Use this text string instead of an icon. 38 | argument of \code{\link{addAwesomeMarkers}()}.} 39 | } 40 | \description{ 41 | Make Awesome Icon 42 | } 43 | 44 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet-MiniMap/Minimap-binding.js: -------------------------------------------------------------------------------- 1 | LeafletWidget.methods.addMiniMap = 2 | function(tilesURL, tilesProvider, position, 3 | width, height, collapsedWidth, collapsedHeight , zoomLevelOffset, 4 | zoomLevelFixed, centerFixed, zoomAnimation , toggleDisplay, autoToggleDisplay, 5 | minimized, aimingRectOptions, shadowRectOptions, strings, mapOptions) { 6 | 7 | (function() { 8 | if(this.minimap) { 9 | this.minimap.removeFrom( this ); 10 | } 11 | 12 | // determin the tiles for the minimap 13 | // default to OSM tiles 14 | layer = new L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'); 15 | if(tilesProvider) { 16 | // use a custom tiles provider if specified. 17 | layer = new L.tileLayer.provider(tilesProvider); 18 | } else if(tilesURL) { 19 | // else use a custom tiles URL if specified. 20 | layer = new L.tileLayer(tilesURL); 21 | } 22 | 23 | this.minimap = new L.Control.MiniMap(layer, { 24 | position: position, 25 | width: width, 26 | height: height, 27 | collapsedWidth: collapsedWidth, 28 | collapsedHeight: collapsedWidth, 29 | zoomLevelOffset: zoomLevelOffset, 30 | zoomLevelFixed: zoomLevelFixed, 31 | centerFixed: centerFixed, 32 | zoomAnimation: zoomAnimation, 33 | toggleDisplay: toggleDisplay, 34 | autoToggleDisplay: autoToggleDisplay, 35 | minimized: minimized, 36 | aimingRectOptions: aimingRectOptions, 37 | shadowRectOptions: shadowRectOptions, 38 | strings: strings, 39 | mapOptions: mapOptions 40 | }); 41 | this.minimap.addTo(this); 42 | }).call(this); 43 | }; 44 | -------------------------------------------------------------------------------- /inst/examples/geojson.R: -------------------------------------------------------------------------------- 1 | 2 | library(leaflet) 3 | library(sp) 4 | #'

5 | #' The V8 part is simply to read the JSON embeded in the Javascript.
6 | #' For a geojson file `jsonlite::fromfromJSON()` or `geojsonio::regeojson_read()` will do 7 | #' 8 | jsURL <- 'https://rawgit.com/Norkart/Leaflet-MiniMap/master/example/local_pubs_restaurant_norway.js' 9 | v8 <- V8::v8() 10 | v8$source(jsURL) 11 | geoJson <- geojsonio::as.json(v8$get('pubsGeoJSON')) 12 | 13 | # This is the kicker, convert geojson to a Spatial object. 14 | # This then allows us to use formulas in our markers, polygons etc. 15 | spdf <- geojsonio::geojson_sp(geoJson) 16 | 17 | icons <- awesomeIconList( 18 | pub = makeAwesomeIcon(icon='glass', library='fa', markerColor = 'red'), 19 | restaurant = makeAwesomeIcon(icon='cutlery', library='fa', markerColor = 'blue') 20 | ) 21 | 22 | leaflet() %>% addTiles() %>% 23 | setView(10.758276373601069, 59.92448055859924, 13) %>% 24 | addAwesomeMarkers(data=spdf, 25 | label=~stringr::str_c(amenity,': ', name), 26 | icon = ~icons[amenity], 27 | options = markerOptions(riseOnHover = TRUE, opacity = 0.75), 28 | group = 'pubs') 29 | 30 | 31 | #'

32 | #' Another examples this time with polygons 33 | url <- 'http://www.partners-popdev.org/wp-content/themes/original-child/vendor/Geojson/States/Maharashtra.geojson' 34 | 35 | mhSPDF <- geojsonio::geojson_read(url, what="sp") 36 | 37 | cols <- colorFactor(topo.colors(nrow(mhSPDF)),mhSPDF$NAME_2) 38 | 39 | leaflet() %>% addProviderTiles(providers$Stamen.TonerLite) %>% 40 | setView(75.7139, 19.7515, 6) %>% 41 | addPolygons(data=mhSPDF, opacity = 5, 42 | label=~NAME_2, weight = 1, 43 | fillColor = ~cols(NAME_2)) 44 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet-MiniMap/images/toggle.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /R/scalebar.R: -------------------------------------------------------------------------------- 1 | #' Add or remove a scale bar 2 | #' 3 | #' Uses Leaflet's built-in 4 | #' \href{http://leafletjs.com/reference.html#control-scale}{scale bar} 5 | #' feature to add a scale bar. 6 | #' 7 | #' @param map the map to add the scale bar to 8 | #' @param position position of control: 'topleft', 'topright', 'bottomleft', or 9 | #' 'bottomright' 10 | #' @param options a list of additional options, intended to be provided by 11 | #' a call to \code{scaleBarOptions} 12 | #' 13 | #' @examples 14 | #' \donttest{ 15 | #' leaflet() %>% 16 | #' addTiles() %>% 17 | #' addScaleBar() 18 | #' } 19 | #' 20 | #' @export 21 | addScaleBar <- function(map, 22 | position = c('topright', 'bottomright', 'bottomleft', 'topleft'), 23 | options = scaleBarOptions()) { 24 | 25 | options = c(options, list(position = match.arg(position))) 26 | invokeMethod(map, getMapData(map), 'addScaleBar', options) 27 | } 28 | 29 | #' @rdname addScaleBar 30 | #' @param maxWidth maximum width of the control in pixels (default 100) 31 | #' @param metric if \code{TRUE} (the default), show a scale bar in metric units 32 | #' (m/km) 33 | #' @param imperial if \code{TRUE} (the default), show a scale bar in imperial 34 | #' units (ft/mi) 35 | #' @param updateWhenIdle if \code{FALSE} (the default), the scale bar is always 36 | #' up-to-date (updated on \code{move}). If \code{TRUE}, the control is updated 37 | #' on \code{moveend}. 38 | #' @export 39 | scaleBarOptions <- function(maxWidth = 100, metric = TRUE, imperial = TRUE, 40 | updateWhenIdle = TRUE) { 41 | list(maxWidth=maxWidth, metric=metric, imperial=imperial, 42 | updateWhenIdle=updateWhenIdle) 43 | } 44 | 45 | #' @rdname addScaleBar 46 | #' @export 47 | removeScaleBar <- function(map) { 48 | invokeMethod(map, NULL, 'removeScaleBar') 49 | } 50 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-omnivore/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "leaflet-omnivore", 3 | "version": "0.3.2", 4 | "description": "a geospatial format parser for Leaflet", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "zuul --local -- test/test.js", 8 | "test-remote": "zuul -- test/test.js", 9 | "test-headless": "zuul --phantom -- test/test.js", 10 | "build": "browserify -s omnivore index.js > leaflet-omnivore.js && uglifyjs leaflet-omnivore.js -c -m > leaflet-omnivore.min.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git@github.com:mapbox/leaflet-omnivore.git" 15 | }, 16 | "browserify": { 17 | "transform": [ 18 | "brfs" 19 | ] 20 | }, 21 | "keywords": [ 22 | "leaflet", 23 | "formats", 24 | "kml", 25 | "csv", 26 | "gpx", 27 | "geojson", 28 | "kml", 29 | "leaflet", 30 | "maps", 31 | "gpx", 32 | "wkt", 33 | "osm", 34 | "polyline", 35 | "topojson", 36 | "format", 37 | "converter" 38 | ], 39 | "author": "Tom MacWright", 40 | "license": "BSD-3-Clause", 41 | "bugs": { 42 | "url": "https://github.com/mapbox/leaflet-omnivore/issues" 43 | }, 44 | "homepage": "https://github.com/mapbox/leaflet-omnivore", 45 | "dependencies": { 46 | "csv2geojson": "~5.0.0", 47 | "togeojson": "0.13.0", 48 | "corslite": "0.0.7", 49 | "wellknown": "0.4.2", 50 | "brfs": "1.4.3", 51 | "topojson": "1.6.26", 52 | "polyline": "0.2.0" 53 | }, 54 | "devDependencies": { 55 | "browserify": "13.0.1", 56 | "tape": "4.5.1", 57 | "uglify-js": "^2.6.2", 58 | "jshint": "2.9.2", 59 | "mocha": "~2.5.3", 60 | "zuul": "~3.10.1", 61 | "st": "1.1.0", 62 | "mapbox.js": "2.4.0", 63 | "phantomjs-prebuilt": "2.1.7" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /inst/examples/providers.R: -------------------------------------------------------------------------------- 1 | #' Now that there is a providers list 2 | #' You can programmatically add providers.
3 | #' Here I show how to add all 'ESRI' provided basemaps. 4 | #' Checkout the `providers` list for all available providers.
5 | #'
6 | library(leaflet) 7 | 8 | m <- leaflet() %>% setView(0,0,1) 9 | 10 | # Take out ESRI provided tiles 11 | esri <- providers %>% 12 | purrr::keep(~ grepl('^Esri',.)) 13 | 14 | esri %>% 15 | purrr::walk(function(x) m <<- m %>% addProviderTiles(x,group=x)) 16 | 17 | m %>% 18 | addLayersControl( 19 | baseGroups = names(esri), 20 | options = layersControlOptions(collapsed = TRUE) 21 | ) 22 | 23 | #'



24 | #' providers with options 25 | #' Change the accessToken with your mapbox token in options below 26 | #' The one here may not work always 27 | mapbox.tileIds <- list(Satellite='mapbox.satellite', 28 | Terrian='mapbox.mapbox-terrain-v2', 29 | Comic='bhaskarvk.1cm89o4e', 30 | 'High Contrast'='bhaskarvk.1biainl5') 31 | 32 | m <- leaflet() %>% setView(0,0,1) 33 | 34 | names(mapbox.tileIds) %>% 35 | purrr::walk(function(x) { 36 | m <<- m %>% 37 | addProviderTiles(providers$MapBox, group = x, 38 | options = providerTileOptions( 39 | detectRetina = TRUE, 40 | # id and accessToken are Mapbox specific options 41 | id = mapbox.tileIds[[x]] , 42 | accessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN') 43 | )) 44 | }) 45 | 46 | m %>% 47 | addLayersControl( 48 | baseGroups = names(mapbox.tileIds), 49 | options = layersControlOptions(collapsed = FALSE) 50 | ) 51 | -------------------------------------------------------------------------------- /R/plugin-simplegraticule.R: -------------------------------------------------------------------------------- 1 | leafletSimpleGraticuleDependencies <- function() { 2 | list( 3 | htmltools::htmlDependency( 4 | "leaflet-simplegraticule", 5 | "0.1.0", 6 | system.file("htmlwidgets/plugins/Leaflet.SimpleGraticule", package = "leaflet"), 7 | script = c("L.SimpleGraticule.js", "SimpleGraticule-binding.js"), 8 | stylesheet = "L.SimpleGraticule.css" 9 | ) 10 | ) 11 | } 12 | 13 | #' Add a simple Graticule on the map 14 | #' see \url{https://github.com/ablakey/Leaflet.SimpleGraticule} 15 | #' 16 | #' @param map a map widget object 17 | #' @param interval The spacing in map units between horizontal and vertical lines. 18 | #' @param showOriginLabel true Whether or not to show '(0,0)' at the origin. 19 | #' @param redraw on which map event to redraw the graticule. On move is default but moveend can be smoother. 20 | #' @param hidden hide on start 21 | #' @param zoomIntervals use different intervals in different zoom levels. If not specified, all zoom levels use value in interval option. 22 | 23 | #' @param layerId the layer id 24 | #' @param group the name of the group this layer belongs to. 25 | #' @examples 26 | #' library(leaflet) 27 | #' 28 | #' leaflet() %>% 29 | #' addTiles() %>% 30 | #' addSimpleGraticule() 31 | #' 32 | #' @export 33 | addSimpleGraticule <- function( 34 | map, 35 | interval = 20, 36 | showOriginLabel = TRUE, 37 | redraw = 'move', 38 | hidden = FALSE, 39 | zoomIntervals = list(), 40 | layerId = NULL, 41 | group=NULL 42 | ) { 43 | map$dependencies <- c(map$dependencies, leafletSimpleGraticuleDependencies()) 44 | invokeMethod( 45 | map 46 | , getMapData(map) 47 | , 'addSimpleGraticule' 48 | , interval 49 | , showOriginLabel 50 | , redraw 51 | , hidden 52 | , zoomIntervals 53 | , layerId 54 | , group 55 | ) 56 | } 57 | -------------------------------------------------------------------------------- /man/map-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \name{setView} 4 | \alias{clearBounds} 5 | \alias{fitBounds} 6 | \alias{setMaxBounds} 7 | \alias{setView} 8 | \title{Methods to manipulate the map widget} 9 | \usage{ 10 | setView(map, lng, lat, zoom, options = list()) 11 | 12 | fitBounds(map, lng1, lat1, lng2, lat2) 13 | 14 | setMaxBounds(map, lng1, lat1, lng2, lat2) 15 | 16 | clearBounds(map) 17 | } 18 | \arguments{ 19 | \item{map}{a map widget object created from \code{\link{leaflet}()}} 20 | 21 | \item{lng}{The longitude of the map center} 22 | 23 | \item{lat}{The latitude of the map center} 24 | 25 | \item{zoom}{the zoom level} 26 | 27 | \item{options}{a list of zoom/pan options (see 28 | \url{http://leafletjs.com/reference.html#map-zoompanoptions})} 29 | 30 | \item{lng1, lat1, lng2, lat2}{the coordinates of the map bounds} 31 | } 32 | \value{ 33 | The modified map widget. 34 | } 35 | \description{ 36 | A series of methods to manipulate the map. 37 | } 38 | \section{Functions}{ 39 | \itemize{ 40 | \item \code{setView}: Set the view of the map (center and zoom level) 41 | 42 | \item \code{fitBounds}: Set the bounds of a map 43 | 44 | \item \code{setMaxBounds}: Restricts the map view to the given bounds 45 | 46 | \item \code{clearBounds}: Clear the bounds of a map, and the bounds will be 47 | automatically determined from latitudes and longitudes of the map elements 48 | if available (otherwise the full world view is used) 49 | }} 50 | \examples{ 51 | library(leaflet) 52 | m = leaflet() \%>\% addTiles() \%>\% setView(-71.0382679, 42.3489054, zoom = 18) 53 | m # the RStudio 'headquarter' 54 | m \%>\% fitBounds(-72, 40, -70, 43) 55 | m \%>\% clearBounds() # world view 56 | } 57 | \references{ 58 | \url{http://leafletjs.com/reference.html#map-set-methods} 59 | } 60 | 61 | -------------------------------------------------------------------------------- /javascript/src/crs_utils.js: -------------------------------------------------------------------------------- 1 | import L from "./global/leaflet"; 2 | import Proj4Leaflet from "./global/proj4leaflet"; 3 | 4 | // Helper function to instanciate a ICRS instance. 5 | export function getCRS(crsOptions) { 6 | let crs = L.CRS.EPSG3857; // Default Spherical Mercator 7 | 8 | switch(crsOptions.crsClass) { 9 | case "L.CRS.EPSG3857": 10 | crs = L.CRS.EPSG3857; 11 | break; 12 | case "L.CRS.EPSG4326": 13 | crs = L.CRS.EPSG4326; 14 | break; 15 | case "L.CRS.EPSG3395": 16 | crs = L.CRS.EPSG3395; 17 | break; 18 | case "L.CRS.Simple": 19 | crs =L.CRS.Simple; 20 | break; 21 | case "L.Proj.CRS": 22 | if(crsOptions.options && crsOptions.options.bounds) { 23 | crsOptions.options.bounds = L.bounds(crsOptions.options.bounds); 24 | } 25 | if(crsOptions.options && crsOptions.options.transformation) { 26 | crsOptions.options.transformation = 27 | L.Transformation( 28 | crsOptions.options.transformation[0], 29 | crsOptions.options.transformation[1], 30 | crsOptions.options.transformation[2], 31 | crsOptions.options.transformation[3] 32 | ); 33 | } 34 | crs = new Proj4Leaflet.CRS(crsOptions.code, crsOptions.proj4def, 35 | crsOptions.options); 36 | break; 37 | case "L.Proj.CRS.TMS": 38 | if(crsOptions.options && crsOptions.options.bounds) { 39 | crsOptions.options.bounds = L.bounds(crsOptions.options.bounds); 40 | } 41 | if(crsOptions.options && crsOptions.options.transformation) { 42 | crsOptions.options.transformation = 43 | L.Transformation( 44 | crsOptions.options.transformation[0], 45 | crsOptions.options.transformation[1], 46 | crsOptions.options.transformation[2], 47 | crsOptions.options.transformation[3] 48 | ); 49 | } 50 | crs = new Proj4Leaflet.CRS.TMS(crsOptions.code, crsOptions.proj4def, 51 | crsOptions.projectedBounds, crsOptions.options); 52 | break; 53 | } 54 | return crs; 55 | } 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # An R Interface to Leaflet Maps 2 | 3 | [![Build Status](https://travis-ci.org/rstudio/leaflet.svg)](https://travis-ci.org/rstudio/leaflet) 4 | 5 | [Leaflet](http://leafletjs.com) is an open-source JavaScript library for 6 | interactive maps. This R package makes it easy to create Leaflet maps from R. 7 | 8 | ```r 9 | library(leaflet) 10 | m = leaflet() %>% addTiles() 11 | m # a map with the default OSM tile layer 12 | 13 | m = m %>% setView(-93.65, 42.0285, zoom = 17) 14 | m 15 | 16 | m %>% addPopups(-93.65, 42.0285, 'Here is the Department of Statistics, ISU') 17 | ``` 18 | 19 | ## Installation 20 | 21 | You can install this package from CRAN, or the development version from Github: 22 | 23 | ```r 24 | # CRAN version 25 | install.packages('leaflet') 26 | 27 | # Or Github version 28 | if (!require('devtools')) install.packages('devtools') 29 | devtools::install_github('rstudio/leaflet') 30 | ``` 31 | 32 | ## Documentation 33 | 34 | In addition to the usual R package documentation, we also have extensive docs and examples at: 35 | http://rstudio.github.io/leaflet You may use [Github issues](https://github.com/rstudio/leaflet/issues) to file bug reports or feature requests, and ask questions on [StackOverflow](http://stackoverflow.com/questions/tagged/r+leaflet) or in the [Shiny mailing list](https://groups.google.com/forum/#!forum/shiny-discuss). 36 | 37 | ## Development 38 | 39 | To make additions or modifications to the JavaScript htmlwidgets binding layer, 40 | you must use Grunt to build and test. Please make sure Node.js is installed on 41 | your system, then run: 42 | 43 | ``` 44 | npm install -g grunt-cli 45 | npm install 46 | ``` 47 | 48 | Now you can build/minify/lint/test using `grunt build`, or run in "watch" mode 49 | by just running `grunt`. JS sources go into `javascript/src` and tests go into 50 | `javascript/tests`. 51 | 52 | ## License 53 | 54 | This package is licensed to you under the terms of the [GNU General Public 55 | License](http://www.gnu.org/licenses/gpl.html) version 3 or later. 56 | 57 | Copyright 2013-2015 RStudio, Inc. 58 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/leaflet-locationfilter/locationfilter-bindings.js: -------------------------------------------------------------------------------- 1 | /* global LeafletWidget, L, Shiny, HTMLWidgets, $ */ 2 | 3 | function getLocationFilterBounds(locationFilter) { 4 | if(locationFilter && locationFilter.getBounds) { 5 | var bounds = locationFilter.getBounds(); 6 | var boundsJSON = 7 | { 8 | "sw_lat" : bounds.getSouth(), 9 | "sw_lng" : bounds.getWest(), 10 | "ne_lat" : bounds.getNorth(), 11 | "ne_lng" : bounds.getEast() 12 | }; 13 | return boundsJSON; 14 | } else { 15 | return null; 16 | } 17 | } 18 | 19 | LeafletWidget.methods.addLocationFilter = function(options) { 20 | (function() { 21 | var map = this; 22 | 23 | if(map.locationFilter) { 24 | map.locationFilter.remove(); 25 | map.locationFilter = null; 26 | } 27 | 28 | if(!$.isEmptyObject(options.bounds)) { 29 | options.bounds = L.latLngBounds(options.bounds); 30 | } 31 | 32 | map.locationFilter = new L.LocationFilter(options); 33 | 34 | map.locationFilter.on("change", function(e) { 35 | if (!HTMLWidgets.shinyMode) return; 36 | Shiny.onInputChange(map.id+"_location_filter_changed", 37 | getLocationFilterBounds(map.locationFilter)); 38 | }); 39 | map.locationFilter.on("enabled", function(e) { 40 | if (!HTMLWidgets.shinyMode) return; 41 | Shiny.onInputChange(map.id+"_location_filter_enabled", 42 | getLocationFilterBounds(map.locationFilter)); 43 | }); 44 | map.locationFilter.on("disabled", function(e) { 45 | if (!HTMLWidgets.shinyMode) return; 46 | Shiny.onInputChange(map.id+"_location_filter_disabled", 47 | getLocationFilterBounds(map.locationFilter)); 48 | }); 49 | 50 | map.locationFilter.addTo(map); 51 | 52 | }).call(this); 53 | }; 54 | 55 | LeafletWidget.methods.removeLocationFilter = function() { 56 | (function() { 57 | var map = this; 58 | 59 | if(map.locationFilter) { 60 | map.locationFilter.remove(); 61 | map.locationFilter = null; 62 | } 63 | 64 | }).call(this); 65 | }; 66 | 67 | -------------------------------------------------------------------------------- /inst/examples/shiny.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(leaflet) 3 | 4 | geodata <- paste(readLines(system.file("examples/test.json", package = "leaflet")), collapse = "\n") 5 | 6 | ui <- fluidPage( 7 | leafletOutput("map1"), 8 | checkboxInput("addMarker", "Add marker on click"), 9 | actionButton("clearMarkers", "Clear all markers"), 10 | textOutput("message", container = h3) 11 | ) 12 | 13 | server <- function(input, output, session) { 14 | v <- reactiveValues(msg = "") 15 | 16 | output$map1 <- renderLeaflet({ 17 | leaflet() %>% 18 | addGeoJSON(geodata) %>% 19 | addCircles(-60, 60, radius = 5e5, layerId = "circle") %>% 20 | fitBounds(-87.1875, 71.4131, 128.3203, 0.3515) 21 | }) 22 | 23 | observeEvent(input$map1_geojson_mouseover, { 24 | v$msg <- paste("Mouse is over", input$map1_geojson_mouseover$featureId) 25 | }) 26 | observeEvent(input$map1_geojson_mouseout, { 27 | v$msg <- "" 28 | }) 29 | observeEvent(input$map1_geojson_click, { 30 | v$msg <- paste("Clicked on", input$map1_geojson_click$featureId) 31 | }) 32 | observeEvent(input$map1_shape_mouseover, { 33 | v$msg <- paste("Mouse is over shape", input$map1_shape_mouseover$id) 34 | }) 35 | observeEvent(input$map1_shape_mouseout, { 36 | v$msg <- "" 37 | }) 38 | observeEvent(input$map1_shape_click, { 39 | v$msg <- paste("Clicked shape", input$map1_shape_click$id) 40 | }) 41 | observeEvent(input$map1_click, { 42 | v$msg <- paste("Clicked map at", input$map1_click$lat, "/", input$map1_click$lng) 43 | if (input$addMarker) { 44 | leafletProxy("map1") %>% 45 | addMarkers(lng = input$map1_click$lng, lat = input$map1_click$lat) 46 | } 47 | }) 48 | observeEvent(input$map1_zoom, { 49 | v$msg <- paste("Zoom changed to", input$map1_zoom) 50 | }) 51 | observeEvent(input$map1_bounds, { 52 | v$msg <- paste("Bounds changed to", paste(input$map1_bounds, collapse = ", ")) 53 | }) 54 | observeEvent(input$clearMarkers, { 55 | leafletProxy("map1") %>% clearMarkers() 56 | }) 57 | 58 | output$message <- renderText(v$msg) 59 | } 60 | 61 | shinyApp(ui, server) 62 | -------------------------------------------------------------------------------- /man/awesomeIcons.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-awesomeMarkers.R 3 | \name{awesomeIcons} 4 | \alias{awesomeIcons} 5 | \title{Create a list of awesome icon data see 6 | \url{https://github.com/lvoogdt/Leaflet.awesome-markers}} 7 | \usage{ 8 | awesomeIcons(icon = "home", library = "glyphicon", markerColor = "blue", 9 | iconColor = "white", spin = FALSE, extraClasses = NULL, 10 | squareMarker = FALSE, iconRotate = 0, fontFamily = "monospace", 11 | text = NULL) 12 | } 13 | \arguments{ 14 | \item{icon}{Name of the icon} 15 | 16 | \item{library}{Which icon library. Default \code{'glyphicon'}, other possible 17 | values are \code{'fa'} (fontawesome) or \code{'ion'} (ionicons).} 18 | 19 | \item{markerColor}{Possible values are \code{'red'}, \code{'darkred'}, \code{'lightred'}, \code{'orange'}, 20 | \code{'beige'}, \code{'green'}, \code{'darkgreen'}, \code{'lightgreen'}, \code{'blue'}, 21 | \code{'darkblue'}, \code{'lightblue'}, \code{'purple'}, \code{'darkpurple'}, \code{'pink'}, 22 | \code{'cadetblue'}, \code{'white'}, \code{'gray'}, \code{'lightgray'}, \code{'black'}} 23 | 24 | \item{iconColor}{The color to use for the icon itself. Use any CSS-valid 25 | color (hex, rgba, etc.) or a named web color.} 26 | 27 | \item{spin}{If \code{TRUE}, make the icon spin (only works when \code{library 28 | = 'fa'})} 29 | 30 | \item{extraClasses}{Additional css classes to include on the icon.} 31 | 32 | \item{squareMarker}{Whether to use a sqare marker.} 33 | 34 | \item{iconRotate}{Rotate the icon by a given angle.} 35 | 36 | \item{fontFamily}{Used when \code{text} option is specified.} 37 | 38 | \item{text}{Use this text string instead of an icon. 39 | argument of \code{\link{addAwesomeMarkers}()}.} 40 | } 41 | \value{ 42 | A list of awesome-icon data that can be passed to the \code{icon} 43 | } 44 | \description{ 45 | An icon can be represented as a list of the form \code{list(icon, library, 46 | ...)}. This function is vectorized over its arguments to create a list of 47 | icon data. Shorter argument values will be re-cycled. \code{NULL} values for 48 | these arguments will be ignored. 49 | } 50 | 51 | -------------------------------------------------------------------------------- /inst/examples/easyButton.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | #' Add two easy buttons. 4 | #' first to set zoom level to 1, 5 | #' second to find your self 6 | leaflet() %>% addTiles() %>% 7 | addEasyButton(easyButton( 8 | icon='fa-globe', title='Zoom to Level 1', 9 | onClick=JS("function(btn, map){ map.setZoom(1);}"))) %>% 10 | addEasyButton(easyButton( 11 | icon='fa-crosshairs', title='Locate Me', 12 | onClick=JS("function(btn, map){ map.locate({setView: true});}"))) 13 | 14 | #'

Toggle Button to freeze/unfreeze clustering at a zoom level. 15 | leaflet() %>% addTiles() %>% 16 | addMarkers(data=quakes, 17 | clusterOptions = markerClusterOptions(), 18 | clusterId = 'quakesCluster') %>% 19 | addEasyButton(easyButton( 20 | states = list( 21 | easyButtonState( 22 | stateName='unfrozen-markers', 23 | icon='ion-toggle', 24 | title='Freeze Clusters', 25 | onClick = JS(" 26 | function(btn, map) { 27 | var clusterManager = 28 | map.layerManager.getLayer('cluster', 29 | 'quakesCluster'); 30 | clusterManager.freezeAtZoom(); 31 | btn.state('frozen-markers'); 32 | }") 33 | ), 34 | easyButtonState( 35 | stateName='frozen-markers', 36 | icon='ion-toggle-filled', 37 | title='UnFreeze Clusters', 38 | onClick = JS(" 39 | function(btn, map) { 40 | var clusterManager = 41 | map.layerManager.getLayer('cluster', 42 | 'quakesCluster'); 43 | clusterManager.unfreeze(); 44 | btn.state('unfrozen-markers'); 45 | }") 46 | ) 47 | ) 48 | )) 49 | 50 | #'

Add two easy buttons in a bar 51 | #' first to set zoom level to 1 52 | #' second to find your self 53 | leaflet() %>% addTiles() %>% 54 | addEasyButtonBar( 55 | easyButton( 56 | icon='fa-globe', title='Zoom to Level 1', 57 | onClick=JS("function(btn, map){ map.setZoom(1);}")), 58 | easyButton( 59 | icon='fa-crosshairs', title='Locate Me', 60 | onClick=JS("function(btn, map){ map.locate({setView: true});}")) 61 | ) 62 | -------------------------------------------------------------------------------- /inst/legacy/examples/choropleth/global.R: -------------------------------------------------------------------------------- 1 | density = c( 2 | "Alabama" = 94.65, 3 | "Arizona" = 57.05, 4 | "Arkansas" = 56.43, 5 | "California" = 241.7, 6 | "Colorado" = 49.33, 7 | "Connecticut" = 739.1, 8 | "Delaware" = 464.3, 9 | "District of Columbia" = 10065, 10 | "Florida" = 353.4, 11 | "Georgia" = 169.5, 12 | "Idaho" = 19.15, 13 | "Illinois" = 231.5, 14 | "Indiana" = 181.7, 15 | "Iowa" = 54.81, 16 | "Kansas" = 35.09, 17 | "Kentucky" = 110, 18 | "Louisiana" = 105, 19 | "Maine" = 43.04, 20 | "Maryland" = 596.3, 21 | "Massachusetts" = 840.2, 22 | "Michigan" = 173.9, 23 | "Minnesota" = 67.14, 24 | "Mississippi" = 63.50, 25 | "Missouri" = 87.26, 26 | "Montana" = 6.858, 27 | "Nebraska" = 23.97, 28 | "Nevada" = 24.80, 29 | "New Hampshire" = 147, 30 | "New Jersey" = 1189 , 31 | "New Mexico" = 17.16, 32 | "New York" = 412.3, 33 | "North Carolina" = 198.2, 34 | "North Dakota" = 9.916, 35 | "Ohio" = 281.9, 36 | "Oklahoma" = 55.22, 37 | "Oregon" = 40.33, 38 | "Pennsylvania" = 284.3, 39 | "Rhode Island" = 1006 , 40 | "South Carolina" = 155.4, 41 | "South Dakota" = 98.07, 42 | "Tennessee" = 88.08, 43 | "Texas" = 98.07, 44 | "Utah" = 34.30, 45 | "Vermont" = 67.73, 46 | "Virginia" = 204.5, 47 | "Washington" = 102.6, 48 | "West Virginia" = 77.06, 49 | "Wisconsin" = 105.2, 50 | "Wyoming" = 5.851 51 | ) 52 | 53 | # Breaks we'll use for coloring 54 | densityBreaks <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf) 55 | # Construct break ranges for displaying in the legend 56 | densityRanges <- data.frame( 57 | from = head(densityBreaks, length(densityBreaks)-1), 58 | to = tail(densityBreaks, length(densityBreaks)-1) 59 | ) 60 | 61 | # Eight colors for eight buckets 62 | palette <- c("#FFEDA0", "#FED976", "#FEB24C", "#FD8D3C", 63 | "#FC4E2A", "#E31A1C", "#BD0026", "#800026") 64 | # Assign colors to states 65 | colors <- structure( 66 | palette[cut(density, densityBreaks)], 67 | names = tolower(names(density)) 68 | ) 69 | 70 | # The state names that come back from the maps package's state database has 71 | # state:qualifier format. This function strips off the qualifier. 72 | getStateName <- function(id) { 73 | strsplit(id, ":")[[1]][1] 74 | } 75 | -------------------------------------------------------------------------------- /man/makeIcon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{makeIcon} 4 | \alias{makeIcon} 5 | \title{Define icon sets} 6 | \usage{ 7 | makeIcon(iconUrl = NULL, iconRetinaUrl = NULL, iconWidth = NULL, 8 | iconHeight = NULL, iconAnchorX = NULL, iconAnchorY = NULL, 9 | shadowUrl = NULL, shadowRetinaUrl = NULL, shadowWidth = NULL, 10 | shadowHeight = NULL, shadowAnchorX = NULL, shadowAnchorY = NULL, 11 | popupAnchorX = NULL, popupAnchorY = NULL, className = NULL) 12 | } 13 | \arguments{ 14 | \item{iconUrl}{the URL or file path to the icon image} 15 | 16 | \item{iconRetinaUrl}{the URL or file path to a retina sized version of the 17 | icon image} 18 | 19 | \item{iconWidth}{size of the icon image in pixels} 20 | 21 | \item{iconHeight}{size of the icon image in pixels} 22 | 23 | \item{iconAnchorX}{the coordinates of the "tip" of the icon 24 | (relative to its top left corner, i.e. the top left corner means 25 | \code{iconAnchorX = 0} and \code{iconAnchorY = 0)}, and the icon will be 26 | aligned so that this point is at the marker's geographical location} 27 | 28 | \item{iconAnchorY}{the coordinates of the "tip" of the icon 29 | (relative to its top left corner, i.e. the top left corner means 30 | \code{iconAnchorX = 0} and \code{iconAnchorY = 0)}, and the icon will be 31 | aligned so that this point is at the marker's geographical location} 32 | 33 | \item{shadowUrl}{the URL or file path to the icon shadow image} 34 | 35 | \item{shadowRetinaUrl}{the URL or file path to the retina sized version of 36 | the icon shadow image} 37 | 38 | \item{shadowWidth}{size of the shadow image in pixels} 39 | 40 | \item{shadowHeight}{size of the shadow image in pixels} 41 | 42 | \item{shadowAnchorX}{the coordinates of the "tip" of the shadow} 43 | 44 | \item{shadowAnchorY}{the coordinates of the "tip" of the shadow} 45 | 46 | \item{popupAnchorX}{the coordinates of the point from which 47 | popups will "open", relative to the icon anchor} 48 | 49 | \item{popupAnchorY}{the coordinates of the point from which 50 | popups will "open", relative to the icon anchor} 51 | 52 | \item{className}{a custom class name to assign to both icon and shadow images} 53 | } 54 | \description{ 55 | Define icon sets 56 | } 57 | 58 | -------------------------------------------------------------------------------- /inst/examples/highlight-polygons.R: -------------------------------------------------------------------------------- 1 | #' 2 | #' An example to show how to highlight polygons on hover using `onRender` 3 | #' 4 | library(sp) 5 | library(albersusa) 6 | library(maptools) 7 | library(leaflet) 8 | 9 | spdf <- rmapshaper::ms_simplify(usa_composite()) 10 | 11 | pal <- colorNumeric(palette = "Blues", domain = spdf@data$pop_2014) 12 | pal2 <- colorNumeric(palette = "Reds", domain = spdf@data$pop_2013) 13 | 14 | bounds <- c(-125, 24 ,-75, 45) 15 | 16 | leaflet( 17 | options= 18 | leafletOptions( 19 | worldCopyJump = FALSE, 20 | crs=leafletCRS( 21 | crsClass="L.Proj.CRS", 22 | code='EPSG:2163', 23 | proj4def='+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs', 24 | resolutions = c(65536, 32768, 16384, 8192, 4096, 2048,1024, 512, 256, 128) 25 | ))) %>% 26 | fitBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>% 27 | setMaxBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>% 28 | addPolygons(data=spdf, weight = 1, color = "#000000", 29 | fillColor=~pal(pop_2014), 30 | fillOpacity=0.7, 31 | label=~stringr::str_c( 32 | name,' ', 33 | formatC(pop_2014, big.mark = ',', format='d')), 34 | labelOptions= labelOptions(direction = 'auto'), 35 | highlightOptions = highlightOptions( 36 | color='#ff0000', opacity = 1, weight = 2, fillOpacity = 1, 37 | bringToFront = TRUE, sendToBack = TRUE), 38 | group="2014") %>% 39 | addPolygons(data=spdf, weight = 1, color = "#000000", 40 | fillColor=~pal2(pop_2013), 41 | fillOpacity=0.7, 42 | label=~stringr::str_c( 43 | name,' ', 44 | formatC(pop_2014, big.mark = ',', format='d')), 45 | labelOptions= labelOptions(direction = 'auto'), 46 | highlightOptions = highlightOptions( 47 | color='#00ff00', opacity = 1, weight = 2, fillOpacity = 1, 48 | bringToFront = TRUE, sendToBack = TRUE), 49 | group="2013") %>% 50 | addLayersControl( 51 | baseGroups=c("2014", "2013"), 52 | position = "topleft", 53 | options = layersControlOptions(collapsed = FALSE) 54 | ) 55 | -------------------------------------------------------------------------------- /inst/examples/icons.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | # adapted from http://leafletjs.com/examples/custom-icons.html 4 | 5 | iconData = data.frame( 6 | lat = c(rnorm(10, 0), rnorm(10, 1), rnorm(10, 2)), 7 | lng = c(rnorm(10, 0), rnorm(10, 3), rnorm(10, 6)), 8 | group = rep(sort(c('green', 'red', 'orange')), each = 10), 9 | stringsAsFactors = FALSE 10 | ) 11 | 12 | leaflet() %>% addMarkers( 13 | data = iconData, 14 | icon = ~ icons( 15 | iconUrl = sprintf('http://leafletjs.com/docs/images/leaf-%s.png', group), 16 | shadowUrl = 'http://leafletjs.com/docs/images/leaf-shadow.png', 17 | iconWidth = 38, iconHeight = 95, shadowWidth = 50, shadowHeight = 64, 18 | iconAnchorX = 22, iconAnchorY = 94, shadowAnchorX = 4, shadowAnchorY = 62, 19 | popupAnchorX = -3, popupAnchorY = -76 20 | ) 21 | ) 22 | 23 | 24 | # use point symbols from base R graphics as icons 25 | pchIcons = function(pch = 0:14, width = 30, height = 30, ...) { 26 | n = length(pch) 27 | files = character(n) 28 | # create a sequence of png images 29 | for (i in seq_len(n)) { 30 | f = tempfile(fileext = '.png') 31 | png(f, width = width, height = height, bg = 'transparent') 32 | par(mar = c(0, 0, 0, 0)) 33 | plot.new() 34 | points(.5, .5, pch = pch[i], cex = min(width, height) / 8, ...) 35 | dev.off() 36 | files[i] = f 37 | } 38 | files 39 | } 40 | 41 | iconData = matrix(rnorm(500), ncol = 2) 42 | res = kmeans(iconData, 10) 43 | iconData = cbind(iconData, res$cluster) 44 | colnames(iconData) = c('lat', 'lng', 'group') 45 | iconData = as.data.frame(iconData) 46 | 47 | # 10 random point shapes for the 10 clusters in iconData 48 | shapes = sample(0:14, 10) 49 | iconFiles = pchIcons(shapes, 40, 40, col = 'steelblue', lwd = 2) 50 | 51 | # note the data has 250 rows, and there are 10 icons in iconFiles; they are 52 | # connected by the `group` variable: the i-th row of iconData uses the 53 | # group[i]-th icon in the icon list 54 | leaflet() %>% addMarkers( 55 | data = iconData, 56 | icon = ~ icons( 57 | iconUrl = iconFiles[group], 58 | popupAnchorX = 20, popupAnchorY = 0 59 | ), 60 | popup = ~ sprintf( 61 | 'lat = %.4f, long = %.4f, group = %s, pch = %s', lat, lng, group, shapes[group] 62 | ) 63 | ) 64 | 65 | unlink(iconFiles) # clean up the tmp png files that have been embedded 66 | -------------------------------------------------------------------------------- /inst/examples/polygon-colors.R: -------------------------------------------------------------------------------- 1 | library(magrittr) 2 | 3 | fName <- 'https://raw.githubusercontent.com/MinnPost/simple-map-d3/master/example-data/world-population.geo.json' 4 | 5 | readGeoJson_ <- function(fName) { 6 | rmapshaper::ms_simplify(paste0(readLines(fName))) 7 | } 8 | 9 | readGeoJson <- memoise::memoise(readGeoJson_) 10 | geoJson <- readGeoJson(fName) 11 | 12 | spdf <- geojsonio::geojson_sp(geoJson) 13 | 14 | #' 15 | #' 16 | #' Calculate population density only for countries with AREA & POP > 1. 17 | spdf@data %<>% dplyr::mutate( 18 | AREA = as.numeric(as.character(AREA)), 19 | POP2005 = as.numeric(as.character(POP2005)) 20 | ) 21 | 22 | spdf <- subset( 23 | spdf, 24 | !(is.na(AREA) | AREA <1 | is.na(POP2005) | POP2005<1) 25 | ) 26 | 27 | spdf@data %<>% 28 | dplyr::mutate( 29 | POPDENSITY = POP2005/AREA 30 | ) 31 | #' 32 | #' 33 | DT::datatable(spdf@data %>% dplyr::select(NAME,POP2005,AREA,POPDENSITY), 34 | options = list(pageLength=5)) 35 | #' 36 | #' 37 | 38 | library(leaflet) 39 | leaf <- leaflet(spdf) 40 | 41 | #' 42 | #' 43 | #' ### Quantiles 44 | 45 | qpal <- colorQuantile(rev(viridis::viridis(10)), spdf$POPDENSITY, n=10) 46 | 47 | leaf %>% 48 | addPolygons(weight=1,color='#333333', fillOpacity = 1, 49 | fillColor = ~qpal(POPDENSITY) ) %>% 50 | addLegend("bottomleft", pal = qpal, values = ~POPDENSITY, 51 | title = htmltools::HTML("Population Density
(2005)"), 52 | opacity = 1 ) 53 | 54 | 55 | #' 56 | #' 57 | #' ### Bins 58 | binpal <- colorBin(rev(viridis::viridis(10)), spdf$POPDENSITY, bins=10) 59 | 60 | leaf %>% 61 | addPolygons(weight=1,color='#333333', fillOpacity = 1, 62 | fillColor = ~binpal(POPDENSITY)) %>% 63 | addLegend("bottomleft", pal = binpal, values = ~POPDENSITY, 64 | title = htmltools::HTML("Population Density
(2005)"), 65 | opacity = 1 ) 66 | 67 | #' 68 | #' 69 | #' ### Numeric 70 | numpal <- colorNumeric(rev(viridis::viridis(256)), spdf$POPDENSITY) 71 | 72 | leaf %>% 73 | addPolygons(weight=1,color='#333333', fillOpacity = 1, 74 | fillColor = ~numpal(POPDENSITY)) %>% 75 | addLegend("bottomleft", pal = numpal, values = ~POPDENSITY, 76 | title = htmltools::HTML("Population Density
(2005)"), 77 | opacity = 1 ) 78 | #' 79 | #' 80 | 81 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet-MiniMap/Control.MiniMap.css: -------------------------------------------------------------------------------- 1 | .leaflet-control-minimap { 2 | border:solid rgba(255, 255, 255, 1.0) 4px; 3 | box-shadow: 0 1px 5px rgba(0,0,0,0.65); 4 | border-radius: 3px; 5 | background: #f8f8f9; 6 | transition: all .6s; 7 | } 8 | 9 | .leaflet-control-minimap a { 10 | background-color: rgba(255, 255, 255, 1.0); 11 | background-repeat: no-repeat; 12 | z-index: 99999; 13 | transition: all .6s; 14 | } 15 | 16 | .leaflet-control-minimap a.minimized-bottomright { 17 | -webkit-transform: rotate(180deg); 18 | transform: rotate(180deg); 19 | border-radius: 0px; 20 | } 21 | 22 | .leaflet-control-minimap a.minimized-topleft { 23 | -webkit-transform: rotate(0deg); 24 | transform: rotate(0deg); 25 | border-radius: 0px; 26 | } 27 | 28 | .leaflet-control-minimap a.minimized-bottomleft { 29 | -webkit-transform: rotate(270deg); 30 | transform: rotate(270deg); 31 | border-radius: 0px; 32 | } 33 | 34 | .leaflet-control-minimap a.minimized-topright { 35 | -webkit-transform: rotate(90deg); 36 | transform: rotate(90deg); 37 | border-radius: 0px; 38 | } 39 | 40 | .leaflet-control-minimap-toggle-display{ 41 | background-image: url("images/toggle.svg"); 42 | background-size: cover; 43 | position: absolute; 44 | border-radius: 3px 0px 0px 0px; 45 | } 46 | 47 | .leaflet-oldie .leaflet-control-minimap-toggle-display{ 48 | background-image: url("images/toggle.png"); 49 | } 50 | 51 | .leaflet-control-minimap-toggle-display-bottomright { 52 | bottom: 0; 53 | right: 0; 54 | } 55 | 56 | .leaflet-control-minimap-toggle-display-topleft{ 57 | top: 0; 58 | left: 0; 59 | -webkit-transform: rotate(180deg); 60 | transform: rotate(180deg); 61 | } 62 | 63 | .leaflet-control-minimap-toggle-display-bottomleft{ 64 | bottom: 0; 65 | left: 0; 66 | -webkit-transform: rotate(90deg); 67 | transform: rotate(90deg); 68 | } 69 | 70 | .leaflet-control-minimap-toggle-display-topright{ 71 | top: 0; 72 | right: 0; 73 | -webkit-transform: rotate(270deg); 74 | transform: rotate(270deg); 75 | } 76 | 77 | /* Old IE */ 78 | .leaflet-oldie .leaflet-control-minimap { 79 | border: 1px solid #999; 80 | } 81 | 82 | .leaflet-oldie .leaflet-control-minimap a { 83 | background-color: #fff; 84 | } 85 | 86 | .leaflet-oldie .leaflet-control-minimap a.minimized { 87 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2); 88 | } 89 | -------------------------------------------------------------------------------- /man/addLayersControl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{addLayersControl} 4 | \alias{addLayersControl} 5 | \alias{layersControlOptions} 6 | \alias{removeLayersControl} 7 | \title{Add UI controls to switch layers on and off} 8 | \usage{ 9 | addLayersControl(map, baseGroups = character(0), 10 | overlayGroups = character(0), position = c("topright", "bottomright", 11 | "bottomleft", "topleft"), options = layersControlOptions()) 12 | 13 | layersControlOptions(collapsed = TRUE, autoZIndex = TRUE, ...) 14 | 15 | removeLayersControl(map) 16 | } 17 | \arguments{ 18 | \item{map}{the map to add the layers control to} 19 | 20 | \item{baseGroups}{character vector where each element is the name of a group. 21 | The user will be able to choose one base group (only) at a time. This is 22 | most commonly used for mostly-opaque tile layers.} 23 | 24 | \item{overlayGroups}{character vector where each element is the name of a 25 | group. The user can turn each overlay group on or off independently.} 26 | 27 | \item{position}{position of control: 'topleft', 'topright', 'bottomleft', or 28 | 'bottomright'} 29 | 30 | \item{options}{a list of additional options, intended to be provided by 31 | a call to \code{layersControlOptions}} 32 | 33 | \item{collapsed}{if \code{TRUE} (the default), the layers control will be 34 | rendered as an icon that expands when hovered over. Set to \code{FALSE} 35 | to have the layers control always appear in its expanded state.} 36 | 37 | \item{autoZIndex}{if \code{TRUE}, the control will automatically maintain 38 | the z-order of its various groups as overlays are switched on and off.} 39 | 40 | \item{...}{other options for \code{layersControlOptions()}} 41 | } 42 | \description{ 43 | Uses Leaflet's built-in 44 | \href{http://leafletjs.com/reference.html#control-layers}{layers control} 45 | feature to allow users to choose one of several base layers, and to choose 46 | any number of overlay layers to view. 47 | } 48 | \examples{ 49 | \donttest{ 50 | leaflet() \%>\% 51 | addTiles(group = "OpenStreetMap") \%>\% 52 | addProviderTiles("Stamen.Toner", group = "Toner by Stamen") \%>\% 53 | addMarkers(runif(20, -75, -74), runif(20, 41, 42), group = "Markers") \%>\% 54 | addLayersControl( 55 | baseGroups = c("OpenStreetMap", "Toner by Stamen"), 56 | overlayGroups = c("Markers") 57 | ) 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | grunt.initConfig({ 3 | babel: { 4 | options: { 5 | sourceMap: true, 6 | presets: ["es2015"], 7 | plugins: ["transform-es2015-modules-commonjs"] 8 | }, 9 | dist: { 10 | files: [{ 11 | expand: true, 12 | cwd: 'javascript/src', 13 | src: ['**/*.js'], 14 | dest: 'inst/htmlwidgets/sources', 15 | ext:'.js' 16 | }] 17 | }, 18 | distSpecs: { 19 | files: [{ 20 | expand: true, 21 | cwd: 'javascript/tests', 22 | src: ['**/*.js'], 23 | dest: 'inst/htmlwidgets/sources', 24 | ext:'.js' 25 | }] 26 | } 27 | }, 28 | browserify: { 29 | options: { 30 | browserifyOptions: { 31 | //debug: true 32 | } 33 | }, 34 | dist: { 35 | files: { 36 | // if the source file has an extension of es6 then 37 | // we change the name of the source file accordingly. 38 | // The result file's extension is always .js 39 | "./inst/htmlwidgets/leaflet.js": ["./inst/htmlwidgets/sources/index.js"] 40 | } 41 | } 42 | }, 43 | eslint: { 44 | target: ["./javascript/src/*.js"] 45 | }, 46 | mochaTest: { 47 | test: { 48 | options: { 49 | reporter: "spec", 50 | require: ["babel-register", "source-map-support/register"], 51 | // captureFile: 'results.txt', // Optionally capture the reporter output to a file 52 | quiet: false, // Optionally suppress output to standard out (defaults to false) 53 | clearRequireCache: false // Optionally clear the require cache before running tests (defaults to false) 54 | }, 55 | src: ["inst/htmlwidgets/sources/test-*.js"] 56 | } 57 | }, 58 | watch: { 59 | scripts: { 60 | files: ["./javascript/src/**/*.js", "javascript/tests/**/*.js"], 61 | tasks: ["babel", "browserify", "eslint", "mochaTest"] 62 | } 63 | } 64 | }); 65 | 66 | grunt.loadNpmTasks("grunt-babel"); 67 | grunt.loadNpmTasks("grunt-browserify"); 68 | grunt.loadNpmTasks("grunt-contrib-watch"); 69 | grunt.loadNpmTasks("grunt-eslint"); 70 | grunt.loadNpmTasks("grunt-mocha-test"); 71 | 72 | grunt.registerTask("default", ["watch"]); 73 | grunt.registerTask("build", ["babel", "browserify", "eslint", "mochaTest"]); 74 | }; -------------------------------------------------------------------------------- /man/easyButton.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-easybutton.R 3 | \name{easyButtonState} 4 | \alias{addEasyButton} 5 | \alias{addEasyButtonBar} 6 | \alias{easyButton} 7 | \alias{easyButtonState} 8 | \title{Create an easyButton statestate} 9 | \usage{ 10 | easyButtonState(stateName, icon, title, onClick) 11 | 12 | easyButton(icon = NULL, title = NULL, onClick = NULL, 13 | position = "topleft", id = NULL, states = NULL) 14 | 15 | addEasyButton(map, button) 16 | 17 | addEasyButtonBar(map, ..., position = "topleft", id = NULL) 18 | } 19 | \arguments{ 20 | \item{stateName}{a unique name for the state} 21 | 22 | \item{icon}{the button icon} 23 | 24 | \item{title}{text to show on hover} 25 | 26 | \item{onClick}{the action to take} 27 | 28 | \item{position}{topleft|topright|bottomleft|bottomright} 29 | 30 | \item{id}{id for the button} 31 | 32 | \item{states}{the states} 33 | 34 | \item{map}{a map widget object} 35 | 36 | \item{button}{the button object created with \code{\link{easyButton}}} 37 | 38 | \item{...}{a list of buttons created with \code{\link{easyButton}}} 39 | } 40 | \description{ 41 | Create an easyButton statestate 42 | 43 | Creates an easy button. 44 | 45 | Add a EasyButton on the map 46 | see \url{https://github.com/CliffCloud/Leaflet.EasyButton} 47 | 48 | Add a easyButton bar on the map 49 | see \url{https://github.com/CliffCloud/Leaflet.EasyButton} 50 | } 51 | \section{Functions}{ 52 | \itemize{ 53 | \item \code{easyButtonState}: state of an easyButton. 54 | 55 | \item \code{addEasyButton}: add an EasyButton to the map 56 | 57 | \item \code{addEasyButtonBar}: add an EasyButton to the map 58 | }} 59 | \examples{ 60 | library(leaflet) 61 | 62 | leaf <- leaflet() \%>\% 63 | addTiles() \%>\% 64 | addEasyButton(easyButton( 65 | icon = htmltools::span(class='star','★'), 66 | onClick = JS("function(btn, map){ map.setZoom(1);}"))) 67 | 68 | library(leaflet) 69 | 70 | leaf <- leaflet() \%>\% 71 | addTiles() \%>\% 72 | addEasyButtonBar( 73 | easyButton( 74 | icon = htmltools::span(class='star','★'), 75 | onClick = JS("function(btn, map){ alert('Button 1');}")), 76 | easyButton( 77 | icon = htmltools::span(class='star','⌖'), 78 | onClick = JS("function(btn, map){ alert('Button 2');}"))) 79 | 80 | 81 | } 82 | \seealso{ 83 | \code{\link{easyButton}} 84 | 85 | \url{https://github.com/CliffCloud/Leaflet.EasyButton} 86 | 87 | \code{\link{addEasyButton}} 88 | } 89 | 90 | -------------------------------------------------------------------------------- /R/methods.R: -------------------------------------------------------------------------------- 1 | #' Methods to manipulate the map widget 2 | #' 3 | #' A series of methods to manipulate the map. 4 | #' @param map a map widget object created from \code{\link{leaflet}()} 5 | #' @param lng The longitude of the map center 6 | #' @param lat The latitude of the map center 7 | #' @param zoom the zoom level 8 | #' @param options a list of zoom/pan options (see 9 | #' \url{http://leafletjs.com/reference.html#map-zoompanoptions}) 10 | #' @references \url{http://leafletjs.com/reference.html#map-set-methods} 11 | #' @return The modified map widget. 12 | #' @describeIn map-methods Set the view of the map (center and zoom level) 13 | #' @export 14 | #' @examples library(leaflet) 15 | #' m = leaflet() %>% addTiles() %>% setView(-71.0382679, 42.3489054, zoom = 18) 16 | #' m # the RStudio 'headquarter' 17 | #' m %>% fitBounds(-72, 40, -70, 43) 18 | #' m %>% clearBounds() # world view 19 | setView <- function(map, lng, lat, zoom, options = list()) { 20 | view = evalFormula(list(c(lat, lng), zoom, options)) 21 | 22 | dispatch(map, 23 | "setView", 24 | leaflet = { 25 | map$x$setView = view 26 | map$x$fitBounds = NULL 27 | map 28 | }, 29 | leaflet_proxy = { 30 | invokeRemote(map, "setView", view) 31 | map 32 | } 33 | ) 34 | } 35 | 36 | #' @describeIn map-methods Set the bounds of a map 37 | #' @param lng1,lat1,lng2,lat2 the coordinates of the map bounds 38 | #' @export 39 | fitBounds <- function(map, lng1, lat1, lng2, lat2) { 40 | bounds = evalFormula(list(lat1, lng1, lat2, lng2), getMapData(map)) 41 | 42 | dispatch(map, 43 | "fitBounds", 44 | leaflet = { 45 | map$x$fitBounds = bounds 46 | map$x$setView = NULL 47 | map 48 | }, 49 | leaflet_proxy = { 50 | invokeRemote(map, "fitBounds", bounds) 51 | map 52 | } 53 | ) 54 | } 55 | 56 | #' @describeIn map-methods Restricts the map view to the given bounds 57 | #' @export 58 | setMaxBounds <- function(map, lng1, lat1, lng2, lat2) { 59 | invokeMethod(map, getMapData(map), 'setMaxBounds', lat1, lng1, lat2, lng2) 60 | } 61 | 62 | #' @describeIn map-methods Clear the bounds of a map, and the bounds will be 63 | #' automatically determined from latitudes and longitudes of the map elements 64 | #' if available (otherwise the full world view is used) 65 | #' @export 66 | clearBounds <- function(map) { 67 | dispatch(map, 68 | "clearBounds", 69 | leaflet = { 70 | map$x$fitBounds = NULL 71 | map$x$setView = NULL 72 | map 73 | } 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /inst/legacy/examples/choropleth/server.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | library(RColorBrewer) 3 | library(maps) 4 | 5 | shinyServer(function(input, output, session) { 6 | values <- reactiveValues(highlight = c()) 7 | 8 | map <- createLeafletMap(session, "map") 9 | 10 | # Draw the given states, with or without highlighting 11 | drawStates <- function(stateNames, highlight = FALSE) { 12 | states <- map("state", stateNames, plot=FALSE, fill=TRUE) 13 | map$addPolygon(I(states$y), I(states$x), I(states$names), 14 | I(lapply(states$names, function(x) { 15 | x <- strsplit(x, ":")[[1]][1] 16 | list(fillColor = colors[[x]]) 17 | })), 18 | I(list(fill=TRUE, fillOpacity=0.7, 19 | stroke=TRUE, opacity=1, color="white", weight=ifelse(highlight, 4, 1) 20 | )) 21 | ) 22 | } 23 | 24 | observe({ 25 | print(input$map_zoom) 26 | map$clearShapes() 27 | if (!is.null(input$map_zoom) && input$map_zoom > 6) { 28 | # Get shapes from the maps package 29 | drawStates(names(density)) 30 | } 31 | }) 32 | 33 | # input$map_shape_mouseover gets updated a lot, even if the id doesn't change. 34 | # We don't want to update the polygons and stateInfo except when the id 35 | # changes, so use values$highlight to insulate the downstream reactives (as 36 | # writing to values$highlight doesn't trigger reactivity unless the new value 37 | # is different than the previous value). 38 | observe({ 39 | values$highlight <- input$map_shape_mouseover$id 40 | }) 41 | 42 | # Dynamically render the box in the upper-right 43 | output$stateInfo <- renderUI({ 44 | if (is.null(values$highlight)) { 45 | return(tags$div("Hover over a state")) 46 | } else { 47 | # Get a properly formatted state name 48 | stateName <- names(density)[getStateName(values$highlight) == tolower(names(density))] 49 | return(tags$div( 50 | tags$strong(stateName), 51 | tags$div(density[stateName], HTML("people/m2")) 52 | )) 53 | } 54 | }) 55 | 56 | lastHighlighted <- c() 57 | # When values$highlight changes, unhighlight the old state (if any) and 58 | # highlight the new state 59 | observe({ 60 | if (length(lastHighlighted) > 0) 61 | drawStates(getStateName(lastHighlighted), FALSE) 62 | lastHighlighted <<- values$highlight 63 | 64 | if (is.null(values$highlight)) 65 | return() 66 | 67 | isolate({ 68 | drawStates(getStateName(values$highlight), TRUE) 69 | }) 70 | }) 71 | }) 72 | -------------------------------------------------------------------------------- /inst/examples/marker-clustering.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | #' Add a Level factor to quakes 4 | quakes <- quakes %>% 5 | dplyr::mutate(mag.level = cut(mag,c(3,4,5,6), 6 | labels = c('>3 & <=4', '>4 & <=5', '>5 & <=6'))) 7 | 8 | l <- leaflet() %>% addTiles() 9 | 10 | #'

11 | #' Default Clustering 12 | l %>% 13 | addMarkers(data=quakes, clusterOptions = markerClusterOptions()) 14 | 15 | #'

16 | #' Clustering Frozen at level 5 17 | l %>% 18 | addMarkers(data=quakes, clusterOptions = markerClusterOptions(freezeAtZoom=6)) 19 | 20 | #'

21 | #' Clustering of Label Only Clusters 22 | l %>% 23 | addLabelOnlyMarkers(data=quakes, 24 | lng=~long, lat=~lat, 25 | label=~as.character(mag), 26 | clusterOptions = markerClusterOptions(), 27 | labelOptions = labelOptions(noHide = T, 28 | direction = 'auto')) 29 | #'

30 | #' Clustering + Layers 31 | quakes.df <- split(quakes, quakes$mag.level) 32 | 33 | l2 <- l 34 | names(quakes.df) %>% 35 | purrr::walk( function(df) { 36 | l2 <<- l2 %>% 37 | addMarkers(data=quakes.df[[df]], 38 | lng=~long, lat=~lat, 39 | label=~as.character(mag), 40 | popup=~as.character(mag), 41 | group = df, 42 | clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F), 43 | labelOptions = labelOptions(noHide = T, 44 | direction = 'auto')) 45 | }) 46 | 47 | l2 %>% 48 | addLayersControl( 49 | overlayGroups = names(quakes.df), 50 | options = layersControlOptions(collapsed = FALSE) 51 | ) 52 | 53 | #'

54 | #' Clustering with custom iconCreateFunction 55 | leaflet(quakes) %>% addTiles() %>% 56 | addMarkers(clusterOptions = 57 | markerClusterOptions(iconCreateFunction = 58 | JS(" 59 | function(cluster) { 60 | return new L.DivIcon({ 61 | html: '
' + cluster.getChildCount() + '
', 62 | className: 'marker-cluster' 63 | }); 64 | }"))) 65 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: leaflet 2 | Type: Package 3 | Title: Create Interactive Web Maps with the JavaScript 'Leaflet' Library 4 | Version: 1.0.2.9010 5 | Date: 2016-12-14 6 | Authors@R: c( 7 | person("Joe", "Cheng", email = "joe@rstudio.com", role = c("aut", "cre")), 8 | person("Yihui", "Xie", role = c("aut")), 9 | person("Hadley", "Wickham", role = c("ctb")), 10 | person("Kenton", "Russell", role = c("ctb")), 11 | person("Bhaskar", "Karambelkar", role = c("ctb")), 12 | person("Kent", "Johnson", role=c("ctb")), 13 | person("jQuery Foundation and contributors", role = c("ctb", "cph"), comment = "jQuery library"), 14 | person("Vladimir", "Agafonkin", role = c("ctb", "cph"), comment = "Leaflet library"), 15 | person("CloudMade", role = c("cph"), comment = "Leaflet library"), 16 | person("Leaflet contributors", role = c("ctb"), comment = "Leaflet library"), 17 | person("Leaflet Providers contributors", role = c("ctb", "cph"), comment = "Leaflet Providers plugin"), 18 | person("Brandon Copeland", role = c("ctb", "cph"), comment = "leaflet-measure plugin"), 19 | person("Jacob Toye", role = c("ctb", "cph"), comment = "Leaflet.label plugin"), 20 | person("Joerg Dietrich", role = c("ctb", "cph"), comment = "Leaflet.Terminator plugin"), 21 | person("Benjamin Becquet", role = c("ctb", "cph"), comment = "Leaflet.MagnifyingGlass plugin"), 22 | person("Norkart AS", role = c("ctb", "cph"), comment = "Leaflet.MiniMap plugin"), 23 | person("L. Voogdt", role = c("ctb", "cph"), comment = "Leaflet.awesome-markers plugin"), 24 | person("RStudio", role = c("cph")) 25 | ) 26 | Maintainer: Joe Cheng 27 | Description: Create and customize interactive maps using the 'Leaflet' 28 | JavaScript library and the 'htmlwidgets' package. These maps can be used 29 | directly from the R console, from 'RStudio', in Shiny apps and R Markdown 30 | documents. 31 | License: GPL-3 | file LICENSE 32 | URL: http://rstudio.github.io/leaflet/ 33 | BugReports: https://github.com/rstudio/leaflet/issues 34 | Depends: R (>= 3.1.0) 35 | Imports: 36 | base64enc, 37 | crosstalk, 38 | htmlwidgets, 39 | htmltools, 40 | magrittr, 41 | markdown, 42 | methods, 43 | png, 44 | RColorBrewer, 45 | raster, 46 | scales (>= 0.2.5), 47 | sp, 48 | stats, 49 | viridis 50 | Suggests: 51 | knitr, 52 | maps, 53 | sf, 54 | shiny, 55 | testit (>= 0.4), 56 | rgdal, 57 | rgeos, 58 | R6, 59 | RJSONIO, 60 | purrr, 61 | testthat 62 | Remotes: 63 | rstudio/crosstalk 64 | RoxygenNote: 5.0.1 65 | LazyData: true 66 | -------------------------------------------------------------------------------- /javascript/src/dataframe.js: -------------------------------------------------------------------------------- 1 | import { recycle, asArray } from "./util"; 2 | 3 | export default class DataFrame { 4 | constructor() { 5 | this.columns = []; 6 | this.colnames = []; 7 | this.colstrict = []; 8 | 9 | this.effectiveLength = 0; 10 | this.colindices = {}; 11 | } 12 | 13 | _updateCachedProperties() { 14 | this.effectiveLength = 0; 15 | this.colindices = {}; 16 | 17 | this.columns.forEach((column, i) => { 18 | this.effectiveLength = Math.max(this.effectiveLength, column.length); 19 | this.colindices[this.colnames[i]] = i; 20 | }); 21 | } 22 | 23 | _colIndex(colname) { 24 | let index = this.colindices[colname]; 25 | if (typeof(index) === "undefined") 26 | return -1; 27 | return index; 28 | } 29 | 30 | col(name, values, strict) { 31 | if (typeof(name) !== "string") 32 | throw new Error("Invalid column name \"" + name + "\""); 33 | 34 | let index = this._colIndex(name); 35 | 36 | if (arguments.length === 1) { 37 | if (index < 0) 38 | return null; 39 | else 40 | return recycle(this.columns[index], this.effectiveLength); 41 | } 42 | 43 | if (index < 0) { 44 | index = this.colnames.length; 45 | this.colnames.push(name); 46 | } 47 | this.columns[index] = asArray(values); 48 | this.colstrict[index] = !!strict; 49 | 50 | // TODO: Validate strictness (ensure lengths match up with other stricts) 51 | 52 | this._updateCachedProperties(); 53 | 54 | return this; 55 | } 56 | 57 | cbind(obj, strict) { 58 | Object.keys(obj).forEach((name) => { 59 | let coldata = obj[name]; 60 | this.col(name, coldata); 61 | }); 62 | return this; 63 | } 64 | 65 | get(row, col, missingOK) { 66 | if (row > this.effectiveLength) 67 | throw new Error("Row argument was out of bounds: " + row + " > " + this.effectiveLength); 68 | 69 | let colIndex = -1; 70 | if (typeof(col) === "undefined") { 71 | let rowData = {}; 72 | this.colnames.forEach((name, i) => { 73 | rowData[name] = this.columns[i][row % this.columns[i].length]; 74 | }); 75 | return rowData; 76 | } else if (typeof(col) === "string") { 77 | colIndex = this._colIndex(col); 78 | } else if (typeof(col) === "number") { 79 | colIndex = col; 80 | } 81 | if (colIndex < 0 || colIndex > this.columns.length) { 82 | if (missingOK) 83 | return void 0; 84 | else 85 | throw new Error("Unknown column index: " + col); 86 | } 87 | 88 | return this.columns[colIndex][row % this.columns[colIndex].length]; 89 | } 90 | 91 | nrow() { 92 | return this.effectiveLength; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-providers/css/gh-fork-ribbon.ie.css: -------------------------------------------------------------------------------- 1 | /* IE voodoo courtesy of http://stackoverflow.com/a/4617511/263871 and 2 | * http://www.useragentman.com/IETransformsTranslator */ 3 | .github-fork-ribbon-wrapper.right .github-fork-ribbon { 4 | /* IE positioning hack (couldn't find a transform-origin alternative for IE) */ 5 | top: -22px; 6 | right: -62px; 7 | 8 | /* IE8+ */ 9 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865474, M12=-0.7071067811865477, M21=0.7071067811865477, M22=0.7071067811865474, SizingMethod='auto expand')"; 10 | /* IE6 and 7 */ 11 | filter: progid:DXImageTransform.Microsoft.Matrix( 12 | M11=0.7071067811865474, 13 | M12=-0.7071067811865477, 14 | M21=0.7071067811865477, 15 | M22=0.7071067811865474, 16 | SizingMethod='auto expand' 17 | ); 18 | } 19 | 20 | .github-fork-ribbon-wrapper.left .github-fork-ribbon { 21 | top: -22px; 22 | left: -22px; 23 | 24 | /* IE8+ */ 25 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865483, M12=0.7071067811865467, M21=-0.7071067811865467, M22=0.7071067811865483, SizingMethod='auto expand')"; 26 | /* IE6 and 7 */ 27 | filter: progid:DXImageTransform.Microsoft.Matrix( 28 | M11=0.7071067811865483, 29 | M12=0.7071067811865467, 30 | M21=-0.7071067811865467, 31 | M22=0.7071067811865483, 32 | SizingMethod='auto expand' 33 | ); 34 | } 35 | 36 | .github-fork-ribbon-wrapper.left-bottom .github-fork-ribbon { 37 | /* IE positioning hack (couldn't find a transform-origin alternative for IE) */ 38 | top: 12px; 39 | left: -22px; 40 | 41 | 42 | /* IE8+ */ 43 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865474, M12=-0.7071067811865477, M21=0.7071067811865477, M22=0.7071067811865474, SizingMethod='auto expand')"; 44 | /* IE6 and 7 */ 45 | /* filter: progid:DXImageTransform.Microsoft.Matrix( 46 | M11=0.7071067811865474, 47 | M12=-0.7071067811865477, 48 | M21=0.7071067811865477, 49 | M22=0.7071067811865474, 50 | SizingMethod='auto expand' 51 | ); 52 | */} 53 | 54 | .github-fork-ribbon-wrapper.right-bottom .github-fork-ribbon { 55 | top: 12px; 56 | right: -62px; 57 | 58 | /* IE8+ */ 59 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865483, M12=0.7071067811865467, M21=-0.7071067811865467, M22=0.7071067811865483, SizingMethod='auto expand')"; 60 | /* IE6 and 7 */ 61 | filter: progid:DXImageTransform.Microsoft.Matrix( 62 | M11=0.7071067811865483, 63 | M12=0.7071067811865467, 64 | M21=-0.7071067811865467, 65 | M22=0.7071067811865483, 66 | SizingMethod='auto expand' 67 | ); 68 | } -------------------------------------------------------------------------------- /man/leafletProxy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{leafletProxy} 4 | \alias{leafletProxy} 5 | \title{Send commands to a Leaflet instance in a Shiny app} 6 | \usage{ 7 | leafletProxy(mapId, session = shiny::getDefaultReactiveDomain(), 8 | data = NULL, deferUntilFlush = TRUE) 9 | } 10 | \arguments{ 11 | \item{mapId}{single-element character vector indicating the output ID of the 12 | map to modify (if invoked from a Shiny module, the namespace will be added 13 | automatically)} 14 | 15 | \item{session}{the Shiny session object to which the map belongs; usually the 16 | default value will suffice} 17 | 18 | \item{data}{a data object; see Details under the \code{\link{leaflet}} help 19 | topic} 20 | 21 | \item{deferUntilFlush}{indicates whether actions performed against this 22 | instance should be carried out right away, or whether they should be held 23 | until after the next time all of the outputs are updated; defaults to 24 | \code{TRUE}} 25 | } 26 | \description{ 27 | Creates a map-like object that can be used to customize and control a map 28 | that has already been rendered. For use in Shiny apps and Shiny docs only. 29 | } 30 | \details{ 31 | Normally, you create a Leaflet map using the \code{\link{leaflet}} function. 32 | This creates an in-memory representation of a map that you can customize 33 | using functions like \code{\link{addPolygons}} and \code{\link{setView}}. 34 | Such a map can be printed at the R console, included in an R Markdown 35 | document, or rendered as a Shiny output. 36 | 37 | In the case of Shiny, you may want to further customize a map, even after it 38 | is rendered to an output. At this point, the in-memory representation of the 39 | map is long gone, and the user's web browser has already realized the Leaflet 40 | map instance. 41 | 42 | This is where \code{leafletProxy} comes in. It returns an object that can 43 | stand in for the usual Leaflet map object. The usual map functions like 44 | \code{\link{addPolygons}} and \code{\link{setView}} can be called, and 45 | instead of customizing an in-memory representation, these commands will 46 | execute on the live Leaflet map instance. 47 | } 48 | \examples{ 49 | \donttest{ 50 | library(shiny) 51 | 52 | ui <- fluidPage( 53 | leafletOutput("map1") 54 | ) 55 | 56 | server <- function(input, output, session) { 57 | output$map1 <- renderLeaflet({ 58 | leaflet() \%>\% addCircleMarkers( 59 | lng = runif(10), 60 | lat = runif(10), 61 | layerId = paste0("marker", 1:10)) 62 | }) 63 | 64 | observeEvent(input$map1_marker_click, { 65 | leafletProxy("map1", session) \%>\% 66 | removeMarker(input$map1_marker_click$id) 67 | }) 68 | } 69 | 70 | shinyApp(ui, server) 71 | 72 | } 73 | 74 | } 75 | 76 | -------------------------------------------------------------------------------- /man/addAwesomeMarkers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-awesomeMarkers.R 3 | \name{addAwesomeMarkers} 4 | \alias{addAwesomeMarkers} 5 | \title{Add Awesome Markers} 6 | \usage{ 7 | addAwesomeMarkers(map, lng = NULL, lat = NULL, layerId = NULL, 8 | group = NULL, icon = NULL, popup = NULL, popupOptions = NULL, 9 | label = NULL, labelOptions = NULL, options = markerOptions(), 10 | clusterOptions = NULL, clusterId = NULL, data = getMapData(map)) 11 | } 12 | \arguments{ 13 | \item{map}{the map to add awesome Markers to.} 14 | 15 | \item{lng}{a numeric vector of longitudes, or a one-sided formula of the form 16 | \code{~x} where \code{x} is a variable in \code{data}; by default (if not 17 | explicitly provided), it will be automatically inferred from \code{data} by 18 | looking for a column named \code{lng}, \code{long}, or \code{longitude} 19 | (case-insensitively)} 20 | 21 | \item{lat}{a vector of latitudes or a formula (similar to the \code{lng} 22 | argument; the names \code{lat} and \code{latitude} are used when guessing 23 | the latitude column from \code{data})} 24 | 25 | \item{layerId}{the layer id} 26 | 27 | \item{group}{the name of the group the newly created layers should belong to 28 | (for \code{\link{clearGroup}} and \code{\link{addLayersControl}} purposes). 29 | Human-friendly group names are permitted--they need not be short, 30 | identifier-style names. Any number of layers and even different types of 31 | layers (e.g. markers and polygons) can share the same group name.} 32 | 33 | \item{icon}{the icon(s) for markers;} 34 | 35 | \item{popup}{a character vector of the HTML content for the popups (you are 36 | recommended to escape the text using \code{\link[htmltools]{htmlEscape}()}} 37 | 38 | \item{popupOptions}{A Vector of \code{\link{popupOptions}} to provide popups 39 | for security reasons)} 40 | 41 | \item{label}{a character vector of the HTML content for the labels} 42 | 43 | \item{labelOptions}{A Vector of \code{\link{labelOptions}} to provide label 44 | options for each label. Default \code{NULL}} 45 | 46 | \item{options}{a list of extra options for tile layers, popups, paths 47 | (circles, rectangles, polygons, ...), or other map elements} 48 | 49 | \item{clusterOptions}{if not \code{NULL}, markers will be clustered using 50 | \href{https://github.com/Leaflet/Leaflet.markercluster}{Leaflet.markercluster}; 51 | you can use \code{\link{markerClusterOptions}()} to specify marker cluster 52 | options} 53 | 54 | \item{clusterId}{the id for the marker cluster layer} 55 | 56 | \item{data}{the data object from which the argument values are derived; by 57 | default, it is the \code{data} object provided to \code{leaflet()} 58 | initially, but can be overridden} 59 | } 60 | \description{ 61 | Add Awesome Markers 62 | } 63 | 64 | -------------------------------------------------------------------------------- /javascript/src/mipmapper.js: -------------------------------------------------------------------------------- 1 | // This class simulates a mipmap, which shrinks images by powers of two. This 2 | // stepwise reduction results in "pixel-perfect downscaling" (where every 3 | // pixel of the original image has some contribution to the downscaled image) 4 | // as opposed to a single-step downscaling which will discard a lot of data 5 | // (and with sparse images at small scales can give very surprising results). 6 | export default class Mipmapper { 7 | constructor(img) { 8 | this._layers = [img]; 9 | } 10 | 11 | // The various functions on this class take a callback function BUT MAY OR MAY 12 | // NOT actually behave asynchronously. 13 | getBySize(desiredWidth, desiredHeight, callback) { 14 | let i = 0; 15 | let lastImg = this._layers[0]; 16 | let testNext = () => { 17 | this.getByIndex(i, function(img) { 18 | // If current image is invalid (i.e. too small to be rendered) or 19 | // it's smaller than what we wanted, return the last known good image. 20 | if (!img || img.width < desiredWidth || img.height < desiredHeight) { 21 | callback(lastImg); 22 | return; 23 | } else { 24 | lastImg = img; 25 | i++; 26 | testNext(); 27 | return; 28 | } 29 | }); 30 | }; 31 | testNext(); 32 | } 33 | 34 | getByIndex(i, callback) { 35 | if (this._layers[i]) { 36 | callback(this._layers[i]); 37 | return; 38 | } 39 | 40 | this.getByIndex(i-1, (prevImg) => { 41 | if (!prevImg) { 42 | // prevImg could not be calculated (too small, possibly) 43 | callback(null); 44 | return; 45 | } 46 | if (prevImg.width < 2 || prevImg.height < 2) { 47 | // Can't reduce this image any further 48 | callback(null); 49 | return; 50 | } 51 | // If reduce ever becomes truly asynchronous, we should stuff a promise or 52 | // something into this._layers[i] before calling this.reduce(), to prevent 53 | // redundant reduce operations from happening. 54 | this.reduce(prevImg, (reducedImg) => { 55 | this._layers[i] = reducedImg; 56 | callback(reducedImg); 57 | return; 58 | }); 59 | }); 60 | } 61 | 62 | reduce(img, callback) { 63 | let imgDataCanvas = document.createElement("canvas"); 64 | imgDataCanvas.width = Math.ceil(img.width / 2); 65 | imgDataCanvas.height = Math.ceil(img.height / 2); 66 | imgDataCanvas.style.display = "none"; 67 | document.body.appendChild(imgDataCanvas); 68 | try { 69 | let imgDataCtx = imgDataCanvas.getContext("2d"); 70 | imgDataCtx.drawImage(img, 0, 0, img.width/2, img.height/2); 71 | callback(imgDataCanvas); 72 | } finally { 73 | document.body.removeChild(imgDataCanvas); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /inst/examples/awesomeMarkers.R: -------------------------------------------------------------------------------- 1 | library(leaflet) 2 | 3 | icon.glyphicon <- makeAwesomeIcon(icon= 'flag', markerColor = 'blue', 4 | iconColor = 'black', library = 'glyphicon', 5 | squareMarker = TRUE) 6 | icon.fa <- makeAwesomeIcon(icon = 'flag', markerColor = 'red', library='fa', 7 | iconColor = 'black') 8 | icon.ion <- makeAwesomeIcon(icon = 'home', markerColor = 'green', 9 | library='ion') 10 | 11 | 12 | # Marker + Label 13 | leaflet() %>% addTiles() %>% 14 | addAwesomeMarkers( 15 | lng=-118.456554, lat=34.078039, 16 | label='This is a label', 17 | icon = icon.glyphicon) 18 | 19 | leaflet() %>% addTiles() %>% 20 | addAwesomeMarkers( 21 | lng=-118.456554, lat=34.078039, 22 | label='This is a label', 23 | icon = icon.fa) 24 | 25 | leaflet() %>% addTiles() %>% 26 | addAwesomeMarkers( 27 | lng=-118.456554, lat=34.078039, 28 | label='This is a label', 29 | icon = icon.ion) 30 | 31 | # Marker + Static Label using custom label options 32 | leaflet() %>% addTiles() %>% 33 | addAwesomeMarkers( 34 | lng=-118.456554, lat=34.078039, 35 | label='This is a static label', 36 | labelOptions = labelOptions(noHide = T), 37 | icon = icon.fa) 38 | 39 | 40 | cities <- read.csv(textConnection(" 41 | City,Lat,Long,Pop 42 | Boston,42.3601,-71.0589,645966 43 | Hartford,41.7627,-72.6743,125017 44 | New York City,40.7127,-74.0059,8406000 45 | Philadelphia,39.9500,-75.1667,1553000 46 | Pittsburgh,40.4397,-79.9764,305841 47 | Providence,41.8236,-71.4222,177994 48 | ")) 49 | 50 | library(dplyr) 51 | cities <- cities %>% mutate(PopCat=ifelse(Pop <500000,'blue','red')) 52 | 53 | 54 | leaflet(cities) %>% addTiles() %>% 55 | addAwesomeMarkers(lng = ~Long, lat = ~Lat, 56 | label = ~City, 57 | icon = icon.ion) 58 | 59 | icon.pop <- awesomeIcons(icon = 'users', 60 | markerColor = ifelse(cities$Pop <500000,'blue','red'), 61 | library = 'fa', 62 | iconColor = 'black') 63 | 64 | leaflet(cities) %>% addTiles() %>% 65 | addAwesomeMarkers(lng = ~Long, lat = ~Lat, 66 | label = ~City, 67 | icon = icon.pop) 68 | 69 | # Make a list of icons (from two different icon libraries). 70 | # We'll index into it based on name. 71 | popIcons <- awesomeIconList( 72 | blue = makeAwesomeIcon(icon='user', library='glyphicon', markerColor = 'blue'), 73 | red = makeAwesomeIcon(icon='users', library='fa', markerColor = 'red')) 74 | 75 | leaflet(cities) %>% addTiles() %>% 76 | addAwesomeMarkers(lng = ~Long, lat = ~Lat, 77 | label = ~City, 78 | labelOptions = rep(labelOptions(noHide = T),nrow(cities)), 79 | icon = ~popIcons[PopCat] ) 80 | -------------------------------------------------------------------------------- /tests/testit/test-legend.R: -------------------------------------------------------------------------------- 1 | library(testit) 2 | 3 | df = data.frame(x1 = 1:3, x2 = 1:3, x3 = 1:3, x4 = factor(1:3)) 4 | map = leaflet(df) 5 | pal1 = colorNumeric('RdBu', df$x1) 6 | pal2 = colorBin('RdBu', df$x2) 7 | pal3 = colorQuantile('BuGn', df$x3) 8 | pal4 = colorFactor('Dark2', df$x4) 9 | 10 | # test syntax 11 | assert( 12 | # either pal or colors, but not both 13 | has_error(addLegend(map, pal = pal1, colors = '#ffffff')), 14 | # values missing when pal is provided 15 | has_error(addLegend(map, pal = pal1)), 16 | # bins is provided when pal is not numeric 17 | has_warning(addLegend(map, pal = pal2, values = ~x2, bins = 10)), 18 | # colors provided, but labels missing 19 | has_error(addLegend(map, colors = '#ffffff')), 20 | # colors and labels not of the same length 21 | has_error(addLegend(map, colors = '#ffffff', labels = c('a', 'b'))) 22 | ) 23 | 24 | getLastLegend = function(map) { 25 | tail(map$x$calls, 1)[[1]]$args[[1]] 26 | } 27 | 28 | # automatic legends 29 | m1 = addLegend(map, pal = pal1, values = ~x1) 30 | l1 = getLastLegend(m1) 31 | assert( 32 | l1$colors == "#67001F , #67001F 0%, #E68367 25%, #F7F7F7 50%, #6EACD1 75%, #053061 100%, #053061 ", 33 | l1$labels == c('1.0', '1.5', '2.0', '2.5', '3.0'), 34 | l1$type == 'numeric' 35 | ) 36 | 37 | m2 = addLegend(map, pal = pal2, values = ~x2) 38 | l2 = getLastLegend(m2) 39 | assert( 40 | l2$colors == c("#CA0020", "#F4A582", "#92C5DE", "#0571B0"), 41 | l2$labels == c('1.0 – 1.5', '1.5 – 2.0', '2.0 – 2.5', '2.5 – 3.0'), 42 | l2$type == 'bin' 43 | ) 44 | 45 | m3 = addLegend(map, pal = pal3, values = ~x3) 46 | l3 = getLastLegend(m3) 47 | assert( 48 | l3$colors == c("#EDF8FB", "#B2E2E2", "#66C2A4", "#238B45"), 49 | l3$labels == c( 50 | '0% – 25%', 51 | '25% – 50%', 52 | '50% – 75%', 53 | '75% – 100%' 54 | ), 55 | l3$type == 'quantile' 56 | ) 57 | 58 | m4 = addLegend(map, pal = pal4, values = ~x4) 59 | l4 = getLastLegend(m4) 60 | assert( 61 | l4$colors == c("#1B9E77", "#D95F02", "#7570B3"), 62 | l4$labels == as.character(df$x4), 63 | l4$type == 'factor' 64 | ) 65 | 66 | # manual legends 67 | m5 = addLegend(map, colors = palette(), labels = palette()) 68 | l5 = getLastLegend(m5) 69 | assert( 70 | l5$colors == palette(), 71 | l5$labels == palette() 72 | ) 73 | 74 | # test the helper function labelFormat() 75 | f = labelFormat( 76 | prefix = 'a', suffix = 'b', between = '--', digits = 1, 77 | transform = function(x) x / 10, big.mark = "'" 78 | ) 79 | assert( 80 | 'labelFormat() works', 81 | identical(f('bin', c(1.234, 2.345)), 'a0.1--0.2b'), 82 | identical(f('bin', c(123456.78, 987654.32)), "a12'345.7--98'765.4b"), 83 | TRUE 84 | ) 85 | -------------------------------------------------------------------------------- /inst/examples/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "id": "rectangle", 7 | "properties": {}, 8 | "geometry": { 9 | "type": "Polygon", 10 | "coordinates": [ 11 | [ 12 | [ 13 | -24.960937499999996, 14 | 43.068887774169625 15 | ], 16 | [ 17 | -24.960937499999996, 18 | 60.23981116999893 19 | ], 20 | [ 21 | 18.28125, 22 | 60.23981116999893 23 | ], 24 | [ 25 | 18.28125, 26 | 43.068887774169625 27 | ], 28 | [ 29 | -24.960937499999996, 30 | 43.068887774169625 31 | ] 32 | ] 33 | ] 34 | } 35 | }, 36 | { 37 | "type": "Feature", 38 | "id": "polygon", 39 | "properties": {}, 40 | "geometry": { 41 | "type": "Polygon", 42 | "coordinates": [ 43 | [ 44 | [ 45 | 60.1171875, 46 | 55.97379820507658 47 | ], 48 | [ 49 | 89.296875, 50 | 37.16031654673677 51 | ], 52 | [ 53 | 77.34374999999999, 54 | 15.284185114076445 55 | ], 56 | [ 57 | 49.92187499999999, 58 | 22.917922936146045 59 | ], 60 | [ 61 | 42.890625, 62 | 47.040182144806664 63 | ], 64 | [ 65 | 60.1171875, 66 | 55.97379820507658 67 | ] 68 | ] 69 | ] 70 | } 71 | }, 72 | { 73 | "type": "Feature", 74 | "id": "marker1", 75 | "properties": {}, 76 | "geometry": { 77 | "type": "Point", 78 | "coordinates": [ 79 | 6.6796875, 80 | 14.944784875088372 81 | ] 82 | } 83 | }, 84 | { 85 | "type": "Feature", 86 | "id": "marker2", 87 | "properties": {}, 88 | "geometry": { 89 | "type": "Point", 90 | "coordinates": [ 91 | -11.25, 92 | 20.3034175184893 93 | ] 94 | } 95 | }, 96 | { 97 | "type": "Feature", 98 | "id": "line", 99 | "properties": {}, 100 | "geometry": { 101 | "type": "LineString", 102 | "coordinates": [ 103 | [ 104 | -36.2109375, 105 | 65.94647177615738 106 | ], 107 | [ 108 | -67.1484375, 109 | 36.5978891330702 110 | ] 111 | ] 112 | } 113 | } 114 | ] 115 | } 116 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/leaflet.awesome-markers.min.js: -------------------------------------------------------------------------------- 1 | (function(window,document,undefined){"use strict";L.AwesomeMarkers={};L.AwesomeMarkers.version="2.0.1";L.AwesomeMarkers.Icon=L.Icon.extend({options:{iconSize:[35,45],iconAnchor:[17,42],popupAnchor:[1,-32],shadowAnchor:[10,12],shadowSize:[36,16],className:"awesome-marker",prefix:"glyphicon",spinClass:"fa-spin",extraClasses:"",icon:"home",markerColor:"blue",iconColor:"white",iconRotate:0,font:"monospace"},initialize:function(options){options=L.Util.setOptions(this,options)},createIcon:function(){var div=document.createElement("div"),options=this.options;if(options.icon){div.innerHTML=this._createInner()}if(options.bgPos){div.style.backgroundPosition=-options.bgPos.x+"px "+-options.bgPos.y+"px"}this._setIconStyles(div,"icon-"+options.markerColor);return div},_createInner:function(){var iconClass,iconSpinClass="",iconColorClass="",iconColorStyle="",options=this.options;if(!options.prefix||options.icon.slice(0,options.prefix.length+1)===options.prefix+"-"){iconClass=options.icon}else{iconClass=options.prefix+"-"+options.icon}if(options.spin&&typeof options.spinClass==="string"){iconSpinClass=options.spinClass}if(options.iconColor){if((options.iconColor==="white"||options.iconColor==="black")&&options.prefix!=="fa"){iconColorClass="icon-"+options.iconColor}else if(options.prefix==="fa"&&options.iconColor==="white"){iconColorClass="fa-inverse"}else{iconColorStyle="color: "+options.iconColor+";"}}if(options.font&&options.text){iconColorStyle+="font-family: "+options.font+";"}if(options.iconRotate&&options.iconRotate!==0){iconColorStyle+="-webkit-transform: rotate("+options.iconRotate+"deg);";iconColorStyle+="-moz-transform: rotate("+options.iconRotate+"deg);";iconColorStyle+="-o-transform: rotate("+options.iconRotate+"deg);";iconColorStyle+="-ms-transform: rotate("+options.iconRotate+"deg);";iconColorStyle+="transform: rotate("+options.iconRotate+"deg);"}if(options.text){return""+options.text+""}return""},_setIconStyles:function(img,name){var options=this.options,size=L.point(options[name==="shadow"?"shadowSize":"iconSize"]),anchor;if(name==="shadow"){anchor=L.point(options.shadowAnchor||options.iconAnchor)}else{anchor=L.point(options.iconAnchor)}if(!anchor&&size){anchor=size.divideBy(2,true)}img.className="awesome-marker-"+name+" "+options.className;if(anchor){img.style.marginLeft=-anchor.x+"px";img.style.marginTop=-anchor.y+"px"}if(size){img.style.width=size.x+"px";img.style.height=size.y+"px"}},createShadow:function(){var div=document.createElement("div");this._setIconStyles(div,"shadow");return div}});L.AwesomeMarkers.icon=function(options){return new L.AwesomeMarkers.Icon(options)}})(this,document); 2 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.awesome-markers/leaflet.awesome-markers.css: -------------------------------------------------------------------------------- 1 | /* 2 | Author: L. Voogdt 3 | License: MIT 4 | Version: 1.0 5 | */ 6 | 7 | /* Marker setup */ 8 | .awesome-marker { 9 | background: url('images/markers-soft.png') no-repeat 0 0; 10 | width: 35px; 11 | height: 46px; 12 | position:absolute; 13 | left:0; 14 | top:0; 15 | display: block; 16 | text-align: center; 17 | } 18 | 19 | .awesome-marker-shadow { 20 | background: url('images/markers-shadow.png') no-repeat 0 0; 21 | width: 36px; 22 | height: 16px; 23 | } 24 | 25 | /* Retina displays */ 26 | @media (min--moz-device-pixel-ratio: 1.5),(-o-min-device-pixel-ratio: 3/2), 27 | (-webkit-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5),(min-resolution: 1.5dppx) { 28 | .awesome-marker { 29 | background-image: url('images/markers-soft@2x.png'); 30 | background-size: 720px 92px; 31 | } 32 | .awesome-marker-shadow { 33 | background-image: url('images/markers-shadow@2x.png'); 34 | background-size: 35px 16px; 35 | } 36 | } 37 | 38 | .awesome-marker i { 39 | color: #333; 40 | margin-top: 10px; 41 | display: inline-block; 42 | font-size: 14px; 43 | } 44 | 45 | .awesome-marker .icon-white { 46 | color: #fff; 47 | } 48 | 49 | /* Colors */ 50 | .awesome-marker-icon-red { 51 | background-position: 0 0; 52 | } 53 | 54 | .awesome-marker-icon-darkred { 55 | background-position: -180px 0; 56 | } 57 | 58 | .awesome-marker-icon-lightred { 59 | background-position: -360px 0; 60 | } 61 | 62 | .awesome-marker-icon-orange { 63 | background-position: -36px 0; 64 | } 65 | 66 | .awesome-marker-icon-beige { 67 | background-position: -396px 0; 68 | } 69 | 70 | .awesome-marker-icon-green { 71 | background-position: -72px 0; 72 | } 73 | 74 | .awesome-marker-icon-darkgreen { 75 | background-position: -252px 0; 76 | } 77 | 78 | .awesome-marker-icon-lightgreen { 79 | background-position: -432px 0; 80 | } 81 | 82 | .awesome-marker-icon-blue { 83 | background-position: -108px 0; 84 | } 85 | 86 | .awesome-marker-icon-darkblue { 87 | background-position: -216px 0; 88 | } 89 | 90 | .awesome-marker-icon-lightblue { 91 | background-position: -468px 0; 92 | } 93 | 94 | .awesome-marker-icon-purple { 95 | background-position: -144px 0; 96 | } 97 | 98 | .awesome-marker-icon-darkpurple { 99 | background-position: -288px 0; 100 | } 101 | 102 | .awesome-marker-icon-pink { 103 | background-position: -504px 0; 104 | } 105 | 106 | .awesome-marker-icon-cadetblue { 107 | background-position: -324px 0; 108 | } 109 | 110 | .awesome-marker-icon-white { 111 | background-position: -576px 0; 112 | } 113 | 114 | .awesome-marker-icon-gray { 115 | background-position: -648px 0; 116 | } 117 | 118 | .awesome-marker-icon-lightgray { 119 | background-position: -612px 0; 120 | } 121 | 122 | .awesome-marker-icon-black { 123 | background-position: -682px 0; 124 | } 125 | 126 | .awesome-marker-square { 127 | background-position-y: -46px; 128 | } 129 | -------------------------------------------------------------------------------- /man/remove.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/controls.R, R/layers.R, R/plugin-measure.R, R/plugin-omnivore.R 3 | \name{removeControl} 4 | \alias{clearControls} 5 | \alias{clearGeoJSON} 6 | \alias{clearGroup} 7 | \alias{clearImages} 8 | \alias{clearMarkerClusters} 9 | \alias{clearMarkers} 10 | \alias{clearPopups} 11 | \alias{clearShapes} 12 | \alias{clearTiles} 13 | \alias{clearTopoJSON} 14 | \alias{remove} 15 | \alias{removeControl} 16 | \alias{removeGeoJSON} 17 | \alias{removeImage} 18 | \alias{removeMarker} 19 | \alias{removeMarkerCluster} 20 | \alias{removeMarkerFromCluster} 21 | \alias{removeMeasure} 22 | \alias{removePopup} 23 | \alias{removeShape} 24 | \alias{removeTiles} 25 | \alias{removeTopoJSON} 26 | \title{Remove elements from a map} 27 | \usage{ 28 | removeControl(map, layerId) 29 | 30 | clearControls(map) 31 | 32 | clearGroup(map, group) 33 | 34 | removeImage(map, layerId) 35 | 36 | clearImages(map) 37 | 38 | removeTiles(map, layerId) 39 | 40 | clearTiles(map) 41 | 42 | removePopup(map, layerId) 43 | 44 | clearPopups(map) 45 | 46 | removeMarker(map, layerId) 47 | 48 | clearMarkers(map) 49 | 50 | removeMarkerCluster(map, layerId) 51 | 52 | clearMarkerClusters(map) 53 | 54 | removeMarkerFromCluster(map, layerId, clusterId) 55 | 56 | removeShape(map, layerId) 57 | 58 | clearShapes(map) 59 | 60 | removeGeoJSON(map, layerId) 61 | 62 | clearGeoJSON(map) 63 | 64 | removeMeasure(map) 65 | 66 | removeTopoJSON(map, layerId) 67 | 68 | clearTopoJSON(map) 69 | } 70 | \arguments{ 71 | \item{map}{a map widget object, possibly created from \code{\link{leaflet}}() 72 | but more likely from \code{\link{leafletProxy}}()} 73 | 74 | \item{layerId}{character vector; the layer id(s) of the item to remove} 75 | 76 | \item{group}{the name of the group whose members should be removed} 77 | 78 | \item{clusterId}{the id of the marker cluster layer} 79 | } 80 | \value{ 81 | the new \code{map} object 82 | } 83 | \description{ 84 | Remove one or more features from a map, identified by \code{layerId}; or, 85 | clear all features of the given type or group. 86 | } 87 | \note{ 88 | When used with a \code{\link{leaflet}}() map object, these functions 89 | don't actually remove the features from the map object, but simply add an 90 | operation that will cause those features to be removed after they are 91 | added. In other words, if you add a polygon \code{"foo"} and the call 92 | \code{removeShape("foo")}, it's not smart enough to prevent the polygon 93 | from being added in the first place; instead, when the map is rendered, the 94 | polygon will be added and then removed. 95 | 96 | For that reason, these functions aren't that useful with \code{leaflet} map 97 | objects and are really intended to be used with \code{\link{leafletProxy}} 98 | instead. 99 | 100 | WMS tile layers are extensions of tile layers, so they can also be removed 101 | or cleared via \code{removeTiles()} or \code{clearTiles()}. 102 | } 103 | 104 | -------------------------------------------------------------------------------- /man/addMeasure.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugin-measure.R 3 | \name{addMeasure} 4 | \alias{addMeasure} 5 | \title{Add a measure control to the map.} 6 | \usage{ 7 | addMeasure(map, position = "topright", primaryLengthUnit = "feet", 8 | secondaryLengthUnit = NULL, primaryAreaUnit = "acres", 9 | secondaryAreaUnit = NULL, activeColor = "#ABE67E", 10 | completedColor = "#C8F2BE", popupOptions = list(className = 11 | "leaflet-measure-resultpopup", autoPanPadding = c(10, 10)), 12 | captureZIndex = 10000, localization = "en", decPoint = ".", 13 | thousandsSep = ",") 14 | } 15 | \arguments{ 16 | \item{map}{a map widget object} 17 | 18 | \item{position}{standard \href{http://leafletjs.com/reference.html#control-positions}{Leaflet control position options}.} 19 | 20 | \item{primaryLengthUnit, secondaryLengthUnit}{units used to display length 21 | results. secondaryLengthUnit is optional. 22 | Valid values are \code{"feet"}, \code{"meters"}, \code{"miles"}, and \code{"kilometers"}.} 23 | 24 | \item{primaryAreaUnit, secondaryAreaUnit}{units used to display area results. 25 | secondaryAreaUnit is optional. Valid values are 26 | \code{"acres"}, \code{"hectares"}, \code{"sqmeters"}, and \code{"sqmiles"}.} 27 | 28 | \item{activeColor}{base color to use for map features rendered while 29 | actively performing a measurement. 30 | Value should be a color represented as a hexadecimal string.} 31 | 32 | \item{completedColor}{base color to use for features generated 33 | from a completed measurement. 34 | Value should be a color represented as a hexadecimal string.} 35 | 36 | \item{popupOptions}{\code{list} of ptions applied to the popup 37 | of the resulting measure feature. 38 | Properties may be any \href{http://leafletjs.com/reference.html#popup-options}{standard Leaflet popup options}.} 39 | 40 | \item{captureZIndex}{Z-index of the marker used to capture measure clicks. 41 | Set this value higher than the z-index of all other map layers to 42 | disable click events on other layers while a measurement is active.} 43 | 44 | \item{localization}{Locale to translate displayed text. 45 | Available locales include en (default), cn, de, es, fr, it, nl, pt, 46 | pt_BR, pt_PT, ru, and tr} 47 | 48 | \item{decPoint}{Decimal point used when displaying measurements. 49 | If not specified, values are defined by the localization.} 50 | 51 | \item{thousandsSep}{Thousands separator used when displaying measurements. 52 | If not specified, values are defined by the localization.} 53 | } 54 | \value{ 55 | modified map 56 | } 57 | \description{ 58 | Add a measure control to the map. 59 | } 60 | \examples{ 61 | library(leaflet) 62 | 63 | leaf <- leaflet() \%>\% 64 | addTiles() \%>\% 65 | # central park 66 | fitBounds( -73.9, 40.75, -73.95, 40.8 ) \%>\% 67 | addMeasure() 68 | 69 | leaf 70 | 71 | # customizing 72 | leaf \%>\% addMeasure( 73 | position = "bottomleft" 74 | , primaryLengthUnit = "meters" 75 | , primaryAreaUnit = "sqmeters" 76 | , activeColor = "#3D535D" 77 | , completedColor = "#7D4479" 78 | , localization = 'de' 79 | ) 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/Leaflet.label/leaflet.label.css: -------------------------------------------------------------------------------- 1 | .leaflet-label { 2 | background: rgb(235, 235, 235); 3 | background: rgba(235, 235, 235, 0.81); 4 | background-clip: padding-box; 5 | border-color: #777; 6 | border-color: rgba(0,0,0,0.45); 7 | border-radius: 4px; 8 | border-style: solid; 9 | border-width: 4px; 10 | color: #111; 11 | display: block; 12 | font: 12px/20px "Helvetica Neue", Arial, Helvetica, sans-serif; 13 | font-weight: bold; 14 | padding: 1px 6px; 15 | position: absolute; 16 | -webkit-user-select: none; 17 | -moz-user-select: none; 18 | -ms-user-select: none; 19 | user-select: none; 20 | pointer-events: none; 21 | white-space: nowrap; 22 | z-index: 500; 23 | } 24 | 25 | .leaflet-label.leaflet-clickable { 26 | cursor: pointer; 27 | pointer-events: auto; 28 | } 29 | 30 | .leaflet-label:before, 31 | .leaflet-label:after { 32 | border-top: 6px solid transparent; 33 | border-bottom: 6px solid transparent; 34 | border-right: 6px solid transparent; 35 | content: none; 36 | position: absolute; 37 | top: 5px; 38 | } 39 | 40 | .leaflet-label:before { 41 | border-right: 6px solid black; 42 | border-right-color: inherit; 43 | left: -10px; 44 | } 45 | 46 | .leaflet-label:after { 47 | border-left: 6px solid black; 48 | border-left-color: inherit; 49 | right: -16px; 50 | } 51 | 52 | .leaflet-label-top:after, 53 | .leaflet-label-top:before { 54 | left: -50%; 55 | border-top-color: black; 56 | border-top-color: rgba(0,0,0,0.45); 57 | position: relative; 58 | top: 29px; 59 | } 60 | 61 | .leaflet-label-top:before { 62 | display: none; 63 | border-right-color: transparent; 64 | border-bottom-color: transparent; 65 | border-left-color: transparent; 66 | border-top-color: transparent; 67 | } 68 | 69 | .leaflet-label-top:after { 70 | content: ' '; 71 | border-right-color: transparent; 72 | border-bottom-color: transparent; 73 | border-left-color: transparent; 74 | } 75 | 76 | .leaflet-label-bottom:before { 77 | display: none; 78 | border-right-color: transparent; 79 | border-bottom-color: transparent; 80 | border-left-color: transparent; 81 | border-top-color: transparent; 82 | } 83 | 84 | .leaflet-label-bottom:after, 85 | .leaflet-label-bottom:before { 86 | left: -50%; 87 | border-bottom-color: black; 88 | border-bottom-color: rgba(0,0,0,0.45); 89 | position: relative; 90 | top: -28px; 91 | } 92 | 93 | .leaflet-label-bottom:after { 94 | border-right-color: transparent; 95 | border-top-color: transparent; 96 | border-left-color: transparent; 97 | } 98 | 99 | .leaflet-label-bottom:after, 100 | .leaflet-label-top:after, 101 | .leaflet-label-right:before, 102 | .leaflet-label-left:after { 103 | content: ""; 104 | } 105 | 106 | .leaflet-label.leaflet-label-text-only, 107 | .leaflet-label.leaflet-label-text-only:before, 108 | .leaflet-label.leaflet-label-text-only:after { 109 | background: none; 110 | border: none; 111 | } 112 | 113 | .leaflet-label.leaflet-label-text-only.leaflet-label-left { 114 | margin-right: -10px; 115 | } 116 | 117 | .leaflet-label.leaflet-label-text-only.leaflet-label-right { 118 | margin-left: -10px; 119 | } 120 | -------------------------------------------------------------------------------- /R/plugin-providers.R: -------------------------------------------------------------------------------- 1 | leafletProviderDependencies <- function() { 2 | list( 3 | htmltools::htmlDependency( 4 | "leaflet-providers", 5 | "1.0.27", 6 | system.file("htmlwidgets/lib/leaflet-providers", package = "leaflet"), 7 | script = "leaflet-providers.js" 8 | ), 9 | htmltools::htmlDependency( 10 | "leaflet-providers-plugin", 11 | packageVersion("leaflet"), 12 | system.file("htmlwidgets/plugins/leaflet-providers-plugin", package = "leaflet"), 13 | script = "leaflet-providers-plugin.js" 14 | ) 15 | ) 16 | } 17 | 18 | #' Add a tile layer from a known map provider 19 | #' 20 | #' @param map the map to add the tile layer to 21 | #' @param provider the name of the provider (see 22 | #' \url{http://leaflet-extras.github.io/leaflet-providers/preview/} and 23 | #' \url{https://github.com/leaflet-extras/leaflet-providers}) 24 | #' @param layerId the layer id to assign 25 | #' @param group the name of the group the newly created layers should belong to 26 | #' (for \code{\link{clearGroup}} and \code{\link{addLayersControl}} purposes). 27 | #' Human-friendly group names are permitted--they need not be short, 28 | #' identifier-style names. 29 | #' @param options tile options 30 | #' @return modified map object 31 | #' 32 | #' @examples 33 | #' leaflet() %>% 34 | #' addProviderTiles("Stamen.Watercolor") %>% 35 | #' addProviderTiles("Stamen.TonerHybrid") 36 | #' 37 | #' @export 38 | addProviderTiles <- function( 39 | map, 40 | provider, 41 | layerId = NULL, 42 | group = NULL, 43 | options = providerTileOptions() 44 | ) { 45 | map$dependencies <- c(map$dependencies, leafletProviderDependencies()) 46 | invokeMethod(map, getMapData(map), 'addProviderTiles', 47 | provider, layerId, group, options) 48 | } 49 | 50 | #' @param 51 | #' errorTileUrl,noWrap,opacity,zIndex,unloadInvisibleTiles,updateWhenIdle,detectRetina,reuseTiles 52 | #' the tile layer options; see 53 | #' \url{http://leafletjs.com/reference.html#tilelayer} 54 | #' @param ... named parameters to add to the options 55 | #' @rdname addProviderTiles 56 | #' @export 57 | providerTileOptions <- function(errorTileUrl = '', noWrap = FALSE, 58 | opacity = NULL, zIndex = NULL, unloadInvisibleTiles = NULL, 59 | updateWhenIdle = NULL, detectRetina = FALSE, reuseTiles = FALSE, ... 60 | ) { 61 | opts <- list(errorTileUrl = errorTileUrl, noWrap = noWrap, 62 | zIndex = zIndex, unloadInvisibleTiles = unloadInvisibleTiles, 63 | updateWhenIdle = updateWhenIdle, detectRetina = detectRetina, 64 | reuseTiles = reuseTiles, ...) 65 | # Don't include opacity=NULL--it overrides the provider's default opacity 66 | if (!is.null(opacity)) 67 | opts$opacity <- opacity 68 | opts 69 | } 70 | 71 | #' Providers 72 | #' 73 | #' List of all providers with their variations 74 | #' 75 | #' @format A list of characters 76 | #' @source \url{https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js} 77 | "providers" 78 | 79 | #' Providers Details 80 | #' 81 | #' List of all providers with their variations and additional info 82 | #' 83 | #' @format A list of lists (JSON) 84 | #' @source \url{https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js} 85 | "providers.details" 86 | 87 | 88 | -------------------------------------------------------------------------------- /inst/htmlwidgets/plugins/Leaflet.Graticule/L.Graticule.js: -------------------------------------------------------------------------------- 1 | /* 2 | Graticule plugin for Leaflet powered maps. 3 | */ 4 | L.Graticule = L.GeoJSON.extend({ 5 | 6 | options: { 7 | style: { 8 | color: '#333', 9 | weight: 1 10 | }, 11 | interval: 20 12 | }, 13 | 14 | initialize: function (options) { 15 | L.Util.setOptions(this, options); 16 | this._layers = {}; 17 | 18 | if (this.options.sphere) { 19 | this.addData(this._getFrame()); 20 | } else { 21 | this.addData(this._getGraticule()); 22 | } 23 | }, 24 | 25 | _getFrame: function() { 26 | return { "type": "Polygon", 27 | "coordinates": [ 28 | this._getMeridian(-180).concat(this._getMeridian(180).reverse()) 29 | ] 30 | }; 31 | }, 32 | 33 | _getGraticule: function () { 34 | var features = [], interval = this.options.interval; 35 | 36 | // Meridians 37 | for (var lng = 0; lng <= 180; lng = lng + interval) { 38 | features.push(this._getFeature(this._getMeridian(lng), { 39 | "name": (lng) ? lng.toString() + "° E" : "Prime meridian" 40 | })); 41 | if (lng !== 0) { 42 | features.push(this._getFeature(this._getMeridian(-lng), { 43 | "name": lng.toString() + "° W" 44 | })); 45 | } 46 | } 47 | 48 | // Parallels 49 | for (var lat = 0; lat <= 90; lat = lat + interval) { 50 | features.push(this._getFeature(this._getParallel(lat), { 51 | "name": (lat) ? lat.toString() + "° N" : "Equator" 52 | })); 53 | if (lat !== 0) { 54 | features.push(this._getFeature(this._getParallel(-lat), { 55 | "name": lat.toString() + "° S" 56 | })); 57 | } 58 | } 59 | 60 | return { 61 | "type": "FeatureCollection", 62 | "features": features 63 | }; 64 | }, 65 | 66 | _getMeridian: function (lng) { 67 | lng = this._lngFix(lng); 68 | var coords = []; 69 | for (var lat = -90; lat <= 90; lat++) { 70 | coords.push([lng, lat]); 71 | } 72 | return coords; 73 | }, 74 | 75 | _getParallel: function (lat) { 76 | var coords = []; 77 | for (var lng = -180; lng <= 180; lng++) { 78 | coords.push([this._lngFix(lng), lat]); 79 | } 80 | return coords; 81 | }, 82 | 83 | _getFeature: function (coords, prop) { 84 | return { 85 | "type": "Feature", 86 | "geometry": { 87 | "type": "LineString", 88 | "coordinates": coords 89 | }, 90 | "properties": prop 91 | }; 92 | }, 93 | 94 | _lngFix: function (lng) { 95 | if (lng >= 180) return 179.999999; 96 | if (lng <= -180) return -179.999999; 97 | return lng; 98 | } 99 | 100 | }); 101 | 102 | L.graticule = function (options) { 103 | return new L.Graticule(options); 104 | }; 105 | -------------------------------------------------------------------------------- /R/normalize-sf.R: -------------------------------------------------------------------------------- 1 | # metaData ---------------------------------------------------------------- 2 | 3 | #' @export 4 | metaData.sf <- function(obj) { 5 | obj 6 | } 7 | 8 | # pointsData -------------------------------------------------------------- 9 | 10 | #' @export 11 | pointData.sf <- function(obj) { 12 | geometry <- obj[[attr(obj, "sf_column")]] 13 | pointData(geometry) 14 | } 15 | 16 | #' @export 17 | pointData.sfc_POINT <- function(obj) { 18 | check_crs(obj) 19 | 20 | structure( 21 | sf_coords(do.call("rbind", obj)), 22 | bbox = sf_bbox(obj) 23 | ) 24 | } 25 | 26 | #' @export 27 | pointData.POINT <- function(obj) { 28 | check_crs(obj) 29 | 30 | bbox <- sf_bbox(obj) 31 | 32 | if (!is.matrix(obj)) { 33 | # st_point can be represented by either a numeric vector or a matrix. 34 | # Normalize to a matrix. 35 | # 36 | # is.matrix(sf::st_point(c(1,1))) # FALSE 37 | # is.matrix(sf::st_point(matrix(c(1, 1), ncol = 2))) # TRUE 38 | obj <- matrix(obj, nrow = 1) 39 | } 40 | 41 | structure( 42 | sf_coords(obj), 43 | bbox = bbox 44 | ) 45 | } 46 | 47 | # polygonData ------------------------------------------------------------- 48 | 49 | #' @export 50 | polygonData.sf <- function(obj) { 51 | polygonData(sf::st_geometry(obj)) 52 | } 53 | 54 | #' @export 55 | polygonData.sfc <- function(obj) { 56 | check_crs(obj) 57 | 58 | structure( 59 | to_multipolygon_list(obj), 60 | bbox = sf_bbox(obj) 61 | ) 62 | } 63 | 64 | #' @export 65 | polygonData.sfg <- function(obj) { 66 | structure( 67 | to_multipolygon_list(obj), 68 | bbox = sf_bbox(obj) 69 | ) 70 | } 71 | 72 | 73 | # helpers ----------------------------------------------------------------- 74 | 75 | check_crs <- function(x) { 76 | crs <- sf::st_crs(x) 77 | 78 | # Don't have enough information to check 79 | if (is.na(crs)) 80 | return() 81 | 82 | if (identical(sf::st_is_longlat(x), FALSE)) { 83 | warning("sf layer is not long-lat data", call. = FALSE) 84 | } 85 | 86 | if (!grepl("+datum=WGS84", crs$proj4string, fixed = TRUE)) { 87 | warning( 88 | "sf layer has inconsistent datum (", crs$proj4string, ").\n", 89 | "Need '+proj=longlat +datum=WGS84'", 90 | call. = FALSE 91 | ) 92 | } 93 | 94 | } 95 | 96 | sf_coords <- function(x) { 97 | stopifnot(is.matrix(x) || inherits(x, "XY")) 98 | structure( 99 | as.data.frame(unclass(x)), 100 | names = c("lng", "lat") 101 | ) 102 | } 103 | 104 | sf_bbox <- function(x) { 105 | structure( 106 | matrix(sf::st_bbox(x), ncol = 2, byrow = FALSE), 107 | dimnames = list(c("lng", "lat"), NULL) 108 | ) 109 | } 110 | 111 | #' @export 112 | to_ring.LINESTRING <- function(x) { 113 | sf_coords(x) 114 | } 115 | 116 | #' @export 117 | to_polygon.POLYGON <- function(x) { 118 | lapply(x, sf_coords) 119 | } 120 | 121 | #' @export 122 | to_multipolygon_list.sfc <- function(x) { 123 | lapply(x, to_multipolygon) 124 | } 125 | 126 | #' @export 127 | to_multipolygon.MULTIPOLYGON <- function(x) { 128 | lapply(x, function(el) { 129 | to_polygon(sf::st_polygon(el)) 130 | }) 131 | } 132 | 133 | #' @export 134 | to_multipolygon.MULTILINESTRING <- function(x) { 135 | lapply(x, function(el) { 136 | to_polygon(sf::st_linestring(el)) 137 | }) 138 | } 139 | -------------------------------------------------------------------------------- /man/addRasterImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/layers.R 3 | \name{addRasterImage} 4 | \alias{addRasterImage} 5 | \alias{projectRasterForLeaflet} 6 | \title{Add a raster image as a layer} 7 | \usage{ 8 | addRasterImage(map, x, colors = "Spectral", opacity = 1, 9 | attribution = NULL, layerId = NULL, group = NULL, project = TRUE, 10 | maxBytes = 4 * 1024 * 1024) 11 | 12 | projectRasterForLeaflet(x) 13 | } 14 | \arguments{ 15 | \item{map}{a map widget object} 16 | 17 | \item{x}{a \code{RasterLayer} object--see \code{\link[raster]{raster}}} 18 | 19 | \item{colors}{the color palette (see \code{\link{colorNumeric}}) or function 20 | to use to color the raster values (hint: if providing a function, set 21 | \code{na.color} to \code{"#00000000"} to make \code{NA} areas transparent)} 22 | 23 | \item{opacity}{the base opacity of the raster, expressed from 0 to 1} 24 | 25 | \item{attribution}{the HTML string to show as the attribution for this layer} 26 | 27 | \item{layerId}{the layer id} 28 | 29 | \item{group}{the name of the group this raster image should belong to (see 30 | the same parameter under \code{\link{addTiles}})} 31 | 32 | \item{project}{if \code{TRUE}, automatically project \code{x} to the map 33 | projection expected by Leaflet (\code{EPSG:3857}); if \code{FALSE}, it's 34 | the caller's responsibility to ensure that \code{x} is already projected, 35 | and that \code{extent(x)} is expressed in WGS84 latitude/longitude 36 | coordinates} 37 | 38 | \item{maxBytes}{the maximum number of bytes to allow for the projected image 39 | (before base64 encoding); defaults to 4MB.} 40 | } 41 | \description{ 42 | Create an image overlay from a \code{RasterLayer} object. \emph{This is only 43 | suitable for small to medium sized rasters}, as the entire image will be 44 | embedded into the HTML page (or passed over the websocket in a Shiny 45 | context). 46 | } 47 | \details{ 48 | The \code{maxBytes} parameter serves to prevent you from accidentally 49 | embedding an excessively large amount of data into your htmlwidget. This 50 | value is compared to the size of the final compressed image (after the raster 51 | has been projected, colored, and PNG encoded, but before base64 encoding is 52 | applied). Set \code{maxBytes} to \code{Inf} to disable this check, but be 53 | aware that very large rasters may not only make your map a large download but 54 | also may cause the browser to become slow or unresponsive. 55 | 56 | By default, the \code{addRasterImage} function will project the RasterLayer 57 | \code{x} to EPSG:3857 using the \code{raster} package's 58 | \code{\link[raster]{projectRaster}} function. This can be a time-consuming 59 | operation for even moderately sized rasters. Upgrading the \code{raster} 60 | package to 2.4 or later will provide a large speedup versus previous 61 | versions. If you are repeatedly adding a particular raster to your Leaflet 62 | maps, you can perform the projection ahead of time using 63 | \code{projectRasterForLeaflet()}, and call \code{addRasterImage} with 64 | \code{project=FALSE}. 65 | } 66 | \examples{ 67 | library(raster) 68 | 69 | r <- raster(xmn=-2.8, xmx=-2.79, ymn=54.04, ymx=54.05, nrows=30, ncols=30) 70 | values(r) <- matrix(1:900, nrow(r), ncol(r), byrow = TRUE) 71 | crs(r) <- CRS("+init=epsg:4326") 72 | 73 | leaflet() \%>\% addTiles() \%>\% 74 | addRasterImage(r, colors = "Spectral", opacity = 0.8) 75 | } 76 | 77 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | leaflet 1.1 2 | -------------------------------------------------------------------------------- 3 | 4 | * Add support for sf 5 | 6 | * Added support for Crosstalk (https://rstudio.github.io/crosstalk/). 7 | 8 | * Added ability to select rectangular region in a map. 9 | 10 | * Added a way for the Map instance to be instantiated via a factory. 11 | 12 | * Added option to highlight polygons on hover. 13 | 14 | * Fixed all isses due to missing or NA data. 15 | 16 | * Made the package extensible. 17 | 18 | * Fixed Issues #288, #261, #283. 19 | 20 | * Added 2 new plugins Proj4Leaflet (PR #294) and EasyButton (PR #295). 21 | 22 | * Upgraded existing plugins to their respective latest versions and added missing/new functionality from those plugins. (PR #293) 23 | 24 | * Added Graticule plugin (PR #293) 25 | 26 | * Upgrade leaflet.js to 0.7.7.1 (PR #359) 27 | 28 | * Color palette improvements. All color palette functions now support viridis palettes ("viridis", "magma", "inferno", and "plasma"). 29 | 30 | * Color palette functions now support reversing the order in which colors are used, via reverse=TRUE. 31 | 32 | * colorFactor no longer interpolates qualitative RColorBrewer palettes, unless the number of factor levels being mapped exceeds the number of colors in the specified RColorBrewer palette. (Issue #300) 33 | 34 | leaflet 1.0.2 35 | -------------------------------------------------------------------------------- 36 | 37 | * When used with `leafletProxy`, `fitBounds` did not return its input object as 38 | output, so magrittr chains would break after `fitBounds` was called. 39 | 40 | * Add addMeasure()/removeMeasure() functions to allow users to measure lines and 41 | areas, via the leaflet-measure plugin by @ljagis. (PR #171. Thanks, Kenton 42 | Russell!) 43 | 44 | * Add `input${mapid}_center` Shiny event. 45 | 46 | * Add support for labels on most layers, that show either statically or on 47 | hover. (PR #181. Thanks Bhaskar Karambelkar!) 48 | 49 | * Add support for markers with configurable colors and icons, via the 50 | Leaflet.awesome-markers plugin by @lvoogdt. See `?addAwesomeMarkers`. 51 | (PR #184. Great work, Bhaskar!) 52 | 53 | * Add support for the Leaflet.Terminator plugin by @joergdietrich. Overlays 54 | day and night regions on a map. See `?addTerminator`. (PR #184, thanks 55 | Bhaskar!) 56 | 57 | * Add support for Leaflet.SimpleGraticule plugin by @ablakey. See 58 | `?addSimpleGraticule`. (PR #184, thanks again Bhaskar!) 59 | 60 | * Add support for Leaflet.MagnifyingGlass plugin by @bbecquet. Adds a 61 | configurable magnifying glass that displays the area under the cursor at an 62 | increased zoom level. See `?addMagnifyingGlass`. (PR #184, still Bhaskar!) 63 | 64 | * Add support for Leaflet-MiniMap plugin by @Norkart. Adds a mini map to the 65 | corner that can be used to see or change the bounds of the main map. See 66 | `?addMiniMap`. (PR #184, Bhaskar again!) 67 | 68 | * `addScaleBar` and related functions added, for showing Leaflet's built-in 69 | scale bar in one of the corners of the map. (PR #201. Thanks Kent Johnson!) 70 | 71 | 72 | leaflet 1.0.1 73 | -------------------------------------------------------------------------------- 74 | 75 | * Fix #242: Compatibility with htmlwidgets 0.6 (thanks byzheng). 76 | 77 | 78 | leaflet 1.0.0 79 | -------------------------------------------------------------------------------- 80 | 81 | * Initial release 82 | 83 | -------------------------------------------------------------------------------- /tests/testit/test-colors.R: -------------------------------------------------------------------------------- 1 | library(testit) 2 | 3 | bw = c("black", "white") 4 | 5 | # Do these cases make sense? 6 | assert( 7 | colorBin(bw, NULL)(1) == "#777777", 8 | colorBin(bw, 1)(1) == "#FFFFFF", 9 | TRUE 10 | ) 11 | 12 | # Outside of domain? Return na.color 13 | suppressWarnings( 14 | assert( 15 | identical("#808080", colorFactor(bw, letters)("foo")), 16 | identical("#808080", colorQuantile(bw, 0:1)(-1)), 17 | identical("#808080", colorQuantile(bw, 0:1)(2)), 18 | identical("#808080", colorNumeric(bw, c(0, 1))(-1)), 19 | identical("#808080", colorNumeric(bw, c(0, 1))(2)), 20 | is.na(colorFactor(bw, letters, na.color = NA)("foo")), 21 | is.na(colorQuantile(bw, 0:1, na.color = NA)(-1)), 22 | is.na(colorQuantile(bw, 0:1, na.color = NA)(2)), 23 | is.na(colorNumeric(bw, c(0, 1), na.color = NA)(-1)), 24 | is.na(colorNumeric(bw, c(0, 1), na.color = NA)(2)), 25 | has_warning(colorFactor(bw, letters, na.color = NA)("foo")), 26 | has_warning(colorQuantile(bw, 0:1, na.color = NA)(-1)), 27 | has_warning(colorQuantile(bw, 0:1, na.color = NA)(2)), 28 | has_warning(colorNumeric(bw, c(0, 1), na.color = NA)(-1)), 29 | has_warning(colorNumeric(bw, c(0, 1), na.color = NA)(2)), 30 | TRUE 31 | ) 32 | ) 33 | 34 | assert( 35 | identical( 36 | c("#000000", "#7F7F7F", "#FFFFFF"), 37 | colorNumeric(colorRamp(bw), NULL)(c(0, 0.5, 1)) 38 | ), 39 | identical( 40 | c("#000000FF", "#777777FF", "#FFFFFFFF", "#FFFFFF00", "blue"), 41 | colorNumeric(c(bw, "#FFFFFF00"), NULL, na.color = "blue", alpha = TRUE)(c(0, 0.25, 0.5, 1, NA)) 42 | ) 43 | ) 44 | 45 | assert( 46 | identical( 47 | c("#000000", "#FFFFFF"), 48 | colorBin(bw, NULL)(c(1,2)) 49 | ), 50 | 51 | identical( 52 | c("#000000", "#FFFFFF"), 53 | colorBin(bw, c(1,2))(c(1,2)) 54 | ), 55 | 56 | identical( 57 | c("#000000", "#FFFFFF"), 58 | colorBin(bw, c(1,2), 2)(c(1,2)) 59 | ), 60 | 61 | identical( 62 | c("#000000", "#FFFFFF"), 63 | colorBin(bw, NULL, bins=c(1,1.5,2))(c(1,2)) 64 | ), 65 | 66 | identical( 67 | c("#000000", "#FFFFFF"), 68 | colorBin(bw, c(1,2), bins=c(1,1.5,2))(c(1,2)) 69 | ), 70 | 71 | TRUE 72 | ) 73 | 74 | assert( 75 | identical( 76 | c("#000000", "#777777", "#FFFFFF"), 77 | colorNumeric(bw, NULL)(1:3) 78 | ), 79 | 80 | identical( 81 | c("#000000", "#777777", "#FFFFFF"), 82 | colorNumeric(bw, c(1:3))(1:3) 83 | ), 84 | 85 | identical( 86 | rev(c("#000000", "#777777", "#FFFFFF")), 87 | colorNumeric(rev(bw), c(1:3))(1:3) 88 | ), 89 | 90 | TRUE 91 | ) 92 | 93 | assert( 94 | 95 | # domain != unique(x) 96 | identical( 97 | c("#000000", "#0E0E0E", "#181818"), 98 | colorFactor(bw, LETTERS)(LETTERS[1:3]) 99 | ), 100 | 101 | # domain == unique(x) 102 | identical( 103 | c("#000000", "#777777", "#FFFFFF"), 104 | colorFactor(bw, LETTERS[1:3])(LETTERS[1:3]) 105 | ), 106 | 107 | # no domain 108 | identical( 109 | c("#000000", "#777777", "#FFFFFF"), 110 | colorFactor(bw, NULL)(LETTERS[1:3]) 111 | ), 112 | 113 | # Non-factor domains are sorted unless instructed otherwise 114 | identical( 115 | c("#000000", "#777777", "#FFFFFF"), 116 | colorFactor(bw, rev(LETTERS[1:3]))(LETTERS[1:3]) 117 | ), 118 | identical( 119 | rev(c("#000000", "#777777", "#FFFFFF")), 120 | colorFactor(bw, rev(LETTERS[1:3]), ordered = TRUE)(LETTERS[1:3]) 121 | ), 122 | 123 | TRUE 124 | ) 125 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-measure/leaflet-measure.css: -------------------------------------------------------------------------------- 1 | .leaflet-control-measure h3,.leaflet-measure-resultpopup h3{margin:0 0 12px 0;padding-bottom:10px;line-height:1em;font-weight:normal;font-size:1.1em;border-bottom:solid 1px #DDD}.leaflet-control-measure p,.leaflet-measure-resultpopup p{margin:10px 0 0;line-height:1em}.leaflet-control-measure p:first-child,.leaflet-measure-resultpopup p:first-child{margin-top:0}.leaflet-control-measure a,.leaflet-measure-resultpopup a{color:#5E66CC;text-decoration:none}.leaflet-control-measure a:hover,.leaflet-measure-resultpopup a:hover{opacity:0.5;text-decoration:none}.leaflet-control-measure .tasks,.leaflet-measure-resultpopup .tasks{margin:12px 0 0;padding:10px 0 0;border-top:solid 1px #DDD;list-style:none;list-style-image:none}.leaflet-control-measure .tasks li,.leaflet-measure-resultpopup .tasks li{display:inline;margin:0 10px 0 0}.leaflet-control-measure .tasks li:last-child,.leaflet-measure-resultpopup .tasks li:last-child{margin-right:0}.leaflet-control-measure .coorddivider,.leaflet-measure-resultpopup .coorddivider{color:#999}.leaflet-control-measure{background:#fff;border-radius:5px;box-shadow:0 1px 5px rgba(0,0,0,0.4)}.leaflet-control-measure .leaflet-control-measure-toggle,.leaflet-control-measure .leaflet-control-measure-toggle:hover{display:block;width:36px;height:36px;background-position:50% 50%;background-repeat:no-repeat;background-image:url(images/rulers.png);border-radius:5px;text-indent:100%;white-space:nowrap;overflow:hidden}.leaflet-retina .leaflet-control-measure .leaflet-control-measure-toggle,.leaflet-retina .leaflet-control-measure .leaflet-control-measure-toggle:hover{background-image:url(images/rulers_@2X.png);background-size:16px 16px}.leaflet-touch .leaflet-control-measure .leaflet-control-measure-toggle,.leaflet-touch .leaflet-control-measure .leaflet-control-measure-toggle:hover{width:44px;height:44px}.leaflet-control-measure .startprompt h3{margin-bottom:10px}.leaflet-control-measure .startprompt .tasks{margin-top:0;padding-top:0;border-top:0}.leaflet-control-measure .leaflet-control-measure-interaction{padding:10px 12px}.leaflet-control-measure .results .group{margin-top:10px;padding-top:10px;border-top:dotted 1px #eaeaea}.leaflet-control-measure .results .group:first-child{margin-top:0;padding-top:0;border-top:0}.leaflet-control-measure .results .heading{margin-right:5px;color:#999}.leaflet-control-measure a.start{padding-left:18px;background-repeat:no-repeat;background-position:0% 50%;background-image:url(images/start.png)}.leaflet-retina .leaflet-control-measure a.start{background-image:url(images/start_@2X.png);background-size:12px 12px}.leaflet-control-measure a.cancel{padding-left:18px;background-repeat:no-repeat;background-position:0% 50%;background-image:url(images/cancel.png)}.leaflet-retina .leaflet-control-measure a.cancel{background-image:url(images/cancel_@2X.png);background-size:12px 12px}.leaflet-control-measure a.finish{padding-left:18px;background-repeat:no-repeat;background-position:0% 50%;background-image:url(images/check.png)}.leaflet-retina .leaflet-control-measure a.finish{background-image:url(images/check_@2X.png);background-size:12px 12px}.leaflet-measure-resultpopup a.zoomto{padding-left:18px;background-repeat:no-repeat;background-position:0% 50%;background-image:url(images/focus.png)}.leaflet-retina .leaflet-measure-resultpopup a.zoomto{background-image:url(images/focus_@2X.png);background-size:12px 12px}.leaflet-measure-resultpopup a.deletemarkup{padding-left:18px;background-repeat:no-repeat;background-position:0% 50%;background-image:url(images/trash.png)}.leaflet-retina .leaflet-measure-resultpopup a.deletemarkup{background-image:url(images/trash_@2X.png);background-size:11px 12px} 2 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/leaflet-providers/README.md: -------------------------------------------------------------------------------- 1 | Leaflet-providers 2 | ================= 3 | An extension to [Leaflet](http://leafletjs.com/) that contains configurations for various free[1](#what-is-free) tile providers. 4 | 5 | # Usage 6 | Leaflet-providers [providers](#providers) are refered to with a `provider[.]`-string. Let's say you want to add the nice [Watercolor](http://maps.stamen.com/#watercolor/) style from Stamen to your map, you pass `Stamen.Watercolor` to the `L.tileLayer.provider`-constructor, which will return a [L.TileLayer](http://leafletjs.com/reference.html#tilelayer) instance for Stamens Watercolor tile layer. 7 | 8 | ```Javascript 9 | // add Stamen Watercolor to map. 10 | L.tileLayer.provider('Stamen.Watercolor').addTo(map); 11 | ``` 12 | 13 | ## Protocol relativity (`https://`-urls) 14 | 15 | Leaflet-providers tries to use `https://` if the page uses `https://` and the provider supports it. 16 | You can force the use of `http://` by passing `force_http: true` in the options argument. 17 | 18 | ## Retina tiles 19 | 20 | Some providers have retina tiles for which the URL only needs to be slightly adjusted, e.g. `-----@2x.png`. For this, add the retina option in the URL, e.g. `-----{retina}.png`, and set a retina value in the options, e.g. `retina: '@2x'`. If Leaflet detects a retina screen (`L.Browser.retina`), the retina option passed to the tileLayer is set to the value supplied, otherwise it's replaced by an empty string. 21 | 22 | # Providers 23 | 24 | Leaflet-providers provides tile layers from different providers, including *OpenStreetMap*, *Stamen*, *Esri* and *OpenWeatherMap*. The full listing of free to use layers can be [previewed](http://leaflet-extras.github.io/leaflet-providers/preview/index.html). The page will show you the name to use with `leaflet-providers.js` and the code to use it without dependencies. 25 | 26 | ## Providers requiring registration 27 | 28 | In addition to the providers you are free1 to use, we support some layers which require registration. 29 | 30 | ### HERE (formerly Nokia). 31 | 32 | In order to use HERE layers, you must [register](http://developer.here.com/). Once registered, you can create an `app_id` and `app_code` which you have to pass to `L.tileLayer.provider` in the options: 33 | 34 | ```Javascript 35 | L.tileLayer.provider('HERE.terrainDay', { 36 | app_id: '', 37 | app_code: '' 38 | }).addTo(map); 39 | ``` 40 | 41 | [Available HERE layers](http://leaflet-extras.github.io/leaflet-providers/preview/#filter=HERE) 42 | 43 | ### Mapbox 44 | 45 | In order to use Mapbox maps, you must [register](https://tiles.mapbox.com/signup). You can get map ID and ACCESS_TOKEN from [Mapbox projects](https://www.mapbox.com/projects): 46 | ```JavaScript 47 | L.tileLayer.provider('MapBox', {id: 'ID', accessToken: 'ACCESS_TOKEN'}).addTo(map); 48 | ``` 49 | 50 | ### Esri/ArcGIS 51 | 52 | In order to use ArcGIS maps, you must [register](https://developers.arcgis.com/en/sign-up/) and abide by the [terms of service](https://developers.arcgis.com/en/terms/). No special syntax is required. 53 | 54 | [Available Esri layers](http://leaflet-extras.github.io/leaflet-providers/preview/#filter=Esri) 55 | 56 | # Attribution 57 | 58 | This work was inspired from , and originally created by [Stefan Seelmann](https://github.com/seelmann). 59 | 60 | ### What do we mean by *free*? 61 | 1 62 | We try to maintain leaflet-providers in such a way that you'll be able to use the layers we include without paying money. 63 | This doesn't mean no limits apply, you should always check before using these layers for anything serious. 64 | --------------------------------------------------------------------------------