Skip to content

Commit 8eb9daa

Browse files
committed
Upgraded minimap to 3.3.1 and added ability to add custom basemap for the minimap.
1 parent 2f6cbec commit 8eb9daa

File tree

8 files changed

+554
-39
lines changed

8 files changed

+554
-39
lines changed

R/plugin-minimap.R

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ leafletMiniMapDependencies <- function() {
22
list(
33
htmltools::htmlDependency(
44
"leaflet-minimap",
5-
"0.1.0",
5+
"3.3.1",
66
system.file("htmlwidgets/plugins/Leaflet-MiniMap", package = "leaflet"),
77
script = c('Control.MiniMap.min.js', 'Minimap-binding.js'),
88
stylesheet = c('Control.MiniMap.min.css')
@@ -14,25 +14,44 @@ leafletMiniMapDependencies <- function() {
1414
#' \url{https://github.com/Norkart/Leaflet-MiniMap}
1515
#'
1616
#' @param map a map widget object
17-
#' @param position The standard Leaflet.Control position parameter, used like all the other controls.
17+
#' @param tiles URL for tiles or one of the \code{\link{providers}}
18+
#' @param position The standard Leaflet.Control position parameter,
19+
#' used like all the other controls.
1820
#' Defaults to 'bottomright'.
1921
#' @param width The width of the minimap in pixels. Defaults to 150.
2022
#' @param height The height of the minimap in pixels. Defaults to 150.
21-
#' @param collapsedWidth The width of the toggle marker and the minimap when collapsed, in pixels.
22-
#' Defaults to 19.
23-
#' @param collapsedHeight The height of the toggle marker and the minimap when collapsed, in pixels.
24-
#' Defaults to 19.
25-
#' @param zoomLevelOffset The offset applied to the zoom in the minimap compared to the zoom of the main map.
26-
#' Can be positive or negative, defaults to -5.
27-
#' @param zoomLevelFixed Overrides the offset to apply a fixed zoom level to the minimap regardless of the main map zoom.
28-
#' Set it to any valid zoom level, if unset zoomLevelOffset is used instead.
23+
#' @param collapsedWidth The width of the toggle marker and the minimap
24+
#' when collapsed, in pixels. Defaults to 19.
25+
#' @param collapsedHeight The height of the toggle marker and the minimap
26+
#' when collapsed, in pixels. Defaults to 19.
27+
#' @param zoomLevelOffset The offset applied to the zoom in the minimap compared
28+
#' to the zoom of the main map. Can be positive or negative, defaults to -5.
29+
#' @param zoomLevelFixed Overrides the offset to apply a fixed zoom level to
30+
#' the minimap regardless of the main map zoom.
31+
#' Set it to any valid zoom level, if unset zoomLevelOffset is used instead.
32+
#' @param centerFixed: Applies a fixed position to the minimap regardless of
33+
#' the main map's view / position. Prevents panning the minimap, but does
34+
#' allow zooming (both in the minimap and the main map).
35+
#' If the minimap is zoomed, it will always zoom around the centerFixed point.
36+
#' You can pass in a LatLng-equivalent object. Defaults to false.
2937
#' @param zoomAnimation Sets whether the minimap should have an animated zoom.
30-
#' (Will cause it to lag a bit after the movement of the main map.) Defaults to false.
38+
#' (Will cause it to lag a bit after the movement of the main map.)
39+
#' Defaults to false.
3140
#' @param toggleDisplay Sets whether the minimap should have a button to minimise it.
32-
#' Defaults to false.
41+
#' Defaults to false.
3342
#' @param autoToggleDisplay Sets whether the minimap should hide automatically,
34-
#' if the parent map bounds does not fit within the minimap bounds.
35-
#' Especially useful when 'zoomLevelFixed' is set.
43+
#' if the parent map bounds does not fit within the minimap bounds.
44+
#' Especially useful when 'zoomLevelFixed' is set.
45+
#' @param minimized Sets whether the minimap should start in a minimized position.
46+
#' @param aimingRectOptions Sets the style of the aiming rectangle by passing in
47+
#' a Path.Options (\url{http://leafletjs.com/reference.html#path-options}) object.
48+
#' (Clickable will always be overridden and set to false.)
49+
#' @param shadowRectOptions Sets the style of the aiming shadow rectangle by passing in
50+
#' a Path.Options (\url{http://leafletjs.com/reference.html#path-options}) object.
51+
#' (Clickable will always be overridden and set to false.)
52+
#' @param strings Overrides the default strings allowing for translation.
53+
#' @param mapOptions Sets Leaflet options for the MiniMap map.
54+
#' It does not override the MiniMap default map options but extends them.
3655
#' @examples
3756
#' library(leaflet)
3857
#'
@@ -43,31 +62,60 @@ leafletMiniMapDependencies <- function() {
4362
#' @export
4463
addMiniMap <- function(
4564
map,
65+
tiles = NULL,
4666
position = 'bottomright',
4767
width = 150,
4868
height = 150,
4969
collapsedWidth = 19,
5070
collapsedHeight = 19,
5171
zoomLevelOffset = -5,
52-
zoomLevelFixed = NULL,
72+
zoomLevelFixed = FALSE,
73+
centerFixed = FALSE,
5374
zoomAnimation = FALSE,
5475
toggleDisplay = FALSE,
55-
autoToggleDisplay = NULL
76+
autoToggleDisplay = FALSE,
77+
minimized = FALSE,
78+
aimingRectOptions = list(color= '#ff7800', weight= 1, clickable= FALSE),
79+
shadowRectOptions = list(color= '#000000', weight= 1, clickable= FALSE,
80+
opacity= 0, fillOpacity= 0),
81+
strings = list(hideText= 'Hide MiniMap', showText= 'Show MiniMap'),
82+
mapOptions = list()
5683
) {
84+
85+
# determin tiles to use
86+
tilesURL <- NULL
87+
tilesProvider <- NULL
88+
if(!is.null(tiles)) {
89+
if(tiles %in% providers) {
90+
map$dependencies <- c(map$dependencies, leafletProviderDependencies())
91+
tilesProvider <- tiles
92+
} else {
93+
tilesURL <- tiles
94+
}
95+
}
96+
5797
map$dependencies <- c(map$dependencies, leafletMiniMapDependencies())
5898
invokeMethod(
5999
map
60100
, getMapData(map)
61101
, 'addMiniMap'
102+
, tilesURL
103+
, tilesProvider
62104
, position
63105
, width
64106
, height
65107
, collapsedWidth
66108
, collapsedHeight
67109
, zoomLevelOffset
68110
, zoomLevelFixed
111+
, centerFixed
69112
, zoomAnimation
70113
, toggleDisplay
71114
, autoToggleDisplay
115+
, minimized
116+
, aimingRectOptions
117+
, shadowRectOptions
118+
, strings
119+
, mapOptions
72120
)
73121
}

inst/examples/minimap.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
library(leaflet)
2-
# Default
3-
leaflet() %>% addTiles() %>% addMiniMap()
42

5-
# Custom Options
6-
leaflet() %>% addTiles() %>% addMiniMap(toggleDisplay = T)
3+
l <- leaflet() %>% setView(0,0,1)
4+
5+
#' Default Minimap
6+
l %>% addTiles() %>% addMiniMap()
7+
8+
#' <br/>
9+
#' Different basemap for the minimap and togglable
10+
l %>% addProviderTiles(providers$Esri.WorldStreetMap) %>%
11+
addMiniMap(
12+
tiles = providers$Esri.WorldStreetMap,
13+
toggleDisplay = T)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
.leaflet-control-minimap {
2+
border:solid rgba(255, 255, 255, 1.0) 4px;
3+
box-shadow: 0 1px 5px rgba(0,0,0,0.65);
4+
border-radius: 3px;
5+
background: #f8f8f9;
6+
transition: all .6s;
7+
}
8+
9+
.leaflet-control-minimap a {
10+
background-color: rgba(255, 255, 255, 1.0);
11+
background-repeat: no-repeat;
12+
z-index: 99999;
13+
transition: all .6s;
14+
}
15+
16+
.leaflet-control-minimap a.minimized-bottomright {
17+
-webkit-transform: rotate(180deg);
18+
transform: rotate(180deg);
19+
border-radius: 0px;
20+
}
21+
22+
.leaflet-control-minimap a.minimized-topleft {
23+
-webkit-transform: rotate(0deg);
24+
transform: rotate(0deg);
25+
border-radius: 0px;
26+
}
27+
28+
.leaflet-control-minimap a.minimized-bottomleft {
29+
-webkit-transform: rotate(270deg);
30+
transform: rotate(270deg);
31+
border-radius: 0px;
32+
}
33+
34+
.leaflet-control-minimap a.minimized-topright {
35+
-webkit-transform: rotate(90deg);
36+
transform: rotate(90deg);
37+
border-radius: 0px;
38+
}
39+
40+
.leaflet-control-minimap-toggle-display{
41+
background-image: url("images/toggle.svg");
42+
background-size: cover;
43+
position: absolute;
44+
border-radius: 3px 0px 0px 0px;
45+
}
46+
47+
.leaflet-oldie .leaflet-control-minimap-toggle-display{
48+
background-image: url("images/toggle.png");
49+
}
50+
51+
.leaflet-control-minimap-toggle-display-bottomright {
52+
bottom: 0;
53+
right: 0;
54+
}
55+
56+
.leaflet-control-minimap-toggle-display-topleft{
57+
top: 0;
58+
left: 0;
59+
-webkit-transform: rotate(180deg);
60+
transform: rotate(180deg);
61+
}
62+
63+
.leaflet-control-minimap-toggle-display-bottomleft{
64+
bottom: 0;
65+
left: 0;
66+
-webkit-transform: rotate(90deg);
67+
transform: rotate(90deg);
68+
}
69+
70+
.leaflet-control-minimap-toggle-display-topright{
71+
top: 0;
72+
right: 0;
73+
-webkit-transform: rotate(270deg);
74+
transform: rotate(270deg);
75+
}
76+
77+
/* Old IE */
78+
.leaflet-oldie .leaflet-control-minimap {
79+
border: 1px solid #999;
80+
}
81+
82+
.leaflet-oldie .leaflet-control-minimap a {
83+
background-color: #fff;
84+
}
85+
86+
.leaflet-oldie .leaflet-control-minimap a.minimized {
87+
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2);
88+
}

0 commit comments

Comments
 (0)