Skip to content
Merged
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ importFrom(golem,bundle_resources)
importFrom(golem,favicon)
importFrom(golem,with_golem_options)
importFrom(lubridate,year)
importFrom(purrr,set_names)
importFrom(shiny,NS)
importFrom(shiny,shinyApp)
importFrom(shiny,tagList)
Expand Down
2 changes: 1 addition & 1 deletion R/mod_carto_leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod_carto_leaflet_server <- function(id, global) {

if (isTRUE(input$missingdata)) {
thedata <- local$df_prep$data_prep |>
purrr::keep(\(x) (x[8] == "1"))
purrr::keep(\(x) (x["info_missing"] == "1"))
thereens <- 0
} else {
thedata <- local$df_prep$data_prep
Expand Down
4 changes: 3 additions & 1 deletion R/prepare_leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param dbtruffle A data frame containing information about truffles.
#' @param dbreens A data frame containing information about reensemencement.
#' @importFrom dplyr filter mutate distinct full_join
#' @importFrom purrr set_names
#' @return A list suitable for passing to Leaflet JavaScript for visualization.
#'
#' @export
Expand Down Expand Up @@ -51,7 +52,8 @@ prepare_leaflet <- function(dboak, dbtruffle, dbreens) {
data_prep <- lapply(
1:nrow(c),
function(i) {
unname(as.list(as.character(c[i, ])))
unname(as.list(as.character(c[i, ]))) |>
set_names(names(c))
}
)

Expand Down
20 changes: 10 additions & 10 deletions inst/app/www/leaflet_.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ $(document).ready(function () {
var locations = arg.data;
var reens = arg.reens;
var mean_lat = locations.length
? locations.reduce((sum, loc) => sum + Number(loc[2] || 0), 0) /
? locations.reduce((sum, loc) => sum + Number(loc.lat || 0), 0) /
locations.length
: 0;

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

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

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

marker.id = locations[i][0];
marker.id = locations[i].idoak;

if (reens === 0) {
if (locations[i][3] === "Normal") {
if (locations[i].type === "Normal") {
marker.setStyle({
color: "#FF0000",
fillColor: "#FF0000",
Expand All @@ -81,7 +81,7 @@ $(document).ready(function () {
});
}
} else {
if (locations[i][7] === "1") {
if (locations[i].info_reens === "1") {
marker.setStyle({
color: "#00AEEF",
fillColor: "#00AEEF",
Expand Down