Skip to content

Commit

Permalink
fixed leaflet symbols bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed May 28, 2024
1 parent 2e467c0 commit 4a825bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions R/tmapLeafletInit.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
addBaseGroup <- function(group) {
addBaseGroup = function(group) {
for (g in group) {
if (is.na(bases[1])) {
bases <- g
bases = g
} else if (!(g %in% bases)) {
bases <- c(bases, g)
bases = c(bases, g)
}
}
assign("bases", bases, envir = .TMAP_LEAFLET)
}

eraseBaseGroup <- function() {
eraseBaseGroup = function() {
assign("bases", character(0), envir = .TMAP_LEAFLET)
}

eraseOverlayTiles <- function() {
overlays <- setdiff(overlays, overlays_tiles)
eraseOverlayTiles = function() {
overlays = setdiff(overlays, overlays_tiles)
assign("overlays", overlays, envir = .TMAP_LEAFLET)
}

addOverlayGroup <- function(group, are.tiles = FALSE) {
addOverlayGroup = function(group, are.tiles = FALSE) {
for (g in group) {
if (is.na(overlays[1])) {
overlays <- g
overlays = g
} else if (!(g %in% overlays)) {
overlays <- c(overlays, g)
overlays = c(overlays, g)
}
}
assign("overlays", overlays, envir = .TMAP_LEAFLET)
Expand All @@ -45,7 +45,7 @@ tmapLeafletInit = function(o, return.asp = FALSE, vp) {
# leaflet options

if (o$crs_leaflet$crsClass == "L.CRS.Simple") {
if (is.na(o$set.zoom.limits)[1]) o$set.zoom.limits[1] <- -1000
if (is.na(o$set.zoom.limits)[1]) o$set.zoom.limits[1] = -1000
}
leaflet_opts = do.call(leaflet::leafletOptions, c(list(crs=o$crs_leaflet), o$leaflet.options))

Expand Down Expand Up @@ -104,7 +104,7 @@ tmapLeafletAux = function(o, q) {



view_set_bounds <- function(lf, bbx, o) {
view_set_bounds = function(lf, bbx, o) {
if (!is.logical(o$set.bounds)) {
lims = unname(o$set.bounds)
} else {
Expand All @@ -127,19 +127,20 @@ view_set_bounds <- function(lf, bbx, o) {
}

if (!is.na(zm)) {
set.view <- c(mean.default(lims[c(1,3)]), mean.default(lims[c(2,4)]), zm)
set.view = c(mean.default(lims[c(1,3)]), mean.default(lims[c(2,4)]), zm)
} else if (!is.na(o$set.zoom.limits[2])) { # 2nd is checked to bypass (-1000, NA) used for simple CRS
set.view <- c(mean.default(lims[c(1,3)]), mean.default(lims[c(2,4)]), o$set.zoom.limits[1])
set.view = c(mean.default(lims[c(1,3)]), mean.default(lims[c(2,4)]), o$set.zoom.limits[1])
} else {
set.view = NULL
}
} else if (length(o$set.view) == 1) {
set.view <- c(mean.default(lims[c(1,3)]), mean.default(lims[c(2,4)]), o$set.view)
set.view = c(mean.default(lims[c(1,3)]), mean.default(lims[c(2,4)]), o$set.view)
} else {
set.view <- o$set.view
set.view = o$set.view
}

if (!is.null(set.view)) {
names(set.view) = NULL
lf = lf %>% setView(set.view[1], set.view[2], set.view[3])
}

Expand Down
2 changes: 1 addition & 1 deletion R/tmapLeaflet_layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ tmapLeafletSymbols = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, f
symbols_icons <- merge_icons(iconLib)
size = gp2$width[sid] / gp2$baseSize

#size[sid] = size[sid] * args$icon.scale # icon.scale is set to 1 in view mode
size[sid] = size[sid] * args$icon.scale/3 # icon.scale is set to 1 in view mode

for (i in seq_along(sid)) {
symbols$iconUrl[sid[i]] = symbols_icons$iconUrl[i]
Expand Down

0 comments on commit 4a825bc

Please sign in to comment.