Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing zoom to option #56

Closed
ghost opened this issue Jan 31, 2017 · 6 comments
Closed

Removing zoom to option #56

ghost opened this issue Jan 31, 2017 · 6 comments

Comments

@ghost
Copy link

ghost commented Jan 31, 2017

Hi,

How do you remove the 'zoom to' option from the map? See attached picture, under the legend.

Many thanks,
Wanda

2017-01-31 13_00_42-viewer zoom

@timelyportfolio
Copy link
Contributor

timelyportfolio commented Jan 31, 2017

@wandab, please include reproducible code next time. I include some code below to accomplish removal of the zoom-to home buttons.

library(mapview)

# get the leaflet instance
mp <- mapview(breweries91)@map

# show where the zoom to calls exist
mp$x$calls
# more specifically
Filter(
  function(cl) {
    cl$method == "addHomeButton"
  },
  mp$x$calls
)

# write a function to remove all zoom to calls
#   use the Filter above but change == to !=
remove_zoomto <- function(leafmap) {
  if(inherits(leafmap, "mapview")) {
    leafmap <- leafmap@map
  }
  
  remove_zoomto <- function(leafmap) {
  if(inherits(leafmap, "mapview")) {
    leafmap <- leafmap@map
  }
  
  leafmap$x$calls <- Filter(
    function(cl) {
      cl$method != "addHomeButton"
    },
    leafmap$x$calls
  )
  
  leafmap
}
  
  leafmap
}

# try it out
remove_zoomto(mp)

# try with a mapview
remove_zoomto(
  mapview(breweries91)
)

@ghost
Copy link
Author

ghost commented Jan 31, 2017

Many thanks for the reply.

I have used a very simple code:
Survey <- SpatialPointsDataFrame(data[,c("Longitude", "Latitude")], data[,1:4])
proj4string(Survey) <- CRS("+init=epsg:4326")
mapview(Survey, zcol = "Year", burst = TRUE, legend = TRUE)

And according to this the zoom to function appears automatically on the map.

Your code didn't work for me.

@timelyportfolio
Copy link
Contributor

@wandab, please include the error next time. I spotted the error and fixed in the above reply. Also, I have added a reproducible example that seems similar to your objective.

# example from ?mapview
library(mapview)
library(sp)

data("meuse")
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")

mapview(meuse, zcol = "soil", burst = TRUE) # three layers

# write a function to remove all zoom to calls
#   use the Filter above but change == to !=
remove_zoomto <- function(leafmap) {
  if(inherits(leafmap, "mapview")) {
    leafmap <- leafmap@map
  }
  
  leafmap$x$calls <- Filter(
    function(cl) {
      cl$method != "addHomeButton"
    },
    leafmap$x$calls
  )
  
  leafmap
}

remove_zoomto(
  mapview(meuse, zcol = "soil", burst = TRUE)
)

@ghost
Copy link
Author

ghost commented Jan 31, 2017

This worked, thank you.

@tim-salabim
Copy link
Member

This can also easily be avoided by setting homebutton = FALSE

library(mapview)
library(sp)

data("meuse")
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")

mapview(meuse, zcol = "soil", burst = TRUE, homebutton = FALSE) 

@michaeldgarber
Copy link

michaeldgarber commented Oct 12, 2022

In case someone lands on this old page via a web search, note that mapview now has a function, removeMapJunk, for this purpose: https://r-spatial.github.io/mapview/reference/removeMapJunk.html

For example:

library(mapview)
mv_breweries_with_junk = mapview(breweries)
mv_breweries_without_junk = removeMapJunk(mv_breweries_with_junk, junk = c("zoomControl", "layersControl"))
mv_breweries_without_junk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants