Skip to content

Commit

Permalink
leaflet.glify to leafgl
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-salabim committed Jan 12, 2019
1 parent 529c500 commit faed3e4
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 142 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,4 +1,4 @@
Package: leaflet.glify
Package: leafgl
Type: Package
Title: Bindings for Leaflet.glify
Version: 0.1.1
Expand Down
8 changes: 4 additions & 4 deletions NAMESPACE
@@ -1,9 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(addGlifyPoints)
export(addGlifyPolygons)
export(glifyOutput)
export(renderGlify)
export(addGlPoints)
export(addGlPolygons)
export(leafglOutput)
export(renderLeafgl)
importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(leaflet,leafletOutput)
Expand Down
6 changes: 3 additions & 3 deletions R/glify-helpers.R
Expand Up @@ -4,7 +4,7 @@ glifyDependencies = function() {
htmltools::htmlDependency(
"addGlifyPoints",
'0.0.1',
system.file("htmlwidgets/Leaflet.glify", package = "leaflet.glify"),
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPoints.js",
"addGlifyPolygons.js",
Expand Down Expand Up @@ -34,7 +34,7 @@ glifyDependenciesFl = function() {
htmltools::htmlDependency(
"addGlifyPoints",
'0.0.1',
system.file("htmlwidgets/Leaflet.glify", package = "leaflet.glify"),
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPoints.js",
"addGlifyPolygonsFl.js",
Expand Down Expand Up @@ -64,7 +64,7 @@ glifyDependenciesSrc = function() {
htmltools::htmlDependency(
"addGlifyPoints",
'0.0.1',
system.file("htmlwidgets/Leaflet.glify", package = "leaflet.glify"),
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPoints.js",
"addGlifyPolygonsSrc.js",
Expand Down
72 changes: 36 additions & 36 deletions R/glify-points.R
Expand Up @@ -15,12 +15,12 @@
#' @param popup the name of the column in data to be used for popups.
#' @param ... ignored.
#'
#' @describeIn addGlifyPoints add points to a leaflet map using Leaflet.glify
#' @describeIn addGlPoints add points to a leaflet map using Leaflet.glify
#' @examples
#' \dontrun{
#' library(mapview)
#' library(leaflet)
#' library(leaflet.glify)
#' library(leafgl)
#' library(sf)
#' library(colourvalues)
#' library(jsonlite)
Expand All @@ -39,23 +39,23 @@
#' system.time({
#' m = leaflet() %>%
#' addProviderTiles(provider = providers$CartoDB.DarkMatter) %>%
#' addGlifyPoints(data = pts, color = cols, popup = "id") %>%
#' addGlPoints(data = pts, color = cols, popup = "id") %>%
#' addMouseCoordinates() %>%
#' setView(lng = 10.5, lat = 49.5, zoom = 9)
#' })
#'
#' m
#' }
#'
#' @export
addGlifyPoints = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {
#' @export addGlPoints
addGlPoints = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {

if (is.null(group)) group = deparse(substitute(data))
if (inherits(data, "Spatial")) data <- sf::st_as_sf(data)
Expand Down Expand Up @@ -96,14 +96,14 @@ addGlifyPoints = function(map,
}

### via src
addGlifyPointsSrc = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {
addGlPointsSrc = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {

if (is.null(group)) group = deparse(substitute(data))
if (inherits(data, "Spatial")) data <- sf::st_as_sf(data)
Expand Down Expand Up @@ -171,14 +171,14 @@ addGlifyPointsSrc = function(map,


### via src
addGlifyPointsSrc2 = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {
addGlPointsSrc2 = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {

if (is.null(group)) group = deparse(substitute(data))
if (inherits(data, "Spatial")) data <- sf::st_as_sf(data)
Expand Down Expand Up @@ -256,14 +256,14 @@ addGlifyPointsSrc2 = function(map,


### via attachments
addGlifyPointsFl = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {
addGlPointsFl = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 1,
weight = 10,
group = "glpoints",
popup = NULL,
...) {

if (is.null(group)) group = deparse(substitute(data))
if (inherits(data, "Spatial")) data <- sf::st_as_sf(data)
Expand Down
61 changes: 30 additions & 31 deletions R/glify-polygons.R
Expand Up @@ -8,7 +8,7 @@
#' \dontrun{
#' library(mapview)
#' library(leaflet)
#' library(leaflet.glify)
#' library(leafgl)
#' library(sf)
#' library(colourvalues)
#'
Expand All @@ -20,22 +20,21 @@
#'
#' leaflet() %>%
#' addProviderTiles(provider = providers$CartoDB.DarkMatter) %>%
#' addGlifyPolygons(data = fran, color = cols) %>%
#' addGlPolygons(data = fran, color = cols) %>%
#' addMouseCoordinates() %>%
#' setView(lng = 10.5, lat = 49.5, zoom = 8)
#' }
#'
#' @describeIn addGlifyPoints add polygons to a leaflet map using Leaflet.glify
#' @aliases addGlifyPolygons
#' @export addGlifyPolygons
addGlifyPolygons = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 0.6,
weight = 10,
group = "glpolygons",
popup = NULL,
...) {
#' @describeIn addGlPoints add polygons to a leaflet map using Leaflet.glify
#' @aliases addGlPolygons
#' @export addGlPolygons
addGlPolygons = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 0.6,
group = "glpolygons",
popup = NULL,
...) {

if (is.null(group)) group = deparse(substitute(data))
if (inherits(data, "Spatial")) data <- sf::st_as_sf(data)
Expand Down Expand Up @@ -68,20 +67,20 @@ addGlifyPolygons = function(map,
)

leaflet::invokeMethod(map, leaflet::getMapData(map), 'addGlifyPolygons',
data, cols, popup, opacity, weight, group)
data, cols, popup, opacity, group)

}


### via src
addGlifyPolygonsSrc = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 0.6,
weight = 10,
group = "glpolygons",
popup = NULL,
...) {
addGlPolygonsSrc = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 0.6,
weight = 10,
group = "glpolygons",
popup = NULL,
...) {

if (is.null(group)) group = deparse(substitute(data))
if (inherits(data, "Spatial")) data <- sf::st_as_sf(data)
Expand Down Expand Up @@ -156,14 +155,14 @@ addGlifyPolygonsSrc = function(map,


### via attachments
addGlifyPolygonsFl = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 0.6,
weight = 10,
group = "glpolygons",
popup = NULL,
...) {
addGlPolygonsFl = function(map,
data,
color = cbind(0, 0.2, 1),
opacity = 0.6,
weight = 10,
group = "glpolygons",
popup = NULL,
...) {

if (is.null(group)) group = deparse(substitute(data))
if (inherits(data, "Spatial")) data <- sf::st_as_sf(data)
Expand Down Expand Up @@ -229,6 +228,6 @@ addGlifyPolygonsFl = function(map,
# }

leaflet::invokeMethod(map, leaflet::getMapData(map), 'addGlifyPolygonsFl',
data_var, color_var, popup, opacity, weight)
data_var, color_var, popup, opacity)

}
22 changes: 11 additions & 11 deletions R/glify-shiny.R
@@ -1,16 +1,16 @@
#' Use Glify in shiny
#' Use leafgl in shiny
#'
#' @inheritParams leaflet::leafletOutput
#' @importFrom leaflet leafletOutput
#' @importFrom htmltools tagList tags
#' @return A UI for rendering Glify
#' @return A UI for rendering leafgl
#' @export
#'
#' @examples
#' \dontrun{
#' library(mapview)
#' library(leaflet)
#' library(leaflet.glify)
#' library(leafgl)
#' library(sf)
#'
#' n = 1e4
Expand All @@ -27,7 +27,7 @@
#' addLayersControl(overlayGroups = "pts")
#'
#' ui <- fluidPage(
#' glifyOutput("mymap")
#' leafglOutput("mymap")
#' )
#'
#' server <- function(input, output, session) {
Expand All @@ -38,7 +38,7 @@
#' }
#'

glifyOutput <- function(outputId, width = "100%", height = 400){
leafglOutput <- function(outputId, width = "100%", height = 400){
tagList(
leafletOutput(outputId = outputId, width = width, height = height),
tags$script(glifyDependencies())
Expand All @@ -47,20 +47,20 @@ glifyOutput <- function(outputId, width = "100%", height = 400){

# Just for consistency
#
#' Use Glify in shiny
#' Use leafgl in shiny
#'
#' @importFrom leaflet renderLeaflet
#'
#' @inheritParams leaflet::renderLeaflet
#'
#' @return A server function for rendering Glify
#' @return A server function for rendering leafgl
#' @export
#'
#' @examples
#' \dontrun{
#' library(mapview)
#' library(leaflet)
#' library(leaflet.glify)
#' library(leafgl)
#' library(sf)
#' library(shiny)
#'
Expand All @@ -72,13 +72,13 @@ glifyOutput <- function(outputId, width = "100%", height = 400){
#'
#' m = leaflet() %>%
#' addProviderTiles(provider = providers$CartoDB.DarkMatter) %>%
#' addGlifyPoints(data = pts, group = "pts") %>%
#' addGlPoints(data = pts, group = "pts") %>%
#' addMouseCoordinates() %>%
#' setView(lng = 10.5, lat = 49.5, zoom = 6) %>%
#' addLayersControl(overlayGroups = "pts")
#'
#' ui <- fluidPage(
#' glifyOutput("mymap")
#' leafglOutput("mymap")
#' )
#'
#' server <- function(input, output, session) {
Expand All @@ -88,7 +88,7 @@ glifyOutput <- function(outputId, width = "100%", height = 400){
#' shinyApp(ui, server)
#' }
#'
renderGlify <- function(expr, env = parent.frame(), quoted = FALSE){
renderLeafgl <- function(expr, env = parent.frame(), quoted = FALSE){
renderLeaflet(expr = expr, env = env, quoted = quoted)
}

0 comments on commit faed3e4

Please sign in to comment.