Skip to contents

This function adds 2.5D buildings to a Leaflet map using the OSM Buildings plugin.

Usage

addBuildings(
  map,
  buildingURL = "https://{s}.data.osmbuildings.org/0.2/59fcc2e8/tile/{z}/{x}/{y}.json",
  group = NULL,
  eachFn = NULL,
  clickFn = NULL,
  data = NULL
)

Arguments

map

A map widget object created from leaflet.

buildingURL

The URL template for the building data. Default is the OSM Buildings tile server:
"https://{s}.data.osmbuildings.org/0.2/59fcc2e8/tile/{z}/{x}/{y}.json".

group

The name of the group the buildings will be added to.

eachFn

A JavaScript function (using JS) that will be called for each building feature. Use this to apply custom logic to each feature.

clickFn

A JavaScript function (using JS) that will be called when a building is clicked. Use this to handle click events on buildings.

data

A GeoJSON object containing Polygon features representing the buildings. The properties of these polygons can include attributes like height, color, roofColor, and others as specified in the OSM Buildings documentation.

Details

The `data` parameter allows you to provide custom building data as a GeoJSON object. The following properties can be used within the GeoJSON:

  • height

  • minHeight

  • color/wallColor

  • material

  • roofColor

  • roofMaterial

  • shape

  • roofShape

  • roofHeight

See the OSM Wiki: Simple_3D_Buildings

See also

https://github.com/kekscom/osmbuildings/ for more details on the OSM Buildings plugin and available properties.

Other OSM-Buildings Plugin: setBuildingData(), setBuildingStyle(), updateBuildingTime()

Examples

library(leaflet)
library(leaflet.extras2)

leaflet() %>%
  addProviderTiles("CartoDB") %>%
  addBuildings(group = "Buildings") %>%
  addLayersControl(overlayGroups = "Buildings") %>%
  setView(lng = 13.4, lat = 52.51, zoom = 15)