防止缩小传单 R-Map?
Prevent zooming out in leaflet R-Map?
我用传单R包制作了一张传单地图。
结果如下:
我对它很满意,但是当我将它嵌入网站并用我的笔记本电脑向下滚动文章时,我经常不小心将地图缩小,然后看起来像这样:
用户还必须放大并查看地图的中间部分,这让我很恼火。
有没有办法冻结地图的一部分,就像你可以像往常一样放大但不能缩小得比图像上的更多?我尝试在我的代码中设置视图,但您仍然可以缩小,所以我删除了那部分。
mymap <- leaflet() %>%
addProviderTiles("Esri.WorldGrayCanvas") %>%
addPolygons(data = dortmund,
fillColor = ~palette(student1$Anteil), ## we want the polygon filled with
## one of the palette-colors
## according to the value in student1$Anteil
fillOpacity = 0.6, ## how transparent do you want the polygon to be?
color = "darkgrey", ## color of borders between districts
weight = 1.5, ## width of borders
popup = popup1, ## which popup?
group="<span style='color: #7f0000; font-size: 11pt'><strong>2000</strong></span>")%>%
## which group?
## the group's name has to be the same as later in "baseGroups", where we define
## the groups for the Layerscontrol. Because for this layer I wanted a specific
## color and size, the group name includes some font arguments.
## for the second layer we mix things up a little bit, so you'll see the difference in the map!
addPolygons(data = dortmund,
fillColor = ~palette(student2$Anteil),
fillOpacity = 0.2,
color = "white",
weight = 2.0,
popup = popup2,
group="2014")%>%
addLayersControl(
baseGroups = c("<span style='color: #7f0000; font-size: 11pt'><strong>2000</strong></span>", ## group 1
"2014" ## group 2
),
options = layersControlOptions(collapsed = FALSE))%>% ## we want our control to be seen right away
addLegend(position = 'topleft', ## choose bottomleft, bottomright, topleft or topright
colors = c('#fee0d2',
'#fcbba1',
'#fc9272',
'#fb6a4a',
'#ef3b2c',
'#cb181d',
'#a50f15',
'#67000d'),
labels = c('0%',"","","","","","",'26%'), ## legend labels (only min and max)
opacity = 0.6, ##transparency
title = "relative<br>amount") ## title of the legend
请原谅我糟糕的英语水平。如果回答我的问题很重要,完整代码在这里:http://journocode.com/2016/01/28/your-first-choropleth-map/。
非常感谢
将您的 addProviderTiles 替换为以下内容(设置您想要的最大和最小缩放级别:
addProviderTiles("Esri.WorldGrayCanvas",
options = providerTileOptions(minZoom=10, maxZoom=18))
我 发现非常有用的是一个“主页”按钮,它可以让您回到初始地图边界和缩放。
leaflet() |>
addTiles() |>
addEasyButton(easyButton(icon = "fas fa-home",
title = "Fly back home",
position = "topleft",
onClick = JS(paste0(
"function(btn, map) {
map.fitBounds([
[", -11.25, ",", 40, "], ",
"[", 47.9, ",", -15.37, "]
])
}"
)
))) |>
fitBounds(lng1 = 40, lat1 = -11.25,
lng2 = -15.37, lat2 = 47.9)
地理对象的边界框可以用sf::st_bbox()
计算。
我用传单R包制作了一张传单地图。
结果如下:
我对它很满意,但是当我将它嵌入网站并用我的笔记本电脑向下滚动文章时,我经常不小心将地图缩小,然后看起来像这样:
用户还必须放大并查看地图的中间部分,这让我很恼火。
有没有办法冻结地图的一部分,就像你可以像往常一样放大但不能缩小得比图像上的更多?我尝试在我的代码中设置视图,但您仍然可以缩小,所以我删除了那部分。
mymap <- leaflet() %>%
addProviderTiles("Esri.WorldGrayCanvas") %>%
addPolygons(data = dortmund,
fillColor = ~palette(student1$Anteil), ## we want the polygon filled with
## one of the palette-colors
## according to the value in student1$Anteil
fillOpacity = 0.6, ## how transparent do you want the polygon to be?
color = "darkgrey", ## color of borders between districts
weight = 1.5, ## width of borders
popup = popup1, ## which popup?
group="<span style='color: #7f0000; font-size: 11pt'><strong>2000</strong></span>")%>%
## which group?
## the group's name has to be the same as later in "baseGroups", where we define
## the groups for the Layerscontrol. Because for this layer I wanted a specific
## color and size, the group name includes some font arguments.
## for the second layer we mix things up a little bit, so you'll see the difference in the map!
addPolygons(data = dortmund,
fillColor = ~palette(student2$Anteil),
fillOpacity = 0.2,
color = "white",
weight = 2.0,
popup = popup2,
group="2014")%>%
addLayersControl(
baseGroups = c("<span style='color: #7f0000; font-size: 11pt'><strong>2000</strong></span>", ## group 1
"2014" ## group 2
),
options = layersControlOptions(collapsed = FALSE))%>% ## we want our control to be seen right away
addLegend(position = 'topleft', ## choose bottomleft, bottomright, topleft or topright
colors = c('#fee0d2',
'#fcbba1',
'#fc9272',
'#fb6a4a',
'#ef3b2c',
'#cb181d',
'#a50f15',
'#67000d'),
labels = c('0%',"","","","","","",'26%'), ## legend labels (only min and max)
opacity = 0.6, ##transparency
title = "relative<br>amount") ## title of the legend
请原谅我糟糕的英语水平。如果回答我的问题很重要,完整代码在这里:http://journocode.com/2016/01/28/your-first-choropleth-map/。
非常感谢
将您的 addProviderTiles 替换为以下内容(设置您想要的最大和最小缩放级别:
addProviderTiles("Esri.WorldGrayCanvas",
options = providerTileOptions(minZoom=10, maxZoom=18))
我
leaflet() |>
addTiles() |>
addEasyButton(easyButton(icon = "fas fa-home",
title = "Fly back home",
position = "topleft",
onClick = JS(paste0(
"function(btn, map) {
map.fitBounds([
[", -11.25, ",", 40, "], ",
"[", 47.9, ",", -15.37, "]
])
}"
)
))) |>
fitBounds(lng1 = 40, lat1 = -11.25,
lng2 = -15.37, lat2 = 47.9)
地理对象的边界框可以用sf::st_bbox()
计算。