{"id":16090,"date":"2020-05-09T10:56:24","date_gmt":"2020-05-09T10:56:24","guid":{"rendered":"http:\/\/www.wjst.de\/blog\/?p=16090"},"modified":"2020-05-09T11:04:55","modified_gmt":"2020-05-09T11:04:55","slug":"r-leaflet-keep-map-in-frame-after-closing-info-box","status":"publish","type":"post","link":"https:\/\/www.wjst.de\/blog\/sciencesurf\/2020\/05\/r-leaflet-keep-map-in-frame-after-closing-info-box\/","title":{"rendered":"R leaflet &#8211; keep map in frame after closing info box"},"content":{"rendered":"<p>Although having some experience with leaflet before, <a href=\"https:\/\/www.wjst.de\/blog\/sciencesurf\/2020\/05\/heinsberg-und-tirschenreuth-aus-den-schlagzeilen-dafuer-greiz-coesfeld-steinburg-und-neuburg\/\">it took me 5 hours<\/a> to find out how to<br \/>\n(1) change the background color and<br \/>\n(2) re-center my map after the popup was panning the map\u00a0 basically out view. Here is my solution<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nleaflet(options = leafletOptions(\r\n zoomControl = FALSE,\r\n minZoom=6, maxZoom=6,\r\n centerFixed = TRUE) ) %&gt;%\r\naddPolygons(data = ds,\r\n fillColor = ~pal(AnzahlFall),\r\n color=&quot;black&quot;, weight = 1,\r\n fillOpacity = 0.7,\r\n label = ~name_2,\r\n popup = ~www,\r\n popupOptions = popupOptions( autopan=FALSE, keepInView = TRUE ) ) %&gt;%\r\nhtmlwidgets::onRender(&quot;\r\n function(el, x) {\r\n  var myMap = this;\r\n  myMap.dragging.disable();\r\n  myMap.on('popupclose', function(e) { myMap.panTo( {lon: 10.26, lat: 51.1} ) });\r\n  var e = document.getElementsByClassName('leaflet-container');\r\n  e&#x5B;0].style.backgroundColor = 'white';\t    \r\n}&quot;)\r\n<\/pre>\n\n<p>&nbsp;<\/p>\n<div class=\"bottom-note\">\n  <span class=\"mod1\">CC-BY-NC Science Surf , accessed 02.05.2026<\/span>\n <\/div>","protected":false},"excerpt":{"rendered":"<p>Although having some experience with leaflet before, it took me 5 hours to find out how to (1) change the background color and (2) re-center my map after the popup was panning the map\u00a0 basically out view. Here is my solution leaflet(options = leafletOptions( zoomControl = FALSE, minZoom=6, maxZoom=6, centerFixed = TRUE) ) %&gt;% addPolygons(data &hellip; <a href=\"https:\/\/www.wjst.de\/blog\/sciencesurf\/2020\/05\/r-leaflet-keep-map-in-frame-after-closing-info-box\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">R leaflet &#8211; keep map in frame after closing info box<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2893,3409,3408,2717,3410],"class_list":["post-16090","post","type-post","status-publish","format-standard","hentry","category-computer-software","tag-r","tag-choropleth","tag-leaflet","tag-map","tag-popup"],"_links":{"self":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/16090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/comments?post=16090"}],"version-history":[{"count":6,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/16090\/revisions"}],"predecessor-version":[{"id":16096,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/16090\/revisions\/16096"}],"wp:attachment":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/media?parent=16090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/categories?post=16090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/tags?post=16090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}