{"id":13572775,"url":"https://github.com/r-spatial/leafgl","last_synced_at":"2025-04-04T11:30:44.127Z","repository":{"id":41322463,"uuid":"149975903","full_name":"r-spatial/leafgl","owner":"r-spatial","description":"R package for fast web gl rendering for leaflet","archived":false,"fork":false,"pushed_at":"2025-02-03T07:45:23.000Z","size":7973,"stargazers_count":270,"open_issues_count":33,"forks_count":32,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-28T20:15:44.335Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://r-spatial.github.io/leafgl/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-spatial.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-23T10:58:11.000Z","updated_at":"2025-03-22T10:59:46.000Z","dependencies_parsed_at":"2024-01-06T03:08:36.281Z","dependency_job_id":"160de496-6113-40c6-8bac-ad7b1863358c","html_url":"https://github.com/r-spatial/leafgl","commit_stats":{"total_commits":136,"total_committers":7,"mean_commits":"19.428571428571427","dds":0.2647058823529411,"last_synced_commit":"fde85e9813cca0a4303b27bc39ec7a102de438d3"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2Fleafgl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2Fleafgl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2Fleafgl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-spatial%2Fleafgl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-spatial","download_url":"https://codeload.github.com/r-spatial/leafgl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247169900,"owners_count":20895375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:00:19.545Z","updated_at":"2025-04-04T11:30:39.119Z","avatar_url":"https://github.com/r-spatial.png","language":"R","funding_links":[],"categories":["Planning Coding Resources","R","Leaflet Functions","Visualization"],"sub_categories":["R","3D Map","Maps and Spatial Data"],"readme":"---\noutput: github_document\n---\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  eval = FALSE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# leafgl - performant WebGL rendering for leaflet\n\n[![Travis build status](https://travis-ci.org/r-spatial/leafgl.svg?branch=master)](https://travis-ci.org/r-spatial/leafgl)\n[![monthly](http://cranlogs.r-pkg.org/badges/leafgl)](https://www.rpackages.io/package/leafgl) \n[![total](http://cranlogs.r-pkg.org/badges/grand-total/leafgl)](https://www.rpackages.io/package/leafgl)\n[![CRAN](http://www.r-pkg.org/badges/version/leafgl?color=009999)](https://cran.r-project.org/package=leafgl)\n[![status](https://tinyverse.netlify.com/badge/leafgl)](https://CRAN.R-project.org/package=leafgl)\n\nAn R package for fast web gl rendering of features on leaflet maps.\nIt's an R port of https://github.com/robertleeplummerjr/Leaflet.glify where \nmore detailed information/documentation can be found. Also, if you like \nwhat you get here, make sure to star the original repo!\n\n-----\n\n### Installation\n\n##### Stable version from CRAN\n\n```{r cran}\ninstall.packages(\"leafgl\")\n```\n\n##### Development version from Github\n\n```{r install}\ndevtools::install_github(\"r-spatial/leafgl\")\n```\n\n\n### What does it do?\n\nIt allows rendering of a large amount of features on a leaflet map. \nWhat exactly a \"large amount\" is, depends \n\n1. on the types of features and\n2. on the hardware/software of the rendering machine. \n\nRegarding 1. millions of points should be no problem, but millions \nof polygons might, depending on their complexity - i.e. the number of \nvertices.\n\nWith regard to 2., obviously the amount of RAM will matter most but\nthere are other, more suptle, problems that can occur. \n\nGiven it's name, leafgl is intended to fully integrate with the \nleaflet package, though it is very likely that it won't be a 1:1\nreplacement for the respective `leaflet::add*` functions. For example, \ngiven the intention to render/visualise as many features as possible we\nneed to make a compromise on what additional information we allow to be \npart of the rendering. So far, we allow coloring of features and popups\nbased on one column of the feature attributes, hence you cannot provide \nyour own popup content. This may seem drastic, but all this information \nis costly both in terms of performance/speed and memory. In the end, who\nwants to wait for a map that the browser isn't able to render anyway...\n\n### What doesn't it do?\n\nFor starters, it doesn't guarantee to be working tomorrow. At this stage\n`leafgl` is pre-alpha and under heavy development so things are \nlikely to change frequently. For example, we are thinking about shorter \nfuntion names (e.g. `addGlPolygons` instead of the current \n`addGlifyPolygons`). Additionally, we are still figuring out which \npathway is best to use in order to pass data from R to the browser. As\na result, rendering environments other than the browser (or RStudio \nviewer) may not work properly or at all until we approach a more stable \nimplementation.\n\n#### NOTE\n\nDepending on your operating system and browser, you may\nsee some weird colors that do not correspond to the ones that you\nspecified. The only known work-around at this stage is to set `opacity = 1`. \nFor more details the inclined reader is referred to [this issue](https://github.com/r-spatial/leafgl/issues/4)\n\n### What can I do to help?\n\nA lot! First and foremost you can use it as often as possible and report\nissues/bugreports and/or feature request (see end of page for details). \nIf you have ideas on how to enhance functionality without impacting\nperformance too much and feel confident enough to provide pull\nrequest, please don't hesitate. Finally, if you have proficient \nknowledge of JavaScript and want/know how to improve the package in any \nway, we would very much love to hear from you!\n\n### Example usage\n\n#### 1 Mio. points on a map\n\nThis will render 1 Mio. points on a standard leaflet map. \n\n```{r pts, eval=FALSE}\nlibrary(leaflet)\nlibrary(leafgl)\nlibrary(sf)\n\nn = 1e6\n\ndf1 = data.frame(id = 1:n,\n                 x = rnorm(n, 10, 3),\n                 y = rnorm(n, 49, 1.8))\n\npts = st_as_sf(df1, coords = c(\"x\", \"y\"), crs = 4326)\n\noptions(viewer = NULL) # view in browser\n\nleaflet() %\u003e%\n  addProviderTiles(provider = providers$CartoDB.DarkMatter) %\u003e%\n  addGlPoints(data = pts, group = \"pts\") %\u003e%\n  setView(lng = 10.5, lat = 49.5, zoom = 6)\n\n```\n\n![](man/figures/pts_blue.png)\n\n\u003cbr\u003e\n\n-----\n\n#### Colouring points by value mapping\n\nFor this we use `library(colourvalues)` because it can create color \nvoctors in the blink of an eye!\n\n```{r pts_col, eval=FALSE}\nlibrary(leaflet)\nlibrary(leafgl)\nlibrary(sf)\nlibrary(colourvalues)\n\nn = 1e6\n\ndf1 = data.frame(id = 1:n,\n                 x = rnorm(n, 10, 3),\n                 y = rnorm(n, 49, 1.8))\n\npts = st_as_sf(df1, coords = c(\"x\", \"y\"), crs = 4326)\n\ncols = colour_values_rgb(pts$id, include_alpha = FALSE) / 255\n\nleaflet() %\u003e%\n  addProviderTiles(provider = providers$CartoDB.DarkMatter) %\u003e%\n  addGlPoints(data = pts, fillColor = cols, group = \"pts\") %\u003e%\n  setView(lng = 10.5, lat = 49.5, zoom = 6)\n\n```\n\n![](man/figures/pts_viridis.png)\n\n\u003cbr\u003e\n\n-----\n\n#### 100k polygons on a map\n\nIn reality, it only 97112 polygons... But who wants to be pedantic here?\n\nThis data was downloaded from https://download.geofabrik.de/europe/switzerland.html\n\n```{r pols, eval=FALSE}\nlibrary(leaflet)\nlibrary(leafgl)\nlibrary(sf)\nlibrary(colourvalues)\n\nch_lu = st_read(\"/media/timpanse/d8346522-ef28-4d63-9bf3-19fec6e13aab/bu_lenovo/software/testing/mapview/switzerland/landuse.shp\")\n\nch_lu = ch_lu[, c(1, 3, 4)] # don't handle NAs so far\n\noptions(viewer = NULL)\n\ncols = colour_values_rgb(ch_lu$type, include_alpha = FALSE) / 255\n\nleaflet() %\u003e%\n  addProviderTiles(provider = providers$CartoDB.DarkMatter) %\u003e%\n  addGlPolygons(data = ch_lu, \n                color = cols, \n                popup = \"type\",\n                group = \"pols\") %\u003e%\n  setView(lng = 8.3, lat = 46.85, zoom = 9) %\u003e% \n  addLayersControl(overlayGroups = \"pols\")\n```\n\n![](man/figures/polys_ch.png)\n\n\u003cbr\u003e\n\n-----\n\n## Shiny ##\n\nThanks to [@ColinFay](https://github.com/ColinFay) `leafgl` has dedicated shiny functions. Given that what `leafgl` produces is a `leaflet` map, we only need to\nuse `leafglOutput` in our `ui` call. In the `server` call we can simply use `renderLeaflet`. Here an example:\n\n```{r shiny, eval=FALSE}\nlibrary(leaflet)\nlibrary(leafgl)\nlibrary(sf)\nlibrary(shiny)\n\nn = 1e6\n\ndf1 = data.frame(id = 1:n,\n                 x = rnorm(n, 10, 3),\n                 y = rnorm(n, 49, 1.8))\n\npts = st_as_sf(df1, coords = c(\"x\", \"y\"), crs = 4326)\n\noptions(viewer = NULL) # view in browser\n\nm = leaflet() %\u003e%\n  addProviderTiles(provider = providers$CartoDB.DarkMatter) %\u003e%\n  addGlPoints(data = pts, group = \"pts\") %\u003e%\n  setView(lng = 10.5, lat = 49.5, zoom = 4) %\u003e% \n  addLayersControl(overlayGroups = \"pts\")\n\nui \u003c- fluidPage(\n  leafglOutput(\"mymap\")\n)\n\nserver \u003c- function(input, output, session) {\n  output$mymap \u003c- renderLeaflet(m)\n}\n\nshinyApp(ui, server)\n```\n\u003cbr\u003e\n\n-----\n\n\n## Contact ##\n\nPlease file Pull requests, bug reports and feature requests at https://github.com/r-spatial/leafgl/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-spatial%2Fleafgl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-spatial%2Fleafgl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-spatial%2Fleafgl/lists"}