Skip to content

Commit 7dc7e77

Browse files
Merge pull request #8 from ThinkR-open/dev
feat: Improve naming data leaflet
2 parents d067f97 + 3b503a4 commit 7dc7e77

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ importFrom(golem,bundle_resources)
4545
importFrom(golem,favicon)
4646
importFrom(golem,with_golem_options)
4747
importFrom(lubridate,year)
48+
importFrom(purrr,set_names)
4849
importFrom(shiny,NS)
4950
importFrom(shiny,shinyApp)
5051
importFrom(shiny,tagList)

R/mod_carto_leaflet.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mod_carto_leaflet_server <- function(id, global) {
7171

7272
if (isTRUE(input$missingdata)) {
7373
thedata <- local$df_prep$data_prep |>
74-
purrr::keep(\(x) (x[8] == "1"))
74+
purrr::keep(\(x) (x["info_missing"] == "1"))
7575
thereens <- 0
7676
} else {
7777
thedata <- local$df_prep$data_prep

R/prepare_leaflet.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#' @param dbtruffle A data frame containing information about truffles.
88
#' @param dbreens A data frame containing information about reensemencement.
99
#' @importFrom dplyr filter mutate distinct full_join
10+
#' @importFrom purrr set_names
1011
#' @return A list suitable for passing to Leaflet JavaScript for visualization.
1112
#'
1213
#' @export
@@ -51,7 +52,8 @@ prepare_leaflet <- function(dboak, dbtruffle, dbreens) {
5152
data_prep <- lapply(
5253
1:nrow(c),
5354
function(i) {
54-
unname(as.list(as.character(c[i, ])))
55+
unname(as.list(as.character(c[i, ]))) |>
56+
set_names(names(c))
5557
}
5658
)
5759

inst/app/www/leaflet_.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ $(document).ready(function () {
55
var locations = arg.data;
66
var reens = arg.reens;
77
var mean_lat = locations.length
8-
? locations.reduce((sum, loc) => sum + Number(loc[2] || 0), 0) /
8+
? locations.reduce((sum, loc) => sum + Number(loc.lat || 0), 0) /
99
locations.length
1010
: 0;
1111

1212
var mean_lon = locations.length
13-
? locations.reduce((sum, loc) => sum + Number(loc[1] || 0), 0) /
13+
? locations.reduce((sum, loc) => sum + Number(loc.lon || 0), 0) /
1414
locations.length
1515
: 0;
1616

1717
// Calculer les coordonnées min/max comme avant
18-
var minLat = Math.min(...locations.map((loc) => Number(loc[2] || 0)));
19-
var maxLat = Math.max(...locations.map((loc) => Number(loc[2] || 0)));
20-
var minLon = Math.min(...locations.map((loc) => Number(loc[1] || 0)));
21-
var maxLon = Math.max(...locations.map((loc) => Number(loc[1] || 0)));
18+
var minLat = Math.min(...locations.map((loc) => Number(loc.lat || 0)));
19+
var maxLat = Math.max(...locations.map((loc) => Number(loc.lat || 0)));
20+
var minLon = Math.min(...locations.map((loc) => Number(loc.lon || 0)));
21+
var maxLon = Math.max(...locations.map((loc) => Number(loc.lon || 0)));
2222
// Calculer l'étendue géographique
2323
var latDiff = maxLat - minLat;
2424
var lonDiff = maxLon - minLon;
@@ -59,15 +59,15 @@ $(document).ready(function () {
5959
}
6060

6161
for (var i = 0; i < locations.length; i++) {
62-
marker = new L.circleMarker([locations[i][2], locations[i][1]])
62+
marker = new L.circleMarker([locations[i].lat, locations[i].lon])
6363
.unbindPopup()
6464
.addTo(map)
6565
.on("click", onClick);
6666

67-
marker.id = locations[i][0];
67+
marker.id = locations[i].idoak;
6868

6969
if (reens === 0) {
70-
if (locations[i][3] === "Normal") {
70+
if (locations[i].type === "Normal") {
7171
marker.setStyle({
7272
color: "#FF0000",
7373
fillColor: "#FF0000",
@@ -81,7 +81,7 @@ $(document).ready(function () {
8181
});
8282
}
8383
} else {
84-
if (locations[i][7] === "1") {
84+
if (locations[i].info_reens === "1") {
8585
marker.setStyle({
8686
color: "#00AEEF",
8787
fillColor: "#00AEEF",

0 commit comments

Comments
 (0)