当我将一个简单的地图添加到闪亮的应用程序中而不添加多边形时,zoom参数可以正常工作,并且该地图会按预期进行初始化。
另一方面,当我使用add_polygon()添加多边形时,地图的初始化比实际情况要缩小得多。
为什么会这样?
这是我的代码:
library(mapdeck)
library(sf)
sf = st_as_sf(my_LargeSpatialPolygonDataframe)
output$my_map = renderMapdeck({
mapdeck(token = mytoken, location = c(a, b), zoom = 12,
bearing = -45.00, pitch = 0, style = 'mapbox://styles/mapbox/light-v9') %>%
add_polygon(data = sf,
stroke_colour = "#000000",
stroke_width = 20,
stroke_opacity = 200,
fill_opacity = 0,
layer = "init_polygons")
})
答案 0 :(得分:2)
当您通过add_
函数之一添加图层时,该图层将计算将整个数据容纳在窗口框架中所需的缩放级别。您可以使用update_view = FALSE
这是一个可重复的例子
此处add_polygon()
图层将重新缩放地图以显示该图层中的所有数据。这是您所看到的行为。
library(mapdeck)
set_token("MAPBOX_TOKEN")
mapdeck(
location = c(144.9, -37.8)
, zoom = 11
, bearing = -45.00
, pitch = 0
, style = mapdeck_style("light")
) %>%
add_polygon(
data = spatialwidget::widget_melbourne
, stroke_colour = "#000000"
, stroke_width = 20
, stroke_opacity = 200
, fill_opacity = 0
, layer_id = "init_polygons"
)
这告诉图层不要更新视图,因此将使用原始的location()
值。
mapdeck(
location = c(144.9, -37.8)
, zoom = 11
, bearing = -45.00
, pitch = 0
, style = mapdeck_style("light")
) %>%
add_polygon(
data = spatialwidget::widget_melbourne
, stroke_colour = "#000000"
, stroke_width = 20
, stroke_opacity = 200
, fill_opacity = 0
, layer_id = "init_polygons"
, update_view = F
)