add_geojson: Add GeoJson

View source: R/google_map_layer_geojson.R

add_geojsonR Documentation

Add GeoJson


Add GeoJson


  data = get_map_data(map),
  layer_id = NULL,
  style = NULL,
  mouse_over = FALSE,
  update_map_view = TRUE



a googleway map object created from google_map()


A character string or geoJSON literal of correctly formatted geoJSON


single value specifying an id for the layer.


Style options for the geoJSON. See details


logical indicating if a feature should be highlighted when the mouse passess over


logical specifying if the map should re-centre according to the geoJSON


The style of the geoJSON features can be defined inside the geoJSON itself, or specified as a JSON string or R list that's used to style all the features the same

To use the properties in the geoJSON to define the styles, set the style argument to a JSON string or a named list, where each name is one of

All Geometries

  • clickable

  • visible

  • zIndex

Point Geometries

  • cursor

  • icon

  • shape

  • title

Line Geometries

  • strokeColor

  • strokeOpacity

  • strokeWeight

Polygon Geometries (Line Geometries, plus)

  • fillColor

  • fillOpacity

and where the values are the the properties of the geoJSON that contain the relevant style for those properties.

To style all the features the same, supply a JSON string or R list that defines a value for each of the style options (listed above)

See examples.


## Not run: 

## use the properties inside the geoJSON to style each feature
google_map(key = map_key) %>%
  add_geojson(data = geo_melbourne)

## use a JSON string to style all features
style <- '{ "fillColor" : "green" , "strokeColor" : "black", "strokeWeight" : 0.5}'
google_map(key = map_key) %>%
  add_geojson(data = geo_melbourne, style = style)

## use a named list to style all features
style <- list(fillColor = "red" , strokeColor = "blue", strokeWeight = 0.5)
google_map(key = map_key) %>%
  add_geojson(data = geo_melbourne, style = style)

## GeoJSON from a URL
url <- ''
google_map(key = map_key) %>%
  add_geojson(data = url, mouse_over = T)

## End(Not run)

googleway documentation built on Aug. 22, 2023, 9:13 a.m.