Skip to contents

Adds a choropleth map layer for citys with additional customization options.

Usage

addCityShape(
  map,
  data,
  adcode = NULL,
  layerId = NULL,
  group = NULL,
  valueProperty = NULL,
  labelProperty = NULL,
  labelOptions = leaflet::labelOptions(),
  popupProps = NULL,
  popupOptions = leaflet::popupOptions(),
  scale = c("white", "red"),
  steps = 5,
  mode = "q",
  channelMode = c("rgb", "lab", "hsl", "lch"),
  padding = NULL,
  correctLightness = FALSE,
  bezierInterpolate = FALSE,
  colors = NULL,
  stroke = TRUE,
  color = "#ffffff",
  weight = 1,
  opacity = 0.5,
  fillOpacity = 0.7,
  dashArray = NULL,
  smoothFactor = 1,
  noClip = FALSE,
  pathOptions = leaflet::pathOptions(),
  highlightOptions = leaflet::highlightOptions(weight = 2, color = "#000000", fillOpacity
    = 1, opacity = 1, bringToFront = TRUE, sendToBack = TRUE),
  legendOptions = NULL,
  ...
)

Arguments

map

The leaflet map object to add the layer to.

data

A data frame containing the data to be visualized.

adcode

China administrative division code

layerId

An optional string to identify the layer.

group

An optional string for grouping data.

valueProperty

The property in the geojson data that corresponds to the value to be mapped.

labelProperty

The property in the geojson data that will be used for labels.

labelOptions

Options for labels, defaults to leaflet's labelOptions.

popupProps

A named vector of properties to display in the popup.

popupOptions

Options for popups, defaults to leaflet's popupOptions.

scale

A vector of colors to use for the scale of the choropleth map.

steps

The number of steps for the color scale.

mode

The mode for the color scale, can be "q" for quantile, "e" for equal interval, etc.

channelMode

The color channel mode, can be "rgb", "lab", "hsl", or "lch".

padding

Optional padding for the choropleth layer.

correctLightness

A logical value to correct lightness for color scales.

bezierInterpolate

Whether to use bezier interpolation for the lines.

colors

An optional vector of colors to override the default color scale.

stroke

Whether to draw the stroke along the paths.

color

The color for the paths, defaults to white.

weight

The weight for the paths.

opacity

The opacity for the paths.

fillOpacity

The fill opacity for the paths.

dashArray

An optional array to create dashed lines.

smoothFactor

A factor to smooth the factor for the paths.

noClip

Whether to disable clipping of the paths.

pathOptions

Additional options for the paths, defaults to leaflet's pathOptions.

highlightOptions

Options for highlighting features, defaults to leaflet's highlightOptions.

legendOptions

Options for the legend.

...

Additional arguments passed to other functions.

Value

The modified leaflet map object with the added layer.

Examples




# use adcode,adcode can be obtained from leafletZH::china_city
library(leaflet)
library(leaflet.extras)
library(leafletZH)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
data <- data.frame(adcode = seq(110101, 110110, 1), value = runif(5))
leaflet() |>
  leafletZH::addTilesAmap() |>
  addCityShape(
    data = data, adcode = "adcode", valueProperty = "value",
    popupProps = c("value")
  ) |>
  setView(lng = 116, lat = 40, zoom = 8)