Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
1483 lines (1352 loc) · 56.7 KB

File metadata and controls

1483 lines (1352 loc) · 56.7 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if ( !isGeneric('mapView') ) {
setGeneric('mapView', function(x, ...)
standardGeneric('mapView'))
}
#' View spatial objects interactively
#'
#' @description
#' this function produces an interactive view of the specified
#' spatial object(s) on top of the specified base maps.
#'
#' @details
#' If \code{zcol} is not \code{NULL} but a length one character vector
#' (referring to a column name of the attribute table)
#' and \code{burst} is \code{TRUE}, one layer for each unique value
#' of \code{zcol} will be drawn. The same will happen if \code{burst} is
#' a length one character vector (again referring to a column of
#' the attribute table). \cr
#' \cr
#' NOTE: if XYZ or XYM or XYZM data from package sf is passed to mapview,
#' dimensions Z and M will be stripped to ensure smooth rendering even though
#' the popup will potentially still say something like "POLYGON Z".
#'
#' @param x a \code{Raster*} or \code{Spatial*} or \code{Satellite} or
#' \code{sf} object or a list of any combination of those. Furthermore,
#' this can also be a \code{data.frame}, a \code{numeric vector} or a
#' \code{character string} pointing to a tile image folder or file on disk.
#' If missing, a blank map will be drawn.
#' @param map an optional existing map to be updated/added to.
#' @param band for stars layers, the band number to be plotted.
#' @param pane name of the map pane in which to render features. See
#' \code{\link{addMapPane}} for details. Currently only supported for vector layers.
#' Ignored if \code{canvas = TRUE}. The default \code{"auto"} will create different panes
#' for points, lines and polygons such that points overlay lines overlay polygons.
#' Set to \code{NULL} to get default leaflet behaviour where allfeatures
#' are rendered in the same pane and layer order is determined automatically/sequentially.
#' @param canvas whether to use canvas rendering rather than svg. May help
#' performance with larger data. See \url{http://leafletjs.com/reference-1.3.0.html#canvas}
#' for more information. Only applicable for vector data. The default setting will
#' decide automatically, based on feature complexity.
#' @param viewer.suppress whether to render the map in the browser (\code{TRUE})
#' or the RStudio viewer (\code{FALSE}). When not using RStudio, maps will open
#' in the browser by default. This is passed to \link[htmlwidgets]{sizingPolicy}
#' via \link[leaflet]{leafletSizingPolicy}. For raster data the default is \code{FALSE}.
#' For vector data it depends on argument \code{canvas}.
#' @param maxpixels integer > 0. Maximum number of cells to use for the plot.
#' If maxpixels < \code{ncell(x)}, sampleRegular is used before plotting.
#' @param color color (palette) for points/polygons/lines
#' @param col.regions color (palette) pixels.
#' See \code{\link{levelplot}} for details.
#' @param at the breakpoints used for the visualisation.
#' See \code{\link{levelplot}} for details.
#' @param na.color color for missing values
#' @param use.layer.names should layer names of the Raster* object be used?
#' @param map.types character spcifications for the base maps.
#' see \url{http://leaflet-extras.github.io/leaflet-providers/preview/}
#' for available options.
#' @param burst whether to show all (TRUE) or only one (FALSE) layer(s).
#' See also Details.
#' @param zcol attribute name(s) or column number(s) in attribute table
#' of the column(s) to be rendered. See also Details.
#' @param cex attribute name(s) or column number(s) in attribute table
#' of the column(s) to be used for defining the size of circles
#' @param lwd line width
#' @param alpha opacity of lines
#' @param alpha.regions opacity of the fills of points, polygons or raster layer(s)
#' @param na.alpha opacity of missing values
#' @param legend should a legend be plotted
#' @param legend.opacity opacity of the legend
#' @param trim should the raster be trimmed in case there are NAs on the edges
#' @param verbose should some details be printed during the process
#' @param layer.name the name of the layer to be shown on the map
#' @param homebutton logical, whether to add a zoom-to-layer button to the map.
#' Defaults to TRUE
#' @param popup a \code{list} of HTML strings with the popup contents, usually
#' created from \code{\link[leafpop]{popupTable}}. See \code{\link{addControl}} for
#' details.
#' @param label For vector data (sf/sp) a character vector of labels to be
#' shown on mouseover. See \code{\link{addControl}} for details. For raster
#' data (Raster*/stars) a logical indicating whether to add image query.
#' @param native.crs logical whether to reproject to web map coordinate
#' reference system (web mercator - epsg:3857) or render using native CRS of
#' the supplied data (can also be NA). Default is FALSE which will render in
#' web mercator. If set to TRUE now background maps will be drawn (but rendering
#' may be much quicker as no reprojecting is necessary). Currently only works
#' for simple features.
#' @param method for raster data only (raster/stars). Method used to compute
#' values for the resampled layer that is passed on to leaflet. mapview does
#' projection on-the-fly to ensure correct display and therefore needs to know
#' how to do this projection. The default is 'bilinear' (bilinear interpolation),
#' which is appropriate for continuous variables. The other option, 'ngb'
#' (nearest neighbor), is useful for categorical variables. Ignored if the raster
#' layer is of class \code{factor} in which case "ngb" is used.
#' @param highlight either \code{FALSE}, \code{NULL} or a list of styling
#' options for feature highlighting on mouse hover.
#' See \code{\link{highlightOptions}} for details.
#' @param maxpoints the maximum number of points making up the geometry.
#' In case of lines and polygons this refers to the number of vertices. See
#' Details for more information.
#' @param query.type for raster methods only. Whether to show raster value query
#' on \code{'mousemove'} or \code{'click'}. Ignored if \code{label = FALSE}.
#' @param query.digits for raster methods only. The amount of digits to be shown
#' by raster value query. Ignored if \code{label = FALSE}.
#' @param query.position for raster methods only. The position of the raster
#' value query info box. See \code{position} argument of \code{\link{addLegend}}
#' for possible values. Ignored if \code{label = FALSE}.
#' @param query.prefix for raster methods only. a character string to be shown
#' as prefix for the layerId. Ignored if \code{label = FALSE}.
#' @param ... additional arguments passed on to respective functions.
#' See \code{\link{addRasterImage}}, \code{\link{addCircles}},
#' \code{\link{addPolygons}}, \code{\link{addPolylines}} for details
#'
#' @details
#' \code{maxpoints} is taken to determine when to switch rendering from svg
#' to canvas overlay for perfomance. The threshold calculation is done as follows: \cr
#' if the number of points (in case of point data) or vertices (in case of
#' polygon or line data) > \code{maxpoints} then render using special render
#' function. Within this render function we approximate the complexity of
#' features by \cr
#' \cr
#' \code{maxFeatures <- maxfeatures / (npts(data) / length(data))} \cr
#' \cr
#' where \code{npts} determines the number of points/vertices and \code{length}
#' the number of features (points, lines or polygons). When the number of
#' features in the current view window is larger than \code{maxFeatures} then
#' features are rendered on the canvas, otherwise they are rendered as svg objects
#' and fully queriable.
#'
#' @author
#' Tim Appelhans
#'
#' @examples
#' \dontrun{
#' mapview()
#'
#' ## simple features ====================================================
#' library(sf)
#'
#' # sf
#' mapview(breweries)
#' mapview(franconia)
#'
#' # sfc
#' mapview(st_geometry(breweries)) # no popup
#'
#' # sfg / XY - taken from ?sf::st_point
#' outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
#' hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
#' hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
#' pts = list(outer, hole1, hole2)
#' (pl1 = st_polygon(pts))
#' mapview(pl1)
#'
#' ## raster ==============================================================
#' if (interactive()) {
#' library(plainview)
#'
#' mapview(plainview::poppendorf[[5]])
#' }
#'
#' ## spatial objects =====================================================
#' mapview(leaflet::gadmCHE)
#' mapview(leaflet::atlStorms2005)
#'
#'
#' ## styling options & legends ===========================================
#' mapview(franconia, color = "white", col.regions = "red")
#' mapview(franconia, color = "magenta", col.regions = "white")
#'
#' mapview(breweries, zcol = "founded")
#' mapview(breweries, zcol = "founded", at = seq(1400, 2200, 200), legend = TRUE)
#' mapview(franconia, zcol = "district", legend = TRUE)
#'
#' clrs <- sf.colors
#' mapview(franconia, zcol = "district", col.regions = clrs, legend = TRUE)
#'
#' ### multiple layers ====================================================
#' mapview(franconia) + breweries
#' mapview(list(breweries, franconia))
#' mapview(franconia) + mapview(breweries) + trails
#'
#' mapview(franconia, zcol = "district") + mapview(breweries, zcol = "village")
#' mapview(list(franconia, breweries),
#' zcol = list("district", NULL),
#' legend = list(TRUE, FALSE))
#'
#'
#' ### burst ==============================================================
#' mapview(franconia, burst = TRUE)
#' mapview(franconia, burst = TRUE, hide = TRUE)
#' mapview(franconia, zcol = "district", burst = TRUE)
#'
#'
#' ### ceci constitue la fin du pipe ======================================
#' library(dplyr)
#' library(sf)
#'
#' franconia %>%
#' sf::st_union() %>%
#' mapview()
#'
#' franconia %>%
#' group_by(district) %>%
#' summarize() %>%
#' mapview(zcol = "district")
#'
#' franconia %>%
#' group_by(district) %>%
#' summarize() %>%
#' mutate(area = st_area(.) / 1e6) %>%
#' mapview(zcol = "area")
#'
#' franconia %>%
#' mutate(area = sf::st_area(.)) %>%
#' mapview(zcol = "area", legend = TRUE)
#'
#' breweries %>%
#' st_intersection(franconia) %>%
#' mapview(zcol = "district")
#'
#' franconia %>%
#' mutate(count = lengths(st_contains(., breweries))) %>%
#' mapview(zcol = "count")
#'
#' franconia %>%
#' mutate(count = lengths(st_contains(., breweries)),
#' density = count / st_area(.)) %>%
#' mapview(zcol = "density")
#' }
#'
#' @export
#' @docType methods
#' @name mapView
#' @rdname mapView
#' @aliases mapView,RasterLayer-method
######## RASTER ###########################################################
## RasterLayer ============================================================
setMethod('mapView', signature(x = 'RasterLayer'),
function(x,
map = NULL,
maxpixels = mapviewGetOption("mapview.maxpixels"),
col.regions = mapviewGetOption("raster.palette")(256),
at = NULL,
na.color = mapviewGetOption("na.color"),
use.layer.names = mapviewGetOption("use.layer.names"),
map.types = mapviewGetOption("basemaps"),
alpha.regions = 0.8,
legend = mapviewGetOption("legend"),
legend.opacity = 1,
trim = mapviewGetOption("trim"),
verbose = mapviewGetOption("verbose"),
layer.name = NULL,
homebutton = mapviewGetOption("homebutton"),
native.crs = mapviewGetOption("native.crs"),
method = mapviewGetOption("method"),
label = TRUE,
query.type = mapviewGetOption("query.type"),
query.digits = mapviewGetOption("query.digits"),
query.position = mapviewGetOption("query.position"),
query.prefix = mapviewGetOption("query.prefix"),
viewer.suppress = mapviewGetOption("viewer.suppress"),
...) {
if (is.null(at)) at <- lattice::do.breaks(
extendLimits(range(x[], na.rm = TRUE)), 256)
if (mapviewGetOption("platform") == "leaflet") {
# if (maxpixels < raster::ncell(x)) {
# plainview(x,
# maxpixels = maxpixels,
# col.regions = col.regions,
# at = at,
# na.color = na.color,
# verbose = verbose,
# layer.name = layer.name,
# ...)
# } else {
leafletRL(x,
map = map,
maxpixels = maxpixels,
col.regions = col.regions,
at = at,
na.color = na.color,
use.layer.names = use.layer.names,
map.types = map.types,
alpha.regions = alpha.regions,
legend = legend,
legend.opacity = legend.opacity,
trim = trim,
verbose = verbose,
layer.name = layer.name,
homebutton = homebutton,
native.crs = native.crs,
method = method,
label = label,
query.type = query.type,
query.digits = query.digits,
query.position = query.position,
query.prefix = query.prefix,
viewer.suppress = viewer.suppress,
...)
} else {
NULL
}
}
)
## Stars layer ==================================================================
#' @describeIn mapView \code{\link{stars}}
setMethod('mapView', signature(x = 'stars'),
function(x,
band = 1,
map = NULL,
maxpixels = mapviewGetOption("mapview.maxpixels"),
col.regions = mapviewGetOption("raster.palette")(256),
at = NULL,
na.color = mapviewGetOption("na.color"),
use.layer.names = mapviewGetOption("use.layer.names"),
map.types = mapviewGetOption("basemaps"),
alpha.regions = 0.8,
legend = mapviewGetOption("legend"),
legend.opacity = 1,
trim = mapviewGetOption("trim"),
verbose = mapviewGetOption("verbose"),
layer.name = NULL,
homebutton = mapviewGetOption("homebutton"),
native.crs = mapviewGetOption("native.crs"),
method = mapviewGetOption("method"),
label = TRUE,
query.type = mapviewGetOption("query.type"),
query.digits = mapviewGetOption("query.digits"),
query.position = mapviewGetOption("query.position"),
query.prefix = mapviewGetOption("query.prefix"),
viewer.suppress = mapviewGetOption("viewer.suppress"),
...) {
# method = match.arg(method)
if(length(dim(x)) == 2) layer = x[[1]] else layer = x[[1]][, , band]
if (is.null(at)) at <- lattice::do.breaks(
extendLimits(range(layer, na.rm = TRUE)),
256
)
if (mapviewGetOption("platform") == "leaflet") {
leaflet_stars(x,
band = band,
map = map,
maxpixels = maxpixels,
col.regions = col.regions,
at = at,
na.color = na.color,
use.layer.names = use.layer.names,
map.types = map.types,
alpha.regions = alpha.regions,
legend = legend,
legend.opacity = legend.opacity,
trim = trim,
verbose = verbose,
layer.name = layer.name,
homebutton = homebutton,
native.crs = native.crs,
method = method,
label = label,
query.type = query.type,
query.digits = query.digits,
query.position = query.position,
query.prefix = query.prefix,
viewer.suppress = viewer.suppress,
...)
} else {
NULL
}
}
)
## Raster Stack/Brick ===========================================================
#' @describeIn mapView \code{\link{stack}} / \code{\link{brick}}
setMethod('mapView', signature(x = 'RasterStackBrick'),
function(x,
map = NULL,
maxpixels = mapviewGetOption("mapview.maxpixels"),
col.regions = mapviewGetOption("raster.palette")(256),
at = NULL,
na.color = mapviewGetOption("na.color"),
use.layer.names = TRUE,
map.types = mapviewGetOption("basemaps"),
legend = mapviewGetOption("legend"),
legend.opacity = 1,
trim = TRUE,
verbose = mapviewGetOption("verbose"),
homebutton = TRUE,
method = mapviewGetOption("method"),
label = TRUE,
query.type = c("mousemove", "click"),
query.digits,
query.position = "topright",
query.prefix = "Layer",
viewer.suppress = FALSE,
...) {
if (mapviewGetOption("platform") == "leaflet") {
leafletRSB(x,
map = map,
maxpixels = maxpixels,
col.regions = col.regions,
at = at,
na.color = na.color,
use.layer.names = use.layer.names,
map.types = map.types,
legend = legend,
legend.opacity = legend.opacity,
trim = trim,
verbose = verbose,
homebutton = homebutton,
method = method,
label = label,
query.type = query.type,
query.digits = query.digits,
query.position = query.position,
query.prefix = query.prefix,
viewer.suppress = viewer.suppress,
...)
} else {
NULL
}
}
)
## Satellite object =======================================================
#' @describeIn mapView \code{\link{satellite}}
setMethod('mapView', signature(x = 'Satellite'),
function(x,
map = NULL,
maxpixels = mapviewGetOption("mapview.maxpixels"),
col.regions = mapviewGetOption("raster.palette")(256),
at = NULL,
na.color = mapviewGetOption("na.color"),
map.types = mapviewGetOption("basemaps"),
legend = mapviewGetOption("legend"),
legend.opacity = 1,
trim = TRUE,
verbose = mapviewGetOption("verbose"),
homebutton = TRUE,
method = c("bilinear", "ngb"),
label = TRUE,
...) {
if (mapviewGetOption("platform") == "leaflet") {
leafletSatellite(x,
map = map,
maxpixels = maxpixels,
col.regions = col.regions,
at = at,
na.color = na.color,
map.types = map.types,
legend = legend,
legend.opacity = legend.opacity,
trim = trim,
verbose = verbose,
homebutton = homebutton,
method = method,
label = label,
...)
} else {
NULL
}
}
)
######## SIMPLE FEATURES ##################################################
## sf =====================================================================
#' @describeIn mapView \code{\link{st_sf}}
setMethod('mapView', signature(x = 'sf'),
function(x,
map = NULL,
pane = "auto",
canvas = useCanvas(x),
viewer.suppress = canvas,
zcol = NULL,
burst = FALSE,
color = mapviewGetOption("vector.palette"),
col.regions = mapviewGetOption("vector.palette"),
at = NULL,
na.color = mapviewGetOption("na.color"),
cex = 6,
lwd = lineWidth(x),
alpha = 0.9,
alpha.regions = regionOpacity(x),
na.alpha = regionOpacity(x),
map.types = NULL,
verbose = mapviewGetOption("verbose"),
popup = leafpop::popupTable(x),
layer.name = NULL,
label = makeLabels(x, zcol),
legend = mapviewGetOption("legend"),
legend.opacity = 1,
homebutton = TRUE,
native.crs = FALSE,
highlight = mapviewHighlightOptions(x, alpha.regions, alpha, lwd),
maxpoints = getMaxFeatures(x),
...) {
if (nrow(x) == 0) {
stop("\n", deparse(substitute(x, env = parent.frame())),
" does not contain data \n", call. = FALSE)
}
if (is.null(zcol) & is.null(legend)) legend = FALSE
if (!is.null(zcol) && !all(zcol %in% colnames(x))) {
stop("\n", "at least one of the following columns: \n",
paste(zcol, collapse = ", "), "\nnot found in ",
deparse(substitute(x, env = parent.frame())),
call. = FALSE)
}
if (mapviewGetOption("platform") == "leaflet") {
if (is.character(burst)) {
zcol = burst
burst = TRUE
}
if (length(zcol) > 1) {
x = x[, zcol]
burst = TRUE
}
# if (inherits(sf::st_geometry(x), "sfc_GEOMETRY")) {
# x = split(x, f = sf::st_dimension(sf::st_geometry(x)))
# }
if (burst) {
tmp <- burst(x = x,
zcol = zcol,
burst = burst,
color = color,
col.regions = col.regions,
at = at,
na.color = na.color,
popup = popup,
alpha = alpha,
alpha.regions = alpha.regions,
na.alpha = na.alpha,
legend = legend)
lwd = lwd
if (is.function(tmp)) {
tmp = tmp()
x <- tmp$obj
color <- tmp$color
col.regions <- tmp$col.regions
popup <- tmp$popup
label <- tmp$labs
# alpha = tmp$alpha
# alpha.regions = tmp$alpha.regions
zcol = tmp$zcol #as.list(names(x))
}
}
if (!inherits(x, "list")) {
leaflet_sf(sf::st_cast(x),
map = map,
pane = pane,
zcol = zcol,
color = color,
col.regions = col.regions,
at = at,
na.color = na.color,
cex = cex,
lwd = lwd,
alpha = alpha,
alpha.regions = alpha.regions,
na.alpha = na.alpha,
map.types = map.types,
verbose = verbose,
popup = popup,
layer.name = layer.name,
label = label,
legend = legend,
legend.opacity = legend.opacity,
homebutton = homebutton,
native.crs = native.crs,
highlight = highlight,
maxpoints = maxpoints,
canvas = canvas,
viewer.suppress = viewer.suppress,
...)
} else {
mapView(x,
zcol = zcol,
burst = FALSE,
color = color,
col.regions = col.regions,
popup = popup,
label = label,
homebutton = homebutton,
legend = legend,
map.types = map.types,
layer.name = layer.name,
alpha = alpha,
alpha.regions = alpha.regions,
na.alpha = na.alpha,
canvas = canvas,
viewer.suppress = viewer.suppress,
pane = pane,
cex = cex,
lwd = lwd,
...)
}
} else if (mapviewGetOption("platform") == "mapdeck") {
mapdeck_sf(x,
map = map,
zcol = zcol,
color = color,
col.regions = col.regions,
at = at,
na.color = na.color,
cex = cex,
lwd = lwd,
alpha = alpha,
alpha.regions = alpha.regions,
na.alpha = na.alpha,
map.types = map.types,
verbose = verbose,
popup = popup,
layer.name = layer.name,
label = label,
legend = legend,
legend.opacity = legend.opacity,
homebutton = homebutton,
native.crs = native.crs,
highlight = highlight,
maxpoints = maxpoints,
viewer.suppress = viewer.suppress,
...)
} else {
NULL
}
}
)
## sfc ====================================================================
#' @describeIn mapView \code{\link{st_sfc}}
setMethod('mapView', signature(x = 'sfc'),
function(x,
map = NULL,
pane = "auto",
canvas = useCanvas(x),
viewer.suppress = canvas,
color = standardColor(x), #mapviewGetOption("vector.palette"),
col.regions = standardColRegions(x), #mapviewGetOption("vector.palette"),
at = NULL,
na.color = mapviewGetOption("na.color"),
cex = 6,
lwd = lineWidth(x),
alpha = 0.9,
alpha.regions = regionOpacity(x),
map.types = NULL,
verbose = mapviewGetOption("verbose"),
popup = NULL,
layer.name = deparse(substitute(x,
env = parent.frame())),
label = makeLabels(x),
legend = mapviewGetOption("legend"),
legend.opacity = 1,
homebutton = TRUE,
native.crs = FALSE,
highlight = mapviewHighlightOptions(x, alpha.regions, alpha, lwd),
maxpoints = getMaxFeatures(x),
...) {
if (length(x) == 0) {
stop("\n", deparse(substitute(x, env = parent.frame())),
" does not contain data \n", call. = FALSE)
}
if (mapviewGetOption("platform") == "leaflet") {
leaflet_sfc(sf::st_cast(x),
map = map,
pane = pane,
canvas = canvas,
viewer.suppress = viewer.suppress,
color = color,
col.regions = col.regions,
na.color = na.color,
cex = cex,
lwd = lwd,
alpha = alpha,
alpha.regions = alpha.regions,
map.types = map.types,
verbose = verbose,
popup = popup,
layer.name = layer.name,
label = label,
legend = legend,
legend.opacity = legend.opacity,
homebutton = homebutton,
native.crs = native.crs,
highlight = highlight,
maxpoints = maxpoints,
...)
} else if (mapviewGetOption("platform") == "mapdeck") {
mapdeck_sfc(sf::st_cast(x),
map = map,
pane = pane,
canvas = canvas,
viewer.suppress = viewer.suppress,
color = color,
col.regions = col.regions,
na.color = na.color,
cex = cex,
lwd = lwd,
alpha = alpha,
alpha.regions = alpha.regions,
map.types = map.types,
verbose = verbose,
popup = popup,
layer.name = layer.name,
label = label,
legend = legend,
legend.opacity = legend.opacity,
homebutton = homebutton,
native.crs = native.crs,
highlight = highlight,
maxpoints = maxpoints,
...)
} else {
NULL
}
}
)
## character ==============================================================
#' @param tms whether the tiles are served as TMS tiles.
#'
#' @describeIn mapView \code{\link{character}}
setMethod('mapView', signature(x = 'character'),
function(x,
map = NULL,
tms = TRUE,
color = standardColor(),
col.regions = standardColRegions(),
at = NULL,
na.color = mapviewGetOption("na.color"),
cex = 6,
lwd = 2,
alpha = 0.9,
alpha.regions = 0.6,
na.alpha = 0.6,
map.types = NULL,
verbose = FALSE,
layer.name = x,
homebutton = TRUE,
native.crs = FALSE,
canvas = FALSE,
viewer.suppress = FALSE,
...) {
if (mapviewGetOption("platform") == "leaflet") {
if (utils::file_test("-d", x)) {
leaflet_tiles(x = x,
map = map,
tms = tms,
map.types = map.types,
verbose = verbose,
layer.name = layer.name,
homebutton = homebutton,
native.crs = native.crs,
viewer.suppress = viewer.suppress,
...)
} else if (utils::file_test("-f", x)) {
layer.name = basename(tools::file_path_sans_ext(layer.name))
leaflet_file(x = x,
map = map,
color = color,
col.regions = col.regions,
at = at,
na.color = na.color,
cex = cex,
lwd = lwd,
alpha = alpha,
alpha.regions = alpha.regions,
na.alpha = na.alpha,
map.types = map.types,
verbose = verbose,
layer.name = layer.name,
homebutton = homebutton,
native.crs = native.crs,
canvas = canvas,
viewer.suppress = viewer.suppress,
...)
} else {
stop(sprintf("%s is not a directory!", layer.name),
call. = FALSE)
}
}
}
)
## numeric ================================================================
#' @describeIn mapView \code{\link{numeric}}
#' @param y numeric vector.
#' @param type whether to render the numeric vector \code{x} as a
#' point \code{"p"} or line \code{"l"} plot.
setMethod('mapView', signature(x = 'numeric'),
function(x, y, type = "p", grid = TRUE, label, ...) {
if (missing(label)) {
if (!missing(y)) {
labs = lapply(seq(length(x)), function(i) {
paste0("x : ", x[i], '<br>',
"y : ", y[i])
})
label = lapply(labs, htmltools::HTML)
} else {
labs = lapply(seq(length(x)), function(i) {
paste0("x : ", seq_along(x)[i], '<br>',
"y : ", x[i])
})
label = lapply(labs, htmltools::HTML)
}
}
if (type == "l") label = NULL
xyView(x = x,
y = y,
type = type,
grid = grid,
label = label,
...)
}
)
## data.frame =============================================================
#' @describeIn mapView \code{\link{data.frame}}
#' @param xcol the column to be mapped to the x-axis. Only relevant for the
#' data.frame method.
#' @param ycol the column to be mapped to the y-axis. Only relevant for the
#' data.frame method.
#' @param grid whether to plot a (scatter plot) xy-grid to aid interpretation
#' of the visualisation. Only relevant for the data.frame method.
#' @param aspect the ratio of x/y axis corrdinates to adjust the plotting
#' space to fit the screen. Only relevant for the data.frame method.
#' @param crs an optional crs specification for the provided data to enable
#' rendering on a basemap. See argument description in \code{\link{st_sf}}
#' for details.
setMethod('mapView', signature(x = 'data.frame'),
function(x,
xcol,
ycol,
grid = TRUE,
aspect = 1,
popup = leafpop::popupTable(x),
label,
crs = NA,
...) {
if (missing(xcol) | missing(ycol)) {
obj = deparse(substitute(x, env = parent.frame()))
msg = paste0("\noops! Arguments xcol and/or ycol are missing!\n",
"You probably expected ", obj,
" to be a spatial object. \nHowever it is of class ",
class(x), ". \nEither convert ", obj, " to a spatial object ",
"or provide xcol and ycol.")
stop(msg, call. = FALSE)
}
if (missing(label)) {
labs = lapply(seq(nrow(x)), function(i) {
paste0(xcol, " (x) : ", x[[xcol]][i], '<br>',
ycol, " (y) : ", x[[ycol]][i])
})
label = lapply(labs, htmltools::HTML)
}
xyView(x = xcol,
y = ycol,
data = x,
grid = grid,
aspect = aspect,
popup = popup,
label = label,
crs = crs,
...)
}
)
## XY =====================================================================
#' @describeIn mapView \code{\link{st_sfc}}
setMethod('mapView', signature(x = 'XY'),
function(x,
map = NULL,
pane = "auto",
canvas = useCanvas(x),
viewer.suppress = canvas,
color = standardColor(x), #mapviewGetOption("vector.palette"),
col.regions = standardColRegions(x), #mapviewGetOption("vector.palette"),
at = NULL,
na.color = mapviewGetOption("na.color"),
cex = 6,
lwd = lineWidth(x),
alpha = 0.9,
alpha.regions = regionOpacity(x),
map.types = NULL,
verbose = mapviewGetOption("verbose"),
popup = NULL,
layer.name = deparse(substitute(x,
env = parent.frame(1))),
label = makeLabels(x),
legend = mapviewGetOption("legend"),
legend.opacity = 1,
homebutton = TRUE,
native.crs = FALSE,
highlight = mapviewHighlightOptions(x, alpha.regions, alpha, lwd),
maxpoints = getMaxFeatures(x),
...) {
if (mapviewGetOption("platform") == "leaflet") {
x = sf::st_cast(sf::st_sfc(x))
leaflet_sfc(x,
map = map,
pane = pane,
canvas = canvas,
viewer.suppress = viewer.suppress,
color = color,
col.regions = col.regions,
na.color = na.color,
cex = cex,
lwd = lwd,
alpha = alpha,
alpha.regions = alpha.regions,
map.types = map.types,
verbose = verbose,
popup = popup,
layer.name = layer.name,
label = label,
legend = legend,
legend.opacity = legend.opacity,
homebutton = homebutton,
native.crs = native.crs,
highlight = highlight,
maxpoints = maxpoints,
...)
} else {
NULL
}
}
)
## XYZ ====================================================================
#' @describeIn mapView \code{\link{st_sfc}}
setMethod('mapView', signature(x = 'XYZ'),
function(x,
layer.name = deparse(substitute(x,
env = parent.frame(1))),
...) {
mapview(sf::st_zm(x), layer.name = layer.name, ...)
}
)
## XYM ====================================================================
#' @describeIn mapView \code{\link{st_sfc}}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.