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 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ 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,
jsonify,
leaflet,
sf,
yyjsonr,
grDevices
Suggests:
colourvalues,
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)
21 changes: 20 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@ leafgl 0.2.1.9005 (2023-09-08)

features and improvements

* Switched from `jsonify` and `geojsonsf` to `yyjsonr`
* 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
* Increase precision of points, lines and shapes by translating them closer to the Pixel Origin. Thanks @RayLarone #93
* 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 #68
* 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`. #81

documentation etc

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

miscellaneous

* update upstream javascript dependency to 3.3.0. #49
Note: If you previously used the workaround `L.glify.Shapes.instances.splice(0, 1)`, please remove it with this new version.
* unified / simplified the dependency functions/calls


leafgl 0.2.1

Expand Down
32 changes: 25 additions & 7 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,55 @@

#### ✨ features and improvements

- Switched from `jsonify` and `geojsonsf` to `yyjsonr`
- 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](https://github.com/r-spatial/leafgl/issues/48) [#50](https://github.com/r-spatial/leafgl/issues/50)

#### 🐛 bug fixes

* src version now works also in shiny. #71
- Increase precision of points, lines and shapes by translating them closer to the Pixel Origin. Thanks @RayLarone [#93](https://github.com/r-spatial/leafgl/issues/93)
- src version now works also in shiny. [#71](https://github.com/r-spatial/leafgl/issues/71)
- added `popupOptions` and `labelOptions`. [#83](https://github.com/r-spatial/leafgl/issues/83)
- added `stroke` (default=TRUE) in `addGlPolygons` and `addGlPolygonsSrc` for drawing borders. [#3](https://github.com/r-spatial/leafgl/issues/3) [#68](https://github.com/r-spatial/leafgl/issues/68)
- Labels work similar to `leaflet`. `leafgl` accepts a single string, a vector of strings or a formula. [#78](https://github.com/r-spatial/leafgl/issues/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`. [#81](https://github.com/r-spatial/leafgl/issues/81)

#### 💬 documentation etc

- Added some @details for Shiny click and mouseover events and their corresponding input. [#77](https://github.com/r-spatial/leafgl/issues/77)
- Use `@inheritParams leaflet::**` for identical function arguments

#### 🍬 miscellaneous

- update upstream javascript dependency to 3.3.0. [#49](https://github.com/r-spatial/leafgl/issues/49)

⚠️If you previously used the workaround `L.glify.Shapes.instances.splice(0, 1)`, please remove it with this new version.

- unified / simplified the dependency functions/calls

## leafgl 0.2.1

new features:

* all methods can now have labels/tooltips. Currently only lines and polygons support passing of a column name, points need a predefined label vector.
- all methods can now have labels/tooltips. Currently only lines and polygons support passing of a column name, points need a predefined label vector.

miscallaneous:

* all methods now have a pane argument to control layer ordering (thanks to @trafficonese). #67 #64
- all methods now have a pane argument to control layer ordering (thanks to @trafficonese). [#67](https://github.com/r-spatial/leafgl/issues/67) [#64](https://github.com/r-spatial/leafgl/issues/64)

## leafgl 0.2.0

miscallaneous:

* update upstream javascript dependency to 3.2.0
- update upstream javascript dependency to 3.2.0

## leafgl 0.1.2

new features:

* expose additional JavaScript arguments in addGlPoints via magic dots. #54 & #60

- expose additional JavaScript arguments in addGlPoints via magic dots. [#54](https://github.com/r-spatial/leafgl/issues/54) & [#60](https://github.com/r-spatial/leafgl/issues/60)

## leafgl 0.1.1

Expand Down
183 changes: 77 additions & 106 deletions R/glify-helpers.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
# helpers
glifyDependencies = function() {
# dependencies
glifyDependencies = function(src = FALSE) {
src <- ifelse(src, "Src", "")
list(
htmltools::htmlDependency(
"Leaflet.glify",
'3.2.0',
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPoints.js"
, "addGlifyPolygons.js"
, "addGlifyPolylines.js"
, "glify-browser.js"
)
)
)
}

# helpers
glifyDependenciesSrc = function() {
list(
htmltools::htmlDependency(
"Leaflet.glifySrc",
'3.2.0',
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPointsSrc.js"
, "addGlifyPolygonsSrc.js"
, "addGlifyPolylinesSrc.js"
"GlifyUtils.js"
, paste0("addGlifyPoints", src, ".js")
, paste0("addGlifyPolygons", src, ".js")
, paste0("addGlifyPolylines", src, ".js")
, "glify-browser.js"
)
)
Expand Down Expand Up @@ -56,101 +41,87 @@ glifyDataAttachmentSrc = function(fl_data, group, async = FALSE) {
}
}

glifyColorAttachmentSrc = function(fl_color, group) {
data_dir <- dirname(fl_color)
data_file <- basename(fl_color)
list(
htmltools::htmlDependency(
name = paste0(group, "col"),
version = 1,
src = c(file = data_dir),
script = list(data_file)
)
)
}

glifyPopupAttachmentSrc = function(fl_popup, group) {
data_dir <- dirname(fl_popup)
data_file <- basename(fl_popup)
list(
htmltools::htmlDependency(
name = paste0(group, "pop"),
version = 1,
src = c(file = data_dir),
script = list(data_file)
)
)
}

glifyRadiusAttachmentSrc = function(fl_radius, group) {
data_dir <- dirname(fl_radius)
data_file <- basename(fl_radius)
glifyAttachmentSrc <- function(fl, group, type) {
valid_types <- c("col", "pop", "lab", "rad")
if (!type %in% valid_types) {
stop("Invalid type. Valid types are: col, pop, lab, rad.")
}
data_dir <- dirname(fl)
data_file <- basename(fl)
list(
htmltools::htmlDependency(
name = paste0(group, "rad"),
name = paste0(group, type),
version = 1,
src = c(file = data_dir),
script = list(data_file)
)
)
}

glifyDataAttachment = function(fl_data, group) {
data_dir <- dirname(fl_data)
data_file <- basename(fl_data)
list(
htmltools::htmlDependency(
name = paste0(group, "dt"),
version = 1,
src = c(file = data_dir),
attachment = list(data_file)
)
)
}


glifyColorAttachment = function(fl_color, group) {
data_dir <- dirname(fl_color)
data_file <- basename(fl_color)
list(
htmltools::htmlDependency(
name = paste0(group, "cl"),
version = 1,
src = c(file = data_dir),
attachment = list(data_file)
)
)
# helpers
yyson_json_str <- function(x, ...) {
dt <- yyjsonr::write_json_str(x, ...)
class(dt) <- "json"
dt
}

glifyPopupAttachment = function(fl_popup, group) {
data_dir <- dirname(fl_popup)
data_file <- basename(fl_popup)
list(
htmltools::htmlDependency(
name = paste0(group, "pop"),
version = 1,
src = c(file = data_dir),
attachment = list(data_file)
)
)
yyson_geojson_str <- function(x, ...) {
dt <- yyjsonr::write_geojson_str(x, ...)
class(dt) <- "json"
dt
}




# helpers
glifyDependenciesFl = function() {
list(
htmltools::htmlDependency(
"Leaflet.glify",
'2.2.0',
system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
script = c(
"addGlifyPoints.js"
, "addGlifyPolygonsFl.js"
, "addGlifyPolylines.js"
, "glify.js"
)
)
)
}
## Not used ##########
# glifyDependenciesFl = function() {
# list(
# htmltools::htmlDependency(
# "Leaflet.glify",
# '2.2.0',
# system.file("htmlwidgets/Leaflet.glify", package = "leafgl"),
# script = c(
# "GlifyUtils.js"
# , "addGlifyPoints.js"
# , "addGlifyPolygonsFl.js"
# , "addGlifyPolylines.js"
# , "glify-browser.js"
# )
# )
# )
# }
# glifyDataAttachment = function(fl_data, group) {
# data_dir <- dirname(fl_data)
# data_file <- basename(fl_data)
# list(
# htmltools::htmlDependency(
# name = paste0(group, "dt"),
# version = 1,
# src = c(file = data_dir),
# attachment = list(data_file)
# )
# )
# }
# glifyColorAttachment = function(fl_color, group) {
# data_dir <- dirname(fl_color)
# data_file <- basename(fl_color)
# list(
# htmltools::htmlDependency(
# name = paste0(group, "cl"),
# version = 1,
# src = c(file = data_dir),
# attachment = list(data_file)
# )
# )
# }
# glifyPopupAttachment = function(fl_popup, group) {
# data_dir <- dirname(fl_popup)
# data_file <- basename(fl_popup)
# list(
# htmltools::htmlDependency(
# name = paste0(group, "pop"),
# version = 1,
# src = c(file = data_dir),
# attachment = list(data_file)
# )
# )
# }
Loading
Loading