Skip to content

Fix labels/border/remove/clear-instances, **Src-functions, etc.. #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
88ea86c
add args popup/labelOptions, fix labels, add dotlist to glify (sensit…
trafficonese Jun 3, 2024
ca4213a
move JS helper functions to sep file use const/let
trafficonese Jun 3, 2024
a100d37
fix remove/clear methods by layerId/group/all Glify, expose new metho…
trafficonese Jun 5, 2024
1135858
fix: allow layerId to be formula
trafficonese Jun 5, 2024
e6dbde3
move imports to separate pkg-file
trafficonese Jun 5, 2024
806bb8f
fix labels/popup for *Src functions, move Point click/Hover Functions…
trafficonese Jun 8, 2024
c5c9f37
convert_to_json function to try yyjsonr::write_json_str or jsonify::t…
trafficonese Jun 8, 2024
efb51c0
simplify/unify dependency calls
trafficonese Jun 8, 2024
1e95b55
allow custom json_parser_function
trafficonese Jun 8, 2024
706e10e
fixed hoverwait: 10, docs
trafficonese Jun 9, 2024
c3c3a97
use yyjsonr for geojson, expose new option "leafgl_geojson_parser"
trafficonese Jun 11, 2024
b509362
use yyjonsr instead of jsonify/geojsonsf, use correct options, fix te…
trafficonese Jun 11, 2024
af381dd
update Glify to 3.3.0, remove arr.splice workaround, remove tooltip i…
trafficonese Jun 22, 2024
3e9d39c
hoveroff_event JS-func, use .nonce to trigger event
trafficonese Jun 23, 2024
f978f87
Merge branch 'master' into fixlabels
trafficonese Nov 29, 2024
b8691d4
update Glify,update Roxygen, fix .Rproj error
trafficonese Jan 8, 2025
b064140
pull
trafficonese Jan 8, 2025
f2bb497
use Leaflet.Glify 3.3.1
trafficonese Apr 5, 2025
0cccb13
chore: use gha v4
trafficonese Apr 5, 2025
6a6a223
chore: use gha v4 for upload
trafficonese Apr 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions R/glify-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,42 @@ glifyDependenciesFl = function() {
)
)
}



json_funccall <- function() {
json_parser <- getOption("leafgl_json_parser", "jsonify") # Default to jsonify
if (json_parser == "yyjsonr") {
yyjsonr::write_json_str
} else {
jsonify::to_json
}
}
convert_to_json <- function(data, ...) {
json_parser <- getOption("leafgl_json_parser", "jsonify") # Default to jsonify
if (json_parser == "yyjsonr") {
print("I am using yyjsonr")
json_data <- yyjsonr::write_json_str(data, ...)
class(json_data) <- "json"
} else {
print("I am using jsonify")
json_data <- jsonify::to_json(data, ...)
}
return(json_data)
}

## Not used as its not faster - Needs geometries to be the last column and be named geometry
yyjsonr_2_geojson <- function(sfdata) {
# sfdata <- data
geom <- st_geometry(sfdata)
sfdata <- st_drop_geometry(sfdata)
sfdata$geometry <- geom
sfdata <- sf::st_as_sf(sfdata)
json_data <- yyjsonr::write_json_str(sfdata, digits=4)
json_data <- gsub("]}]", "]}}]}", fixed = TRUE,
paste0('{"type":"FeatureCollection","features":[{"type":"Feature","properties":',
gsub('","geometry":', '"},"geometry":{"type":"Polygon","coordinates":',
substr(json_data, 2, nchar(json_data)), fixed = TRUE)))
class(json_data) <- "geojson"
json_data
}
15 changes: 6 additions & 9 deletions R/glify-lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ addGlPolylines = function(map,
if (ncol(color) != 3) stop("only 3 column color matrix supported so far")
color = as.data.frame(color, stringsAsFactors = FALSE)
colnames(color) = c("r", "g", "b")
cols = jsonify::to_json(color, digits = 3)
cols = convert_to_json(color, digits = 3)

# label / popup ########
labels <- leaflet::evalFormula(label, data)
Expand All @@ -96,8 +96,7 @@ addGlPolylines = function(map,
htmldeps
)
}
popup = makePopup(popup, data)
popup = jsonify::to_json(popup)
popup = convert_to_json(makePopup(popup, data))
geom = sf::st_geometry(data)
data = sf::st_sf(id = 1:length(geom), geometry = geom)
}
Expand Down Expand Up @@ -221,7 +220,7 @@ addGlPolylinesSrc = function(map,
fl_color = paste0(dir_color, "/", group, "_color.js")
pre = paste0('var col = col || {}; col["', group, '"] = ')
writeLines(pre, fl_color)
cat('[', jsonify::to_json(color), '];',
cat('[', convert_to_json(color, digits = 3), '];',
file = fl_color, append = TRUE)

map$dependencies = c(
Expand All @@ -233,11 +232,10 @@ addGlPolylinesSrc = function(map,

# labels ############
if (!is.null(label)) {
labels <- leaflet::evalFormula(label, data_orig)
fl_label = paste0(dir_labels, "/", group, "_label.js")
pre = paste0('var labs = labs || {}; labs["', group, '"] = ')
writeLines(pre, fl_label)
cat('[', jsonify::to_json(labels), '];',
cat('[', convert_to_json(leaflet::evalFormula(label, data_orig)), '];',
file = fl_label, append = TRUE)

map$dependencies = c(
Expand All @@ -256,11 +254,10 @@ addGlPolylinesSrc = function(map,
htmldeps
)
}
popup = makePopup(popup, data_orig)
fl_popup = paste0(dir_popup, "/", group, "_popup.js")
pre = paste0('var pops = pops || {}; pops["', group, '"] = ')
writeLines(pre, fl_popup)
cat('[', jsonify::to_json(popup), '];',
cat('[', convert_to_json(makePopup(popup, data_orig)), '];',
file = fl_popup, append = TRUE)

map$dependencies = c(
Expand All @@ -275,7 +272,7 @@ addGlPolylinesSrc = function(map,
fl_weight = paste0(dir_weight, "/", group, "_weight.js")
pre = paste0('var wgt = wgt || {}; wgt["', group, '"] = ')
writeLines(pre, fl_weight)
cat('[', jsonify::to_json(weight), '];',
cat('[', convert_to_json(weight), '];',
file = fl_weight, append = TRUE)

map$dependencies = c(
Expand Down
22 changes: 10 additions & 12 deletions R/glify-points.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ addGlPoints = function(map,
dotopts = list(...)
bounds = as.numeric(sf::st_bbox(data))

# fillColor ###########
# color ###########
palette = "viridis"
if ("palette" %in% names(dotopts)) {
palette <- dotopts$palette
Expand All @@ -147,7 +147,7 @@ addGlPoints = function(map,
if (ncol(fillColor) != 3) stop("only 3 column fillColor matrix supported so far")
fillColor = as.data.frame(fillColor, stringsAsFactors = FALSE)
colnames(fillColor) = c("r", "g", "b")
fillColor = jsonify::to_json(fillColor)
fillColor = convert_to_json(fillColor, digits = 3)

# label / popup ###########
labels <- leaflet::evalFormula(label, data)
Expand All @@ -159,8 +159,7 @@ addGlPoints = function(map,
htmldeps
)
}
popup = makePopup(popup, data)
popup = jsonify::to_json(popup)
popup = convert_to_json(makePopup(popup, data))
} else {
popup = NULL
}
Expand All @@ -173,14 +172,15 @@ addGlPoints = function(map,
jsonify_args = try(
match.arg(
names(dotopts)
, names(as.list(args(jsonify::to_json)))
, names(as.list(args(json_funccall)))
, several.ok = TRUE
)
, silent = TRUE
)
}
if (inherits(jsonify_args, "try-error")) jsonify_args = NULL
data = do.call(jsonify::to_json, c(list(crds), dotopts[jsonify_args]))
data = do.call(json_funccall(), c(list(crds), dotopts[jsonify_args]))
class(data) <- "json"

# dependencies
map$dependencies = c(map$dependencies, glifyDependencies())
Expand Down Expand Up @@ -284,7 +284,7 @@ addGlPointsSrc = function(map,
fl_color = paste0(dir_color, "/", group, "_color.js")
pre = paste0('var col = col || {}; col["', group, '"] = ')
writeLines(pre, fl_color)
cat('[', jsonify::to_json(fillColor), '];',
cat('[', convert_to_json(fillColor, digits = 3), '];',
file = fl_color, append = TRUE)

map$dependencies = c(
Expand All @@ -296,11 +296,10 @@ addGlPointsSrc = function(map,

# labels ############
if (!is.null(label)) {
labels <- leaflet::evalFormula(label, data)
fl_label = paste0(dir_labels, "/", group, "_label.js")
pre = paste0('var labs = labs || {}; labs["', group, '"] = ')
writeLines(pre, fl_label)
cat('[', jsonify::to_json(labels), '];',
cat('[', convert_to_json(leaflet::evalFormula(label, data)), '];',
file = fl_label, append = TRUE)

map$dependencies = c(
Expand All @@ -319,11 +318,10 @@ addGlPointsSrc = function(map,
htmldeps
)
}
popup = makePopup(popup, data)
fl_popup = paste0(dir_popup, "/", group, "_popup.js")
pre = paste0('var pops = pops || {}; pops["', group, '"] = ')
writeLines(pre, fl_popup)
cat('[', jsonify::to_json(popup), '];',
cat('[', convert_to_json(makePopup(popup, data)), '];',
file = fl_popup, append = TRUE)

map$dependencies = c(
Expand All @@ -338,7 +336,7 @@ addGlPointsSrc = function(map,
fl_radius = paste0(dir_radius, "/", layerId, "_radius.js")
pre = paste0('var rad = rad || {}; rad["', layerId, '"] = ')
writeLines(pre, fl_radius)
cat('[', jsonify::to_json(radius), '];',
cat('[', convert_to_json(radius), '];',
file = fl_radius, append = TRUE)

map$dependencies = c(
Expand Down
13 changes: 5 additions & 8 deletions R/glify-polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ addGlPolygons = function(map,
if (ncol(fillColor) != 3) stop("only 3 column fillColor matrix supported so far")
fillColor = as.data.frame(fillColor, stringsAsFactors = FALSE)
colnames(fillColor) = c("r", "g", "b")
cols = jsonify::to_json(fillColor, digits = 3)
cols = convert_to_json(fillColor, digits = 3)

# label / popup ###########
labels <- leaflet::evalFormula(label, data)
Expand All @@ -100,8 +100,7 @@ addGlPolygons = function(map,
htmldeps
)
}
popup = makePopup(popup, data)
popup = jsonify::to_json(popup)
popup = convert_to_json(makePopup(popup, data))
geom = sf::st_geometry(data)
data = sf::st_sf(id = 1:length(geom), geometry = geom)
}
Expand Down Expand Up @@ -226,7 +225,7 @@ addGlPolygonsSrc = function(map,
fl_color = paste0(dir_color, "/", group, "_color.js")
pre = paste0('var col = col || {}; col["', group, '"] = ')
writeLines(pre, fl_color)
cat('[', jsonify::to_json(fillColor), '];',
cat('[', convert_to_json(fillColor, digits = 3), '];',
file = fl_color, append = TRUE)

map$dependencies = c(
Expand All @@ -239,11 +238,10 @@ addGlPolygonsSrc = function(map,

# labels ############
if (!is.null(label)) {
labels <- leaflet::evalFormula(label, data_orig)
fl_label = paste0(dir_labels, "/", group, "_label.js")
pre = paste0('var labs = labs || {}; labs["', group, '"] = ')
writeLines(pre, fl_label)
cat('[', jsonify::to_json(labels), '];',
cat('[', convert_to_json(leaflet::evalFormula(label, data_orig)), '];',
file = fl_label, append = TRUE)

map$dependencies = c(
Expand All @@ -262,11 +260,10 @@ addGlPolygonsSrc = function(map,
htmldeps
)
}
popup = makePopup(popup, data_orig)
fl_popup = paste0(dir_popup, "/", group, "_popup.js")
pre = paste0('var pops = pops || {}; pops["', group, '"] = ')
writeLines(pre, fl_popup)
cat('[', jsonify::to_json(popup), '];',
cat('[', convert_to_json(makePopup(popup, data_orig)), '];',
file = fl_popup, append = TRUE)

map$dependencies = c(
Expand Down