tmap icon indicating copy to clipboard operation
tmap copied to clipboard

Problem with map "titles" in interactive mode in knitted Markdown to html

Open lbusett opened this issue 5 years ago • 3 comments

Hi,

I am encountering a problem while trying to knit a rmarkdown including interactive tmap maps to html. In practice, if I include multiple r chunks including faceted maps, the "titles" on the top left corner are somehow "collated" in the maps of the first chunk, as in the picture below.

image

Generated with the Rmd in attach:

test_tmap_leg_rmd.zip

Note that all seems to work properly if I use tmap_mode("plot"). I am also reasonably sure that it was working properly some versions ago, but unfortunately can not be more specific.

On a side note: Is there any way to manually set the "legend names" in the different facets? They seem to originate from the "names" attribute of the input stars object. However, sometimes it could be useful to set them manually (for example, to plot different bands of a "RasterStack" object containing different variables, which therefore have different measurement units/legends). I think that before the "switch" to stars use, the legend names where originated based on the names attributes of the rasterStack, and therefore could "vary" with band.

Thanks in advance,

Lorenzo

lbusett avatar May 07 '20 07:05 lbusett

Note that this is not specific to facets.

Here is a simpler example with two single maps, trying to make it as minimal as possible (source .Rmd and output .html in zip archive).

tmap_titles.zip

image

stragu avatar Jul 12 '21 05:07 stragu

In the HTML, the second script (for the second map widget) contains this extra bit:

"jsHooks": {
    "render": [{
        "code": "function(el, x, data) {\n  return (\n\t\t\t\t\t\tfunction(el, x) {\n\t\t\t\t\t\t\tvar tldiv = document.getElementsByClassName(\"leaflet-top leaflet-left\")[0];\n\t\t\t\t\t\t\tvar titlediv = document.createElement('div');\n\t\t\t\t\t\t\ttitlediv.className = \"info legend leaflet-control\";\n\t\t\t\t\t\t\ttitlediv.innerHTML = \"<b>A Title<\/b>\";\n\t\t\t\t\t\t\ttldiv.insertBefore(titlediv, tldiv.childNodes[0]);\n\t\t\t\t\t\t}).call(this.getMap(), el, x, data);\n}",
        "data": null
    }]
}

How come this ends up applying to the previous widget?

stragu avatar Jul 12 '21 11:07 stragu

Did you manage to resolve this?

panda88-hub avatar Dec 15 '21 15:12 panda88-hub