Skip to content

Commit

Permalink
Merge pull request #85 from trafficonese/fgb_group
Browse files Browse the repository at this point in the history
FGB attach by group, highlightOptions, label as function
  • Loading branch information
tim-salabim authored Sep 16, 2024
2 parents 541e2a6 + b83abb8 commit 2b748e8
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 153 deletions.
25 changes: 17 additions & 8 deletions R/file.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ addTileFolder = function(map,
#' opacity, fillOpacity if those are to be mapped to an attribute column.
#' @param minZoom minimum zoom level at which data should be rendered.
#' @param maxZoom maximum zoom level at which data should be rendered.
#' @inheritParams leaflet::addPolylines
#' @param ... currently not used.
#'
#' @examples
Expand Down Expand Up @@ -358,6 +359,8 @@ addFgb = function(map,
scale = scaleOptions(),
minZoom = NULL,
maxZoom = 52,
highlightOptions = NULL,
labelOptions = NULL,
...) {


Expand All @@ -375,10 +378,8 @@ addFgb = function(map,

if (is.null(layerId)) layerId = group
layerId = gsub("[[:punct:] ]", "_", layerId)
# layerId = gsub("\\.", "_", layerId)
# layerId = gsub(" ", "", layerId)
# layerId = gsub('\\"', '', layerId)
# layerId = gsub("\\'", "", layerId)

if (missing(labelOptions)) labelOptions <- leaflet::labelOptions()

if (!is.null(file)) {
if (!file.exists(file)) {
Expand All @@ -392,7 +393,7 @@ addFgb = function(map,
}
path_layer = tempfile()
dir.create(path_layer)
path_layer = paste0(path_layer, "/", layerId, "_layer.fgb")
path_layer = paste0(path_layer, "/", group, "_layer.fgb")

file.copy(file, path_layer, overwrite = TRUE)

Expand All @@ -407,7 +408,7 @@ addFgb = function(map,

scale = utils::modifyList(scaleOptions(), scale)

options = options[!(options %in% style_list)]
options = options[!(names(options) %in% names(style_list))]

map$dependencies = c(
map$dependencies
Expand All @@ -417,7 +418,7 @@ addFgb = function(map,

map$dependencies = c(
map$dependencies
, fileAttachment(path_layer, layerId)
, fileAttachment(path_layer, group)
)

if (!is.null(minZoom)) {
Expand All @@ -440,6 +441,8 @@ addFgb = function(map,
, scaleFields
, minZoom
, maxZoom
, highlightOptions
, labelOptions
)
} else {
leaflet::invokeMethod(
Expand All @@ -456,6 +459,8 @@ addFgb = function(map,
, className
, scale
, scaleFields
, highlightOptions
, labelOptions
)
}
} else {
Expand Down Expand Up @@ -496,6 +501,8 @@ addFgb = function(map,
, scaleFields
, minZoom
, maxZoom
, highlightOptions
, labelOptions
)
} else {
leaflet::invokeMethod(
Expand All @@ -512,6 +519,8 @@ addFgb = function(map,
, className
, scale
, scaleFields
, highlightOptions
, labelOptions
)
}
}
Expand All @@ -535,7 +544,7 @@ fgbDependencies = function() {
list(
htmltools::htmlDependency(
"FlatGeoBuf"
, '3.21.3'
, '3.31.1'
, system.file("htmlwidgets/lib/FlatGeoBuf", package = "leafem")
, script = c(
'fgb.js'
Expand Down
Loading

0 comments on commit 2b748e8

Please sign in to comment.