Search code examples
javascriptrshinyr-leaflet

Stop zoom on scroll and use ctrl + scroll to zoom the map and move map with two fingers on mobile?


I am creating 100 + leaflet maps in my shiny app. The maps are 100% of the width of the page, so when the user goes to scroll down the page it zooms the map but I would like it to continue scrolling down the page.

I've found this similar answer but I want the scrollWheelZoom to disabled all the time for every map.

Is there a way to change the Javascript to disable the scrollWheelZoom for all maps?

Shiny: Is there a way to enable mouse wheel zoom only after click on map in shiny?


Solution

  • Depending on how you're creating the maps, something like this should work:

    output$map <- renderLeaflet({
        leaflet(options = leafletOptions(minZoom = 0,
                                         scrollWheelZoom = FALSE))  %>%
          addTiles()
    })
    

    The scroolWheelZoom property which is now built in to R shiny does the trick.