r-spatial / leafsync

Small Multiples for Leaflet Webmaps
Other
36 stars 2 forks source link

caption with latticeView object #5

Closed elisefilotas closed 2 years ago

elisefilotas commented 2 years ago

Hi Tim,

I am having trouble displaying the caption of a figure produced with latticeView when I render an rmarkdown document. The caption does not show up.

I had a similar issue with mapview whenever I added multiple maps (maps = m1 + m2), but when I ask for the @map component (maps@map) the caption renders correctly.

Hence, I suspect that if I could extract a @map component from a latticeView object I could solve this issue. Here is a reproducible example.

cat("

    ```{r}
    library(mapview)
    library(sf)
    library(leaflet)
    library(leafsync)
I create 2 square polygons   
```{r}
M1 <- matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
L1 <- list(M1)
P1 <- st_polygon(L1)

M2 <- matrix(c(5,5,15,5,15,15,5,15,5,5),ncol=2, byrow=TRUE)
L2 <- list(M2)
P2 <- st_polygon(L2) 
```

# EX 1   
Here the legend is NOT showing: 

``` {r sync, fig.align = 'left', out.width = '100%', fig.cap = 'Map caption: Panel with three figures'}
map1 <- mapview(P1, col.regions = 'red')
map2 <- mapview(P2, col.regions = 'blue')
map3 <- mapview(P1, col.regions = 'green')

Map <- leafsync::latticeView(map1,map2, map3, ncol = 3)
Map
```
<br>

Also, the text following the figure appears directly to the rigth of the figure. Even if I put a line break.

# EX 2
Here the caption is NOT showing:
``` {r ex1, fig.align = 'left', out.width = '100%', fig.cap = 'Map caption: Red and blue map'}
Map <- mapview(P1, col.regions = 'red') + mapview(P2, col.regions = 'blue')
Map
```

# EX 3
Here, the caption IS showing:
``` {r ex2, fig.align = 'left', out.width = '100%', fig.cap = 'Map caption: Yellow and green map'}
Map <- mapview(P1, col.regions = 'yellow') + mapview(P2, col.regions = 'green')
Map@map
```

", file = "reprex.Rmd") rmarkdown::render("reprex.Rmd")



Thank you for your help, and thank you for your great packages which I am using a lot!
Elise
tim-salabim commented 2 years ago

Thanks for raising this. I'll try to look into this soon.

tim-salabim commented 2 years ago

Hi @elisefilotas your first issue (line breaks not respected) should be solved with the latest commit. Note that I've changed a few things, including a small layout change: we now have an argument between to control the space between panels rather than the hard coded grey boxes around the panels. This is closer to what individual leaflet maps would look like.

The caption issue is a long standing one and not exclusive to leafsync. See e.g. https://github.com/r-spatial/mapview/issues/146 and all the issues linked there... I am not sure how to solve this unfortunately.

elisefilotas commented 2 years ago

Hi @tim-salabim, thank you so much, it looks great now! Noted for the caption issue. This is less of a problem for me.

tim-salabim commented 2 years ago

Sweet, I'll close the issue here. Feel free to reopen