Reputation: 1111
Whenever the mouse pointer is hovering over a leaflet map, the browser does not scroll up or down. This happens even when I affix minZoom and maxZoom to an equal value. Is there a solution to this?
php.poverty.map.2009 <-
leaflet(options = leafletOptions(minZoom = 12, maxZoom = 12)) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = php.df.polygon.2009,
fillColor = ~php.pal.2009(percent),
color = "#b2aeae", # must use hex colors
fillOpacity = 0.7,
weight = 0.3,
smoothFactor = 0.2,
popup = php.popup.2009) %>%
addLegend(pal = php.pal.2009,
values = php.df.polygon.2009$percent,
position = "bottomright",
title = "Percent of Households <br> Living below Poverty <br> (Census, 2009)",
labFormat = labelFormat(suffix = "%"))
php.poverty.map.2009
Upvotes: 3
Views: 3049
Reputation: 893
In my second attempt at answering this question I came across the leaflet.extras
package which implements a selection of leaflet plugins in R. One of these is the Leaflet.Sleep
plugin which can be implemented by adding the suspendScroll()
function to your leaflet map in R.
First, install leaflet.extras
using devtools::install_github('bhaskarvk/leaflet.extras')
.
library(leaflet)
library(leaflet.extras)
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
suspendScroll()
See this page for an example.
Upvotes: 4
Reputation: 19069
A Leaflet map has a documented scrollWheelZoom
option that allows you to disable scrollwheel interactions (but still allows other ways to zoom the map, such as the zoom buttons).
In plain Javascript, this is used like var map = L.map({ scrollWheelZoom: false })
. I'm not well versed in R, but you should try leaflet(options = leafletOptions(scrollWheelZoom = false))
or variations thereof.
Upvotes: 2
Reputation: 893
I think your zoom options might need to go in the providerTiles function. I.e. addProviderTiles("CartoDB.Positron", options = providerTileOptions(minZoom=12, maxZoom=12))
Upvotes: 1