Change The Default Position Of Zoom Control In Leaflet Map Of Shiny App
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
package sets the default position as topleft
in the source codes.
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');
Could I create a R function to set new position of zoomControl
? For example,
zoomControlPosition <- function(map, position = 'topleft') {
# New codes add here
}
I guess it involves some js
, but I have no experience of js
. Thanks for any suggestions.
Answer
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)
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM