Giter Site home page Giter Site logo

r-spatial / mapview Goto Github PK

View Code? Open in Web Editor NEW
506.0 38.0 92.0 483.02 MB

Interactive viewing of spatial data in R

Home Page: https://r-spatial.github.io/mapview/

License: GNU General Public License v3.0

R 12.22% CSS 1.80% HTML 24.58% JavaScript 61.40%
r leaflet visualization web-mapping gis maps spatial

mapview's People

Contributors

ateucher avatar davidkretch avatar dickoa avatar edzer avatar fdetsch avatar gden173 avatar joshualerickson avatar jsta avatar lbusett avatar mdsumner avatar milesmcbain avatar nowosad avatar olivroy avatar pat-s avatar pierreroudier avatar ranghetti avatar stewartmacdonald avatar tim-salabim avatar timelyportfolio avatar trafficonese avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapview's Issues

add support for simple features

here's a first hack at incorporating methods for the new simple features

#devtools::install_github("edzer/sfr")
library(mapview)
library(sf)

sfLINECoordinates <- function(x) {

  stopifnot(inherits(x, "sf"))

  segments <- lapply(seq(x$geom), function(i) {
    nr <- nrow(x$geom[[i]])
    x$geom[[i]][1:nr, 1:2]
  })

  return(segments)

}

ln <- as.sf(atlStorms2005)

ln_segments <- sfLINECoordinates(ln)

m <- leaflet() %>% addTiles()

for (i in ln_segments) {
  m <- garnishMap(m, addPolylines, lng = i[, 1], lat = i[, 2])
}

garnishMap(m, addMouseCoordinates, addScaleBar, position = "bottomleft")

Error in map$dependencies : $ operator not defined for this S4 class

When using the latest leaflet from github together with mapView, I get this error:

mapview() %>% addMeasure()
Error in map$dependencies : $ operator not defined for this S4 class

While using leaflet directly works:

leaflet() %>% addMeasure()

This is true not only for addMeasure(), but also for other add-in plugins to github leaflet , such as addGraticule(), addMiniMap() etc.

At one point it actually worked, but then I updated both packages and it seems to be broken now.

EDIT: It seems to work if I issue:

mapview() %>% addMouseCoordinates() %>% addMiniMap()

However, the mouse coords are not shown if using mapView from Cran, only with mapView from github.

Error in mapview() with development version 1.1.8

library(leaflet)
library(mapview)
library(sp)

pt <- data.frame(x = 174.764474, y = -36.877245)
coordinates(pt) <- ~ x + y
proj4string(pt) <- "+init=epsg:4326"

img <- system.file("img","Rlogo.png",package="png")  # this does  work though error applies
mapview(pt, popup = popupImage(img))
Error in .local(x, ...) : min and max x are the same

This worked okay with my previous version 1.1.0

Here is sessionInfo()

R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sp_1.2-3           mapview_1.1.8      leaflet_1.0.1.9004

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.6         raster_2.5-8        magrittr_1.5        gdalUtils_2.0.1.7   munsell_0.4.3       colorspace_1.2-6    viridisLite_0.1.3  
 [8] lattice_0.20-33     foreach_1.4.3       plyr_1.8.4          tools_3.3.0         webshot_0.3.2       rgdal_1.1-10        grid_3.3.0         
[15] R.oo_1.20.0         png_0.1-7           latticeExtra_0.6-28 htmltools_0.3.5     iterators_1.0.8     digest_0.6.10       RColorBrewer_1.1-2 
[22] htmlwidgets_0.7     R.utils_2.3.0       codetools_0.2-14    scales_0.4.0        R.methodsS3_1.7.1   stats4_3.3.0        satellite_0.2.0   

Error: pandoc document conversion failed with error 251

I'm trying to export my mapview in R using built-in mapview-function called mapshot. I get this error message:

**pandoc.exe: Out of memory

Error: pandoc document conversion failed with error 251

In addition: Warning message: running command 'C:/PROGRA~2/Pandoc/pandoc +RTS -K512m -RTS ...**

How do I increase the Pandoc memory size permanently or even temporary in R without using a Rmarkdown-file? Is there a handle for this? The function in question is called mapshot, for example mapshot(m, url=paste0(getwd(), "/heatmap.html")).

Legend manipulation in .Rmd leads to deletion of the entire legend

When integrating a mapviewOBJECT@map in a .Rmd file, a manipulation of the legend (for example changing the layer.name) results in a map that does not include any legend at all.

Try to knitr this in a .Rmd file:

library("mapview")
library("sp")
# load example data
data(meuse)
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")
# map does not show any legend at all:
mapview(meuse, zcol="copper", layer.name = "Concentration of Copper")@map

mapview in R shiny

Hi
I create an interactive map using mapView
example
mapView(hspdf, "CDP", fill = TRUE, color = cr, alpha.regions = 0.8)
where hspdf is hexagonal polygons , CDP are corresponding values of each polygon.

Now I put that in R shiny but I am getting error as R shiny does not have function related mapView.
However it has function for leaflet which doesn't nor work for mapview.
Is there any way to put mapview within R shiny or How to change mapView (mentioned above) to leaflet?

with regards
-Debasish

0

in SPDF zcol overrrides layer.name

When zcol is specified for a SpatialPointsDataFrame, any argument specifying layer.name is ignored:

## ignores layer.name
mapview(meuse, zcol="copper", layer.name = "Concentration of Copper")

## uses layer.name
mapview(meuse, layer.name = "Concentration of Copper")

Possibly also true for other methods (polygons, lines)

installing mapview

Hi I am trying to install mapview -

install.packages("mapview")
Installing package into ‘/Volumes/Users/debasish/Library/R/3.3/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.3/mapview_1.2.0.tgz'
Content type 'application/x-gzip' length 2821011 bytes (2.7 MB)
==================================================
downloaded 2.7 MB
The downloaded binary packages are in
/var/folders/5_/f8l_q2590_z_30dr30f8n60h00017z/T//RtmpvtOO6i/downloaded_packages

> library(mapview)
Error in get(method, envir = home) :
lazy-load database '/Volumes/Users/debasish/Library/R/3.3/library/rgdal/R/rgdal.rdb' is corrupt
In addition: Warning messages:
1: In .registerS3method(fin[i, 1], fin[i, 2], fin[i, 3], fin[i, 4], :
restarting interrupted promise evaluation
2: In get(method, envir = home) :
restarting interrupted promise evaluation
3: In get(method, envir = home) : internal error -3 in R_decompress1
Error: package or namespace load failed for ‘mapview’

I was trying using github -

**> library(devtools)

install_github("environmentalinformatics-marburg/mapview")**
Downloading GitHub repo environmentalinformatics-marburg/mapview@master
from URL https://api.github.com/repos/environmentalinformatics-marburg/mapview/zipball/master
Installing mapview
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore
--quiet CMD INSTALL
'/private/var/folders/5_/f8l_q2590_z_30dr30f8n60h00017z/T/RtmpvtOO6i/devtools44a469623d6c/environmentalinformatics-marburg-mapview-f6a67f6'
--library='/Volumes/Users/debasish/Library/R/3.3/library' --install-tests

  • installing source package ‘mapview’ ...
    ** libs
    clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Volumes/Users/debasish/Library/R/3.3/library/Rcpp/include" -fPIC -Wall -mtune=core2 -g -O2 -c RcppExports.cpp -o RcppExports.o
    clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Volumes/Users/debasish/Library/R/3.3/library/Rcpp/include" -fPIC -Wall -mtune=core2 -g -O2 -c brewCppFun.cpp -o brewCppFun.o
    clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Volumes/Users/debasish/Library/R/3.3/library/Rcpp/include" -fPIC -Wall -mtune=core2 -g -O2 -c mapviewCppFun.cpp -o mapviewCppFun.o
    clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o mapview.so RcppExports.o brewCppFun.o mapviewCppFun.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
    installing to /Volumes/Users/debasish/Library/R/3.3/library/mapview/libs
    ** R
    ** data
    *** moving datasets to lazyload DB
    ** inst
    ** preparing package for lazy loading
    Warning in runHook(".onLoad", env, package.lib, package) :
    internal error -3 in R_decompress1
    Error in runHook(".onLoad", env, package.lib, package) :
    lazy-load database '/Volumes/Users/debasish/Library/R/3.3/library/rgdal/R/rgdal.rdb' is corrupt
    ERROR: lazy loading failed for package ‘mapview’
  • removing ‘/Volumes/Users/debasish/Library/R/3.3/library/mapview’
  • restoring previous ‘/Volumes/Users/debasish/Library/R/3.3/library/mapview’
    Error: Command failed (1)

How to fix this problem.

with regards
-Deb

How can I add a leaflet layer to mapview

I have create a mapview of spatialPoint object, and I want to add a static label for each point, which may need the addMarkers function to create a new layer, finally I use mapvew+newlayer, but it dose not work.

Data <- structure(list(Name = structure(1:3, .Label = c("M1", "M2", "M3"), 
                                        class = "factor"), 
                       Latitude = c(52L, 52L, 51L), 
                       Longitude = c(50L, 50L, 50L), 
                       Altitude = c(97L, 97L, 108L)), 
                  .Names = c("Name", "Latitude", "Longitude", "Altitude"), 
                  class = "data.frame", row.names = c(NA, -3L))
rawdata=Data

Data$lat <- jitter(Data$Latitude, factor = 0.0001)
Data$lon <- jitter(Data$Longitude, factor = 0.0001)
coordinates(Data) <- ~ lon + lat
proj4string(Data) <- "+init=epsg:4326"
m=mapview(Data,popup="Name") 


m+leaflet() %>%addMarkers(~Longitude, ~Latitude, label=~Name, labelOptions=labelOptions(noHide=T),data=rawdata)

mapshot: Error: pandoc document conversion failed with error 97

I'm trying to save the map by using mapshot.
E.g.:

m <- mapview(breweries91)
mapshot(m, url = paste0(getwd(), "/map.html"))

But:

pandoc: Could not find data file map_files/leaflet-0.7.7/
Error: pandoc document conversion failed with error 97

I'm using pandoc 1.12.2.1 and the latest mapview and leaflet from Github.

Cannot establish dependency in renderMapview

for example, if I insert req(val <- input$my_slider) to the code chunk.

Listening on http://127.0.0.1:5822
Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
Stack trace (innermost first):
    56: .getReactiveEnvironment()$currentContext
    55: .subset2(x, "impl")$get
    54: $.reactivevalues
    53: $
    52: eval
    51: eval
    50: inherits
    49: isTruthy
    48: fun_
    47: dotloop
    46: req
    45: slot [/Users/showsle/R/InefficientInv/server.R#50]
    44: mapview2leaflet
    43: renderMapview
    42: server [/Users/showsle/R/InefficientInv/server.R#49]
     1: runApp
Error in .getReactiveEnvironment()$currentContext() : 
  Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

package version 1.2.0

`spplot` fails with single-feature `SpatialPoints` object.

Running the following code

library(sp)
library(mapview)

spt <- SpatialPoints(matrix(c(-77.03673, 38.89761), ncol = 2), 
                     proj4string = CRS("+init=epsg:4326"))

m <- mapview(spt)
spplot(m)

throws this error:

 Error in cut.default(as.matrix(z), cuts, dig.lab = 4, include.lowest = TRUE) : 
  'breaks' are not unique

plainview equivalent for vector data

Discussed on twitter, but I thought perhaps this issue would serve as a better forum for determining a good plainview equivalent for vector data. @tim-salabim, what would be some data sources that you have in mind? Would you like the view to be static, or just very "plain"/barebones? I assume quick is a primary concern here.

example(mapview) crashes RStudio on windows

Crash occurs on the line reading: mapView(meuse.grid, zcol = "soil")

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils    
[5] datasets  methods   base     

other attached packages:
[1] mapview_1.1.0  leaflet_1.0.1 
[3] httr_1.0.0     RCurl_1.95-4.8
[5] bitops_1.0-6  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.5         raster_2.5-2       
 [3] magrittr_1.5        gdalUtils_2.0.1.7  
 [5] munsell_0.4.3       viridisLite_0.1.3  
 [7] colorspace_1.2-6    lattice_0.20-33    
 [9] R6_2.1.2            foreach_1.4.3      
[11] plyr_1.8.3          stringr_1.0.0      
[13] tools_3.2.2         webshot_0.3        
[15] rgdal_1.1-1         grid_3.2.2         
[17] png_0.1-7           R.oo_1.19.0        
[19] latticeExtra_0.6-26 htmltools_0.3.5    
[21] iterators_1.0.8     digest_0.6.9       
[23] RColorBrewer_1.1-2  htmlwidgets_0.6    
[25] R.utils_2.1.0       codetools_0.2-14   
[27] sp_1.2-2            stringi_1.0-1      
[29] scales_0.4.0        R.methodsS3_1.7.0  
[31] stats4_3.2.2        satellite_0.2.0

Rasters over international date line

Mapview seems to not be supporting rasters going over the international date line.

This works fine:

library(raster)
r <- raster(xmn = 165, xmx = 180, ymn = -50, ymx = -31, crs = "+init=epsg:4326", nrows = 50, ncols = 50)
r[] <- rnorm(ncell(r))
mapview(r)

But not this, with the raster being cropped and the cells being stretched:

r <- raster(xmn = 165, xmx = 185, ymn = -50, ymx = -31, crs = "+init=epsg:4326", nrows = 50, ncols = 50)
r[] <- rnorm(ncell(r))
mapview(r)

Any idea how I can make this work?
Thank you for your package. This is quite promising.


R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

How can I change the initial zoom level for mapview?

1.How can I change the zoom level for mapview? is there a parameter for setting zoom, or a scale factor that can change the default zoom level with 90% or 80% percent?
2.and how can I change the zoom level change step for mouse action, now the zoom level change from 7 to 8 or 6 when I scroll the mouse, I want that change by 0.5, that is from 7 to 7.5 or 6.5 once.

Cannot compile github version on MacOSX 10.9.5

After
library(devtools)
install_github("environmentalinformatics-marburg/mapview", ref = "master")
I get:
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/mapview/libs/mapview.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/mapview/libs/mapview.so, 6): no suitable image found. Did find:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/mapview/libs/mapview.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03
Error: loading failed
Execution halted

No idea what to do.
Agus

weight parameter is incorrectly passed to leaflet

Hi, I have found a problem with the 'weight' argument of mapView(). When weight is passed as a variable or a manually constructed numeric vector, mapView() generates all the available objects multiple times and creates them with all the different weights passed to it. So basically, you can only currently pass numeric vector of length one to 'weight'. If one wants to attach a variable to 'weight', one needs to use leaflet functions directly.

p.s. appreciate your work on mapview!

Kind regards,
Egor

meuse.grid$part.a wrongly rendered

Tim, great work!

I noticed that in one of the raster maps part_a was rendered wrongly, in the example

mapView(meuse_rst)

however,

unique(meuse.grid$part.a)
[1] 1 0

so we shouldn't see more than two colours.

feature ID (row.names)

When querying a feature, it would be nice if in addition to the long/lat and attribute value, the feature ID, obtained by row.names(obj), would appear. This makes it easier to identify administrative districts, or sample IDs.

When clicking in polygons, we don't get the long/lat of the clicked point, but that of the center point of the polygon. I'd suggest to replace long/lat with feature ID (row.name) in case of polygons (and perhaps lines).

Error mapview()

I would like to report an error in mapview() version 1.2:

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

Error: 'onRender' is not an exported object from 'namespace:htmlwidgets'

SessionInfo()

sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
 [4] LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] mapview_1.2.6  leaflet_1.0.1  scales_0.4.0   dplyr_0.5.0    plyr_1.8.4     rgdal_1.1-10  
 [7] reshape2_1.4.1 ggplot2_2.1.0  raster_2.5-8   sp_1.2-3      

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7         git2r_0.14.0        RColorBrewer_1.1-2  R.methodsS3_1.7.1   R.utils_2.4.0      
 [6] iterators_1.0.8     tools_3.2.3         gdalUtils_2.0.1.7   digest_0.6.10       memoise_1.0.0      
[11] satellite_0.2.0     tibble_1.1          gtable_0.1.2        lattice_0.20-33     viridisLite_0.1.3  
[16] png_0.1-7           foreach_1.4.3       DBI_0.5             curl_1.2            httr_1.2.1         
[21] withr_1.0.1         stringr_1.0.0       htmlwidgets_0.7     devtools_1.11.0     stats4_3.2.3       
[26] grid_3.2.3          webshot_0.3.2       R6_2.1.2            latticeExtra_0.6-28 magrittr_1.5       
[31] codetools_0.2-14    htmltools_0.3.5     assertthat_0.1      colorspace_1.2-7    labeling_0.3       
[36] stringi_1.1.1       munsell_0.4.3       R.oo_1.20.0 

Red circles in latticeView sync mode

I almost got latticeView working in tmap. It really works like charm, thanks!

One small thing: in sync mode, the red "cursor" circles are not only visible when the cursor hovers over another facet (as it is supposed to be), but also when the cursor is outside the facets, or when the cursor hovers over the same facet as the red circle. These red "idle" circles are placed in the center of the map.

This problem only seem to appear with leaflet objects, not with mapview objects, at least in this example:

l1 <- leaflet() %>% addProviderTiles("CartoDB.Positron")
l2 <- leaflet() %>% addProviderTiles("OpenStreetMap")
sync(l1, l2)

image

m1 <- mapview()
m2 <- mapview()
sync(m1, m2)

image

Removing zoom to option

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

canvas rendering fails with L.CRS.Simple

When rendering large date sets mapview internally uses addLargeFeatures which is a special JS binding function that switches between canvas and svg rendering depending on the number of features present in the current view. This works fine when using Leaflet's standard projection (set native.crs = FALSE below to verify). However, when using L.CRS.Simple via native.crs = TRUE features are not rendered on the canvas. They are, however rendered when the function switches to svg rendering. The code below highlights this. he initial view is set so that all features are fit into the view. This means that rendering is done on the canvas and we don't see any features. When we zoom in via the zoom button + (twice works for me) features appear as now there are less features to render and the function switches to svg rendering.

library(ggmap)

data(crime)
crime <- crime[complete.cases(crime), ]

# crime_sf <- crime
# raster::projection(crime_sf) <- NA
crime_sf <- st_as_sf(crime, coords = c("lon", "lat"), crs = 4326)

mapview(crime_sf, native.crs = TRUE)

Any ideas how we can get the canvas rendering working with L.CRS.Simple?
@bhaskarvk @timelyportfolio @gisma

mapview doesn't like multi-Lines in SpatialLinesDataFrame

library(sp)
library(mapview)
l1 = cbind(c(1,2,3),c(3,2,2))
l1a = cbind(l1[,1]+.05,l1[,2]+.05)
l2 = cbind(c(1,2,3),c(1,1.5,1))
Sl1 = Line(l1)
Sl1a = Line(l1a)
Sl2 = Line(l2)
S1 = Lines(list(Sl1, Sl1a), ID="a") # Make a multi-Line
S2 = Lines(list(Sl2), ID="b")
Sl = SpatialLines(list(S1,S2))
proj4string(Sl) <- CRS("+init=epsg:4326")
SlDF <- SpatialLinesDataFrame(Sl, data.frame(d = c("a", "b"), row.names = c("a", "b")))
mapview(SlDF)

#> Error in sp::Lines(list(coords), ID) : Single ID required

trouble saving a mapview::sync map?

Tried syncing maps and that works but the resulting object doesn't seem to play nice with anything. I can't export the map or embed in shiny or anything else. Am I missing something?

Thanks!

library(mapview)
library(htmlwidgets)

mapOSM <- leaflet() %>%
  addTiles() %>% 
  setView(lng = -99.84375, lat = 38.82259, zoom = 10)

mapESRI <- leaflet() %>%
  addTiles(
    urlTemplate = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
  ) %>% 
  setView(lng = -99.84375, lat = 38.82259, zoom = 10)

mapSync <- mapview::sync(mapOSM, mapESRI)
class(mapSync)

[1] "shiny.tag.list" "list"

htmlwidgets::saveWidget(mapSync, file = "MapCompare.html")

Error in system.file(config, package = package) :
'package' must be of length 1

r-sig-geo example does not show points

Your example in the announcement on r-sig-geo,

library(ggplot2)
library(rgdal)
library(mapview)

data(diamonds)

### blow diamonds up a bit
big <- diamonds[rep(seq_len(nrow(diamonds)), 40), ]
big$cut <- as.character(big$cut)
big$color <- as.character(big$color)
big$clarity <- as.character(big$clarity)

### provide some random positions
big$x <- rnorm(nrow(big), 0, 10)
big$y <- rnorm(nrow(big), 0, 10)
coordinates(big) <- ~x+y
proj4string(big) <- CRS("+init=epsg:4326")

### view it
mapview(big)

does not show any points on the map opened. Chrome Version 47.0.2526.106 (64-bit)

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
 [3] LC_TIME=en_GB.UTF-8           LC_COLLATE=en_US.UTF-8       
 [5] LC_MONETARY=en_GB.UTF-8       LC_MESSAGES=en_US.UTF-8      
 [7] LC_PAPER=en_GB.UTF-8          LC_NAME=en_GB.UTF-8          
 [9] LC_ADDRESS=en_GB.UTF-8        LC_TELEPHONE=en_GB.UTF-8     
[11] LC_MEASUREMENT=en_GB.UTF-8    LC_IDENTIFICATION=en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mapview_1.0.0 leaflet_1.0.0 rgdal_1.1-1   sp_1.2-2      ggplot2_1.0.1

loaded via a namespace (and not attached):
 [1] OpenStreetMap_0.3.1 Rcpp_0.12.2         RColorBrewer_1.1-2 
 [4] plyr_1.8.3          R.methodsS3_1.7.0   R.utils_2.1.0      
 [7] iterators_1.0.8     tools_3.2.3         gdalUtils_2.0.1.7  
[10] rasterVis_0.37      digest_0.6.8        jsonlite_0.9.17    
[13] satellite_0.2.0     gtable_0.1.2        lattice_0.20-33    
[16] png_0.1-7           foreach_1.4.3       yaml_2.1.13        
[19] parallel_3.2.3      hexbin_1.27.1       proto_0.3-10       
[22] rJava_0.9-7         stringr_1.0.0       raster_2.4-30      
[25] htmlwidgets_0.5     stats4_3.2.3        grid_3.2.3         
[28] latticeExtra_0.6-26 reshape2_1.4.1      magrittr_1.5       
[31] scales_0.3.0        codetools_0.2-14    htmltools_0.2.6    
[34] MASS_7.3-44         colorspace_1.2-6    stringi_1.0-1      
[37] munsell_0.4.2       zoo_1.7-12          R.oo_1.19.0        

feature request: general 3D plots

Hi, this is two-fold, one a heads-up about the "quadmesh" capability for WebGL via rgl and techniques in R that can generate its data structures from "spatial stuff", and two a request for more general 3D plotting for grids.

Many rgl plots for raster are limited to regular grids, but if we use the features more directly there's no need for the mesh to be regular, but it does need to be a densified mesh of vertices.

EDIT: updated to actually work, and use package on CRAN MDS

Here is an example, using 'quadmesh':

## install.packages('quadmesh")

library(quadmesh)
library(raster)
r <- setExtent(raster(volcano), c(0, nrow(volcano), 0, ncol(volcano)) * 2)
qm <- quadmesh(r, z = r)

library(rgl)
scl <- function(x) (x - min(x)) / diff(range(x))
nc <- 50
shade3d(qm, col = terrain.colors(nc)[(scl(qm$vb[3,]) * (nc - 1) + 1)][qm$ib])

In combination with the features of cubeView this would be incredibly powerful.

I'm hoping to learn more about how to do this as well!

mapview::spplot() does not select type of map

With the cran version mapview_1.0.0, I have problems to select the type of map using mapview::spplot(): I always get the OSM one no matter which one I state. I've tried both
nica <- getData("GADM", country="NIC", level=0)
spplot(mapView(nica["ISO"]),colorkey=FALSE,
map.type="Thunderforest.Landscape")
and
spplot(mapView(nica["ISO"],map.types="Thunderforest.Landscape"),
colorkey=FALSE)

despite the fact that just mapView() selects the correct map:
mapView(nica,map.types="Thunderforest.Landscape" )

leaflet dependency

Great work. With the CRAN release, I keep seeing Warning in leafletPolygonsDF(x, map = map, map.types = map.types, zcol = zcol, : Feature labels on mouseover are not supported in the installed version of 'leaflet'. Run devtools::install_github('rstudio/leaflet') to fix this issue., also after installing that leaflet version.

See https://edzer.github.io/sp/#interactive-maps-leaflet-mapview

two bugs

1.legend=FALSE not works when the parameter alpha is used for SpatialPixelsDataFrame.
2.LayersControl was missing when saved by mapshot for html while it is normal in RStudio.

Feature request: map from data.frame

I often have spatial point data in data.frames read from CSV files. Can mapView() be extended to support a data frame with columns lat/latitude and lon/long/longitude or direct specification of lat/lon similar to e.g. leaflet::addCircles?

Option to plot a single legend for a stacked raster plot

Consider this plot:

mapview(stack(poppendorf[[1]], poppendorf[[1]]+0.01), legend=TRUE)

It's easy to see that the legend is duplicated for no reason. This is ugly and wastes space for those plots where the same data could share a legend (say, e.g., a stack of rasters with mean precipitation for different years). A simple solutions could be this something like:

mapview(poppendorf[[1]], legend=TRUE) + mapview(poppendorf[[1]]+0.01)

But this does not work either: the colors are of course different because the input data is different.

How can have mapview share layer legends with a single call?
Or how can I overlay correctly different mapview items while inheriting the same legend?

request

Dear @tim-salabim
Would be nice to add the option to plot a grid of coordinates in the map as well as a (graphical) interactive control of transparency of the layers.

Excellent tool!
Cheers,
Marcos

Adding mapview layers to leaflet maps and vice versa

From this old blog post I read about:

enhanced leaflet integration so that you can use leaflet maps and add features using mapview (e.g. +) or use mapview to create maps and add functionality provided by leaflet (using e.g. %>%)

Yet I'm unable to join leaflet and mapview layers by this method. Can someone please provide an example of how to do this?

mapview() didn't work with dev package version

Hi,

I was using mapview with the CRAN package (mapview_1.2.0) to render map with large spatial line dataframe.

I wanted to use this package in shiny and see in the issues that i have to switch to the dev package from the gith.

First of all using renderMapview and mapviewOutput doesnt show anything in my shinyApp.
Here is the code i used :

#UI side
mapviewOutput("mapBM",width = "100%",height = 600)

#server side
map <- mapview(mydata) #mydata is the spatialLineDataframe
output$mapBM <- renderMapview({map})

then when i tried to show the map in Rstudio with the function mapview(mydata) like with the CRAN package version but the function is running in loop showing neither result nor error.

layer control shows default basemaps only

When creating maps with the following commands, the layercontrol shows incorrect basemaps for map1. The second variant map2 shows the correct basemaps though.
I tested this only with rasterbricks, but all datatypes might be affected.

require(mapview)
require(raster)
tif <- brick('fig-1C.tif')

map1 <- mapview(map.types = c('OpenStreetMap', 'OpenTopoMap', 'Stamen.Toner'))
map1 <- map1 + tif

map2 <- mapview(tif, map.types = c('OpenStreetMap', 'OpenTopoMap', 'Stamen.Toner'))

adding legend for slideView()

Dear benefactors at mavpiew,

Love your package. The slideView function is an amazing tool to compare spatially distbruted rasters, but often it can be usefull to have a legend.
So I wanted to ask if its possible to add a legend to the slideView function.
Like your example, but with a legend.

library(mapview)
library(raster)

stck1 <- subset(poppendorf, c(1, 1, 1))
stck2 <- subset(poppendorf, c(3, 3, 3))
slideView(stck1, stck2)

"not compatible with STRSXP" error

Sometimes I get a not compatible with STRSXP error.

Here is a reproducible example:
(polys$zones is a valid geometry, according to rgeos::gIsValid())

library(tmap)
library(mapview)
bb <- bb(xlim = c(5.421038, 5.43807), ylim = c(43.321667, 43.33905))
polys <- read_osm(bb, zones = osm_poly("landuse=residential"))
plot(polys$zones)

mapview(polys$zones)
#> Error: not compatible with STRSXP

sessionInfo()
#> R version 3.3.0 (2016-05-03)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 14.04.4 LTS
#> 
#> locale:
#>  [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8    
#>  [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8   
#>  [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] sp_1.2-3           mapview_1.0.40     leaflet_1.0.1.9003
#> [4] tmap_1.4-1         reprex_0.0.0.9001 
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtools_3.5.0        splines_3.3.0       lattice_0.20-33    
#>  [4] colorspace_1.2-6    viridisLite_0.1.3   htmltools_0.3.5    
#>  [7] stats4_3.3.0        XML_3.98-1.4        R.oo_1.20.0        
#> [10] e1071_1.6-7         R.utils_2.3.0       RColorBrewer_1.1-2 
#> [13] foreach_1.4.3       plyr_1.8.4          stringr_1.0.0      
#> [16] rgeos_0.3-19        munsell_0.4.3       raster_2.5-8       
#> [19] osmar_1.1-7         R.methodsS3_1.7.1   htmlwidgets_0.6    
#> [22] codetools_0.2-14    coda_0.18-1         evaluate_0.9       
#> [25] latticeExtra_0.6-28 knitr_1.13          class_7.3-14       
#> [28] gdalUtils_2.0.1.7   spdep_0.6-4         Rcpp_0.12.5        
#> [31] KernSmooth_2.23-15  geosphere_1.5-1     clipr_0.2.0        
#> [34] scales_0.4.0        classInt_0.1-23     satellite_0.2.0    
#> [37] formatR_1.4         gdata_2.17.0        webshot_0.3        
#> [40] deldir_0.1-12       png_0.1-7           digest_0.6.9       
#> [43] stringi_1.1.1       gmodels_2.16.2      grid_3.3.0         
#> [46] rgdal_1.1-10        tools_3.3.0         bitops_1.0-6       
#> [49] LearnBayes_2.15     magrittr_1.5        RCurl_1.95-4.8     
#> [52] MASS_7.3-44         Matrix_1.2-6        rmarkdown_0.9.6.8  
#> [55] iterators_1.0.8     boot_1.3-17         nlme_3.1-128

add sparklines

From a Twitter conversation, sparklines in tooltips for leaflet sounded like an interesting feature. Here is an ugly prototype of this functionality adapting a method from this StackOverflow. Currently, it uses the htmlwidget sparkline for convenience to add the dependency, but this dependency is unnecessary.

library(leaflet)
library(sparkline)
library(htmltools)

rand_lng = function(n = 10) rnorm(n, -93.65, .01)
rand_lat = function(n = 10) rnorm(n, 42.0285, .01)
# make random data for a tooltip
popups = unlist(lapply(
  1:10,
  function(i){
    sprintf(
      '<div><span class="sparkline-tooltip">%s</span></div>',
      paste0(runif(20,0,100),collapse=",")
    )
  }
))

lf<-leaflet() %>%
  addMarkers(
    rand_lng(),
    rand_lat(),
    popup=popups
  )

lf$dependencies <- c(
  lf$dependencies,
  htmlwidgets:::widget_dependencies("sparkline","sparkline")[3]
)

htmlwidgets::onRender(
  lf,
'
function(el,x){
var mutobs = new MutationObserver(
  function(mutations){
    $(mutations.map(function(mutation){
      $(mutation.addedNodes);
    })).find(".sparkline-tooltip").sparkline("html",{type:"bar"})
  }
)
//http://stackoverflow.com/questions/37739789/q-k-rohdes-shiny-leaflet-popup-how-to-ensure-popups-are-properly-displayed-r/37771765#37771765
$(".leaflet-popup-pane").each(function() {
  mutobs.observe(this, {childList: true});
})
}
'
)

image

SpatialPolygons without layers control

If a SpatialPolygons object has too little features, the layer controls do not get rendered properly.

This works as expected:
tst <- as(gadmCHE, "SpatialPolygons")[1:20]
mapview(tst)

This doesn't:
tst <- as(gadmCHE, "SpatialPolygons")[1:15]
mapview(tst)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.