Skip to content

Instantly share code, notes, and snippets.

@smschauhan
Created May 9, 2014 21:29
Show Gist options
  • Save smschauhan/17f64e61afff639b5055 to your computer and use it in GitHub Desktop.
Save smschauhan/17f64e61afff639b5055 to your computer and use it in GitHub Desktop.
rCharts - leaflet - demo

RCharts - Loading maps with different tiles

This notebook is an elementary example of how one can load a map with center at lat, long and a specific zoom. The first cell is mandatory and should not be modified, apart from the height and width parameters.

Due to an RCloud bug(will be fixed pretty soon), please load only one map per markdown cell - just as the example below.

# Always have this code on the top
library(rCharts)
options(
  rcharts.mode = 'iframesrc', 
  rcharts.cdn = TRUE,
  RCHART_WIDTH = 700,
  RCHART_HEIGHT = 400
)

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'Esri.WorldStreetMap')
map2

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'Esri.WorldImagery')
map2

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'Esri.NatGeoWorldMap')
map2

Display a regular map with default tiles

The Knitr directives(comment=NA, results='asis' should be retained)


map1 = Leaflet$new()
map1$setView(c(45.50867, -73.55399), 13)
map1

Display a regular map with tiles from the GIS server

This map is being pull from the internal gis tile server and can take a few seconds to load. These tiles are not as colorful as the OSMap version, and are a better background due to a faded background. Please be patient, or just use Sys.sleep to supress rendering output until the map is loaded. The Knitr directives(comment=NA, results='asis' should be retained)

map1 = Leaflet$new()
map1$setView(c(45.50867, -73.55399), 13)
map1$tileLayer("http://gis.research.att.com/tiles-light/{z}/{x}/{y}.png", zoom = 8)
Sys.sleep(3)
map1

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'Stamen.Terrain')
map2

Display a regular map with a different tile style

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'Stamen.Watercolor')
map2

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'OpenStreetMap.BlackAndWhite')
map2

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'Thunderforest.Landscape')
map2

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'MapQuestOpen.OSM')
map2

Display a regular map with a different tile

You can choose from many different tile layers available in leaflet. The provider can be selected from the page here. Let's run a few of them. The Knitr directives(comment=NA, results='asis' should be retained)

map2 = Leaflet$new()
map2$setView(c(45.50867, -73.55399), 13)

map2$tileLayer(provider = 'OpenMapSurfer.Grayscale')
map2
# scratch file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment