在Shiny应用程序的传单地图中更改缩放控件的默认位置 [英] Change the default position of zoom control in leaflet map of Shiny app
问题描述
我正在使用Shiny应用程序创建传单地图,但要将缩放控件的默认位置从topleft
更改为topright
.
I am using Shiny app to create leaflet map, but want to change the default position of zoom control from topleft
to topright
.
R leaflet
软件包在源代码中将默认位置设置为topleft
.
R leaflet
package sets the default position as topleft
in the source codes.
遵循以下问题:自定义leaflet.js中的放大/缩小按钮,我们可以使用map.zoomControl.setPosition('topright');
更改其位置缩放控制.
Following this question: Customize Zoom in/out button in leaflet.js, we can use map.zoomControl.setPosition('topright');
to change position of zoom control.
var map = L.map('map', {
zoomControl: true
});
map.zoomControl.setPosition('topright');
我可以创建一个R函数来设置zoomControl
的新位置吗?例如,
Could I create a R function to set new position of zoomControl
? For example,
zoomControlPosition <- function(map, position = 'topleft') {
# New codes add here
}
我猜它涉及到某些js
,但是我没有js
的经验.感谢您的任何建议.
I guess it involves some js
, but I have no experience of js
. Thanks for any suggestions.
推荐答案
我弄清楚了如何更改zoomControl
的位置.您可以从我的传单包的分支中找到此功能: https://github.com/byzheng/leaflet /commit/fdf9fb159adbc0e36cc2bd7d7b33c72c17c468f6
I figure out how to change the position of zoomControl
. You can find this feature from my fork of leaflet package: https://github.com/byzheng/leaflet/commit/fdf9fb159adbc0e36cc2bd7d7b33c72c17c468f6
这是使用它的最小示例:
This is an minimum example to use it:
library(shiny)
library(leaflet)
ui <- fluidPage(
leafletOutput("mymap")
)
server <- function(input, output, session) {
output$mymap <- renderLeaflet({
leaflet() %>%
addTiles() %>%
zoomControlPosition('topright')
})
}
shinyApp(ui, server)
这篇关于在Shiny应用程序的传单地图中更改缩放控件的默认位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!