Skip to content
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

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Description: Provides bindings to the 'Leaflet.glify' JavaScript library which e
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: false
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Imports:
geojsonsf,
htmltools,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ S3method(makePopup,shiny.tag)
export(addGlPoints)
export(addGlPolygons)
export(addGlPolylines)
export(clearGlGroup)
export(clearGlLayers)
export(leafglOutput)
export(makeColorMatrix)
Expand All @@ -37,5 +38,6 @@ export(renderLeafgl)
importFrom(htmltools,htmlDependencies)
importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(leaflet,evalFormula)
importFrom(leaflet,leafletOutput)
importFrom(leaflet,renderLeaflet)
13 changes: 13 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ leafgl 0.2.1.9005 (2023-09-08)

features and improvements

* New method *clearGlGroup* removes a group from leaflet and the Leaflet.Glify instances.
* The JavaScript methods of the `removeGl**` functions was rewritten to correctly remove an element identified by `layerId`
* `clearGlLayers` now correctly removes all Leaflet.Glify instances
* When showing/hiding Leaflet.Glify layers, they are set to active = TRUE/FALSE to make mouseevents work again. #48, #50

bug fixes

* src version now works also in shiny. #71
* added `popupOptions` and `labelOptions`. #83
* added `stroke` (default=TRUE) in `addGlPolygons` and `addGlPolygonsSrc` for drawing borders. #3
* Labels work similar to `leaflet`. `leafgl` accepts a single string, a vector of strings or a formula. #78
* The `...` arguments are now passed to all methods in the underlying library. This allows us to set
additional arguments like `fragmentShaderSource`, `sensitivity` or `sensitivityHover`.

documentation etc

* Added some @details for Shiny click and mouseover events and their corresponding input. #77
* Use `@inheritParams leaflet::**` for identical function arguments

miscellaneous


Expand Down
62 changes: 58 additions & 4 deletions R/glify-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ glifyDependencies = function() {
'3.2.0',
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPoints.js"
"GlifyUtils.js"
, "addGlifyPoints.js"
, "addGlifyPolygons.js"
, "addGlifyPolylines.js"
, "glify-browser.js"
Expand All @@ -23,7 +24,8 @@ glifyDependenciesSrc = function() {
'3.2.0',
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPointsSrc.js"
"GlifyUtils.js"
, "addGlifyPointsSrc.js"
, "addGlifyPolygonsSrc.js"
, "addGlifyPolylinesSrc.js"
, "glify-browser.js"
Expand Down Expand Up @@ -81,6 +83,18 @@ glifyPopupAttachmentSrc = function(fl_popup, group) {
)
)
}
glifyLabelAttachmentSrc = function(fl_popup, group) {
data_dir <- dirname(fl_popup)
data_file <- basename(fl_popup)
list(
htmltools::htmlDependency(
name = paste0(group, "lab"),
version = 1,
src = c(file = data_dir),
script = list(data_file)
)
)
}

glifyRadiusAttachmentSrc = function(fl_radius, group) {
data_dir <- dirname(fl_radius)
Expand Down Expand Up @@ -146,11 +160,51 @@ glifyDependenciesFl = function() {
'2.2.0',
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPoints.js"
"GlifyUtils.js"
, "addGlifyPoints.js"
, "addGlifyPolygonsFl.js"
, "addGlifyPolylines.js"
, "glify.js"
, "glify-browser.js"
)
)
)
}



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)
trafficonese marked this conversation as resolved.
Show resolved Hide resolved
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
}
Loading