diff --git a/R/step2_data.R b/R/step2_data.R index 13c5cb38..30b0316d 100644 --- a/R/step2_data.R +++ b/R/step2_data.R @@ -67,11 +67,15 @@ step2_data = function(tm) { plot.order = tml$plot.order + group = if (is.na(tml$group)) tmg$tms$shp_name else as.character(tml$group) + group.control = as.character(tml$group.control) + + # args will be passed on to the scale functions (in case needed) # they also will be used in step 3 (trans) and step 4 (mapping) - trans = mapply(getdts, tml$trans.aes, names(tml$trans.aes), SIMPLIFY = FALSE, MoreArgs = list(p = tp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, mfun = tml$mapping.fun, args = tml$trans.args, plot.order = plot.order)) + trans = mapply(getdts, tml$trans.aes, names(tml$trans.aes), SIMPLIFY = FALSE, MoreArgs = list(p = tp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, group = group, mfun = tml$mapping.fun, args = tml$trans.args, plot.order = plot.order)) - mapping = mapply(getdts, tml$mapping.aes, names(tml$mapping.aes), SIMPLIFY = FALSE, MoreArgs = list(p = gp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, mfun = tml$mapping.fun, args = tml$mapping.args, plot.order = plot.order)) + mapping = mapply(getdts, tml$mapping.aes, names(tml$mapping.aes), SIMPLIFY = FALSE, MoreArgs = list(p = gp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, group = group, mfun = tml$mapping.fun, args = tml$mapping.args, plot.order = plot.order)) dts_trans = cbind_dts(lapply(trans, function(x) x$dt), plot.order) trans_legend = lapply(trans, function(x) x$leg) @@ -81,8 +85,6 @@ step2_data = function(tm) { if (dev) timing_add(s4 = "combine") if (dev) timing_add(s3 = paste0("layer ", tml$layer)) - group = if (is.na(tml$group)) tmg$tms$shp_name else as.character(tml$group) - group.control = as.character(tml$group.control) popup.data = if (!length(tml$popup.vars)) { NULL diff --git a/R/step2_helper_data.R b/R/step2_helper_data.R index af946bfb..3ea38da4 100644 --- a/R/step2_helper_data.R +++ b/R/step2_helper_data.R @@ -66,7 +66,7 @@ update_crt = function(o, crt, v, mfun, unm, active) { crt } -getdts = function(aes, unm, p, q, o, dt, shpvars, layer, mfun, args, plot.order) { +getdts = function(aes, unm, p, q, o, dt, shpvars, layer, group, mfun, args, plot.order) { dev = getOption("tmap.devel.mode") nm = aes$aes @@ -307,6 +307,7 @@ getdts = function(aes, unm, p, q, o, dt, shpvars, layer, mfun, args, plot.order) apply_scale = function(s, l, crt, v, varname, ordname, legname, crtname, sortRev, bypass_ord) { l = update_l(o = o, l = l, v = v, mfun = mfun, unm = unm, active = TRUE) + l$group = group crt = update_crt(o = o, crt = crt, v = v, mfun = mfun, unm = unm, active = TRUE) if (length(s) == 0) stop("mapping not implemented for aesthetic ", unm, call. = FALSE) diff --git a/R/tmapLeafletLegend.R b/R/tmapLeafletLegend.R index 51e8c997..efe67153 100644 --- a/R/tmapLeafletLegend.R +++ b/R/tmapLeafletLegend.R @@ -84,19 +84,12 @@ make_equal_list = function(x) { tmapLeaflet_legend = function(cmp, lf, o, orientation) { - group = "tmp" # TODO + group = cmp$group leg_className = paste("info legend", gsub(" ", "", group, fixed = TRUE)) layerId = paste0("legend", sprintf("%02d", .TMAP_LEAFLET$leg_id)) # "legend401" #todo .TMAP_LEAFLET$leg_id = .TMAP_LEAFLET$leg_id + 1 - # if (length(cmp$gp$col) > 1 || all(is.na(cmp$gp$fill))) { - # pal = cmp$gp$col - # opacity = cmp$gp$col_alpha - # } else { - # pal = cmp$gp$fill - # opacity = cmp$gp$fill_alpha - # } - + lab = cmp$labels val = cmp$dvalues title = if (nonempty_text(cmp$title)) expr_to_char(cmp$title) else NULL @@ -203,6 +196,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { lf %>% leaflegend::addLegendImage(symbols$iconUrl, + group = group, labels = lab, width = symbols$iconWidth + 2*gp2$strokeWidth, height = symbols$iconHeight + 2*gp2$strokeWidth,