Generating leaflet html's easily results in a 50-75 MB file (depending on the number of layers). However, they can be zipped to reduce the file size by factors. So i guess there is lots of repetitive information in the HTML. The data is the same for most of the layers.
Simplifying the geometries would help, but I don't want to alter them. I further red, that GeoJson plots all the boundaries of polygons, even if they are bordering each other, but I didn't succeed down that line.
Any idea on how to do that? I included the mapview-tag as it seems to me that mapview is more data efficient.
The following code creates a simple map with a number of identical layers. Adding two layers, results in 3.7 MB (zip to 1.4), adding 20 layers (with the same information), results in 32.6 MB (zip to 12.9).
library(leaflet)
library(htmlwidgets)
nrep <- 2
colors <- colorFactor(palette="viridis",
domain=gadmCHE@data$NAME_1, na.color="transparent")
mapCH <- gadmCHE %>% leaflet() %>% addTiles()
for (i in 1:nrep){
print(i)
mapCH <- mapCH %>%
addPolygons(fillColor = ~colors(NAME_1), fillOpacity = 1,group = as.character(i))
}
mapCH <- mapCH %>%
addLayersControl(position = "topleft",
baseGroups = c("OpenStreetMap"),
options = layersControlOptions(collapsed=F),
overlayGroups=paste(1:nrep)) %>%
clearControls()%>%
hideGroup(paste(1:nrep))
saveWidget(mapCH, file = paste0("Test_",nrep,".html"))