tmap icon indicating copy to clipboard operation
tmap copied to clipboard

Prevent opening new tab for each viewed map

Open barryrowlingson opened this issue 4 years ago • 1 comments

tmap in view mode opens a new tab for each viewed map. Eventually I get annoyed and have to click-close forty tabs...

Could a method be implemented so that maps showed in the same tab? I don't think its possible from R to cause a current existing browser tab to open a new URL or refresh its current URL (not in an easy cross-platform multi-browser way) so instead I think you have to write the HTML to the same location and the user would have to manually refresh unless the HTML contained one of those clever auto-refresh javascripts...

This could be part of a new "mode", tmap_mode(mode="server"), which saves the HTML to a location, starts a local server on a high port and then opens the browser to that URL. Subsequent maps overwrite at that location and the browser would refresh (with an auto-refresh script).

Having multiple servers open would be even better - like having multiple graphics devices - with the opportunity to send a map to one or another via the tm_server() function.

Looking at the code it doesn't look too simple since tmap:::tmap_print ends up in htmlwidgets print method which prints to a new temp file every time with no possibility of control, but I think some intervention in tmap_print to grab the HTML and stash it in a known location if mode=="server" could do it.

I'll fork it and think about it - but does it sound like a good idea?

barryrowlingson avatar Feb 08 '21 10:02 barryrowlingson

@barryrowlingson we use something like you suggest in mapview::startWatching. This uses servr::httw watch a index.html file. IIRC, I needed to adjust the print method to work with this. Not sure if this is of any help, but may be a starting point

tim-salabim avatar Feb 08 '21 11:02 tim-salabim

@barryrowlingson feel free to reopen the issue if you made any progress

Nowosad avatar Feb 18 '23 19:02 Nowosad