R传单zoomControl选项 [英] R leaflet zoomControl option

查看:37
本文介绍了R传单zoomControl选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用传单在R中构建地图工具,我想将缩放限制在特定区域,但是 setMaxBounds 函数似乎没有任何作用.

I'm building a map tool in R using leaflet, and I would like to restrict the zoom to a certain area, but the setMaxBounds function doesn't seem to have any effect.

library(dplyr)
library(leaflet)
library(tigris)

ohio_map <- leaflet(counties('OH', cb = TRUE)) %>%
  addProviderTiles("CartoDB.Positron") %>%
  addPolygons(weight = .3,
              color = "#229922",
              layerId = ~NAME) %>%
  setMaxBounds(lng1 = -84.800,
               lat1 = 42.000,
               lng2 = -80.500,
               lat2 = 38.400)
ohio_map

这显示了地图的正确区域,但并不阻止缩小.

This shows the right area of the map, but doesn't prevent zooming out.

最好完全删除缩放控件,以便我可以用更适合手边应用程序的内容替换导航.我找到了 zoomControl 选项,但一直无法弄清楚将其放在R中以使其正常工作.

It would be even better to remove the zoom controls altogether, so that I could replace the navigation with something more suitable to the application at hand. I found a zoomControl option, but haven't been able to figure out where to put that in R to get it to work.

正如@Symbolix所指出的那样,setMaxBounds确实与我要寻找的东西有所不同.我真的只想完全禁用缩放,并删除控件.我在小册子JavaScript API文档中介绍了 zoomControl 选项,想要,但是我在R包中找不到该选项.

As pointed out by @Symbolix, setMaxBounds really is something different than what I'm looking for. I really just want to disable zooming altogether, and remove the controls. The zoomControl option described in the leaflet JavaScript API docs appears to be what I want, but I cannot find that option in the R package.

推荐答案

要删除缩放控件,请在 leafletOptions 中设置 zoomControl = FALSE .例如:

To remove the zoom controls, set zoomControl = FALSE in leafletOptions. For example:

library(leaflet)
leaflet(options = leafletOptions(zoomControl = FALSE)) %>%
    addTiles()

请注意,这不会通过鼠标滚轮双击或滚动来禁用缩放.您可以再次在 leafletOptions 中设置 minZoom maxZoom 来控制缩放级别.要禁用缩放,请将 minZoom 设置为等于 maxZoom :

Note that this will not disable zooming via double-clicking or scrolling with your mouse wheel. You can control the zoom level by setting minZoom and maxZoom, again in leafletOptions. To disable zooming, set minZoom equal to maxZoom:

leaflet(options = leafletOptions(zoomControl = FALSE,
                                 minZoom = 3, maxZoom = 3)) %>%
    addTiles()

作为奖励,如果您想要地图的静态"视图,还可以通过 Dragging 选项禁用拖动:

As a bonus, in case you want a "static" view of a map, you can also disable dragging via the dragging option:

leaflet(options = leafletOptions(zoomControl = FALSE,
                                 minZoom = 3, maxZoom = 3,
                                 dragging = FALSE)) %>%
    addTiles()

请注意,您可能需要安装 leaflet 的最新github版本.实现以上选项:

Note that you may need to install the latest github version of leaflet to implement the above options:

# install github version of leaflet
if (!require('devtools')) install.packages('devtools')
devtools::install_github('rstudio/leaflet')`

这篇关于R传单zoomControl选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆