add_vector_tiles: Add vector tile layer to the map

Description Usage Arguments Examples

Description

If you want to create and serve your own vector tiles you may check t-rex.

Usage

1
2
add_vector_tiles(ol, url, attribution = NULL, style = NULL,
  options = layer_options(), format = NULL)

Arguments

ol

map widget

url

url of the vector tiles service

attribution

attribution

style

style object or NULL (use default style)

options

general layer options, see layer_options

format

format of the vector tiles, MVT (mapbox vector tiles), TopoJSON, GeoJSON or NULL (guess format)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Not run: 
  # mapzen
  key <- "your_api_key"
  mapzen <- paste0(
    "https://tile.mapzen.com/mapzen/vector/v1/",
    "roads/{z}/{x}/{y}.topojson",
    "?api_key=", key
  )

  ol() %>%
    add_vector_tiles(mapzen, "Add mapzen attribution") %>%
    set_view(zoom = 16)

  # mapbox
  key <- "your_access_token"
  mapbox <- paste0(
    "https://{a-d}.tiles.mapbox.com/v4/",
    "mapbox.mapbox-streets-v7/",
    "{z}/{x}/{y}.vector.pbf",
    "?access_token=", key
  )
  attribution <- "Add mapbox attribution"

  ol() %>%
    add_vector_tiles(mapbox, attribution)

  # style the tiles
  ol() %>%
    add_vector_tiles(
      mapbox,
      attribution,
      style = stroke_style(color = "green") + fill_style()
    ) %>%
    set_view(zoom = 14)

  # use javascript style function
  mapbox_style <- system.file("javascript/mvt_style_function.js", package = "openlayers") %>%
    read_js_function()

## End(Not run)

crazycapivara/openlayersr documentation built on June 4, 2019, 8:08 p.m.