Skip to content

Commit 3536d45

Browse files
committed
- Initial Support for Proj4Leaflet
1 parent 01844b1 commit 3536d45

File tree

11 files changed

+863
-474
lines changed

11 files changed

+863
-474
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export(addMiniMap)
2525
export(addPolygons)
2626
export(addPolylines)
2727
export(addPopups)
28-
export(addProj4Leaflet)
2928
export(addProviderTiles)
3029
export(addRasterImage)
3130
export(addRectangles)

R/leaflet.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@
1919
#' @param width the width of the map
2020
#' @param height the height of the map
2121
#' @param padding the padding of the map
22+
#' @param mapOptions the map options
2223
#' @return A HTML widget object, on which we can add graphics layers using
2324
#' \code{\%>\%} (see examples).
2425
#' @example inst/examples/leaflet.R
2526
#' @export
26-
leaflet = function(data = NULL, width = NULL, height = NULL, padding = 0) {
27+
leaflet = function(data = NULL, width = NULL, height = NULL,
28+
padding = 0, mapOptions = list()) {
2729
htmlwidgets::createWidget(
2830
'leaflet',
2931
structure(
30-
list(),
32+
list(options = mapOptions),
3133
leafletData = data
3234
),
3335
width = width, height = height,
@@ -44,6 +46,10 @@ getMapData = function(map) {
4446
attr(map$x, "leafletData", exact = TRUE)
4547
}
4648

49+
getMapOptions = function(map) {
50+
attr(map$x, "options", exact = TRUE)
51+
}
52+
4753
#' Set options on a leaflet map object
4854
#'
4955
#' @param map A map widget object created from \code{\link{leaflet}()}

R/plugin-Proj4Leaflet.R

Lines changed: 0 additions & 19 deletions
This file was deleted.

inst/examples/minimap.R

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ m %>%
3232
addMiniMap(
3333
tiles = esri[[1]],
3434
toggleDisplay = T) %>%
35-
htmlwidgets::onRender("function(el, x) {
36-
var myMap = this;
37-
this.on('baselayerchange',
38-
function (e) {
39-
myMap.minimap.changeLayer(L.tileLayer.provider(e.name));
40-
})
41-
}")
35+
htmlwidgets::onRender("
36+
function(el, x) {
37+
var myMap = this.getMap();
38+
myMap.on('baselayerchange',
39+
function (e) {
40+
myMap.minimap.changeLayer(L.tileLayer.provider(e.name));
41+
})
42+
}")
4243

4344
#' <br/><br/>
4445
#' Another advanced use case
@@ -69,33 +70,27 @@ leaflet() %>% addTiles() %>%
6970
options = markerOptions(riseOnHover = TRUE, opacity = 0.75),
7071
group = 'pubs') %>%
7172
addMiniMap() %>%
72-
htmlwidgets::onRender("function(el, t) {
73-
var myMap = this;
73+
htmlwidgets::onRender("
74+
function(el, t) {
75+
var myMap = this.getMap();
7476
75-
var pubs = myMap.layerManager._byGroup.pubs;
76-
var pubs2 = new L.FeatureGroup();
77+
var pubs = myMap.layerManager._byGroup.pubs;
78+
var pubs2 = new L.FeatureGroup();
7779
78-
for(pub in pubs) {
79-
var m = new L.CircleMarker(pubs[pub]._latlng,
80-
{radius: 2});
81-
pubs2.addLayer(m);
82-
83-
}
84-
var layers = new L.LayerGroup([myMap.minimap._layer, pubs2]);
85-
86-
myMap.minimap.changeLayer(layers);
87-
}")
80+
for(pub in pubs) {
81+
var m = new L.CircleMarker(pubs[pub]._latlng, {radius: 2});
82+
pubs2.addLayer(m);
83+
}
84+
var layers = new L.LayerGroup([myMap.minimap._layer, pubs2]);
85+
myMap.minimap.changeLayer(layers);
86+
}")
8887

8988
#' <br/><br/>
9089
#' Finally combine the approaches in last 2 examples
9190
#' Minimap w/ changable layers and circle markers.
9291
m <- leaflet()
93-
esri <- providers %>%
94-
purrr::keep(~ grepl('^Esri',.))
95-
9692
esri %>%
9793
purrr::walk(function(x) m <<- m %>% addProviderTiles(x,group=x))
98-
9994
m %>%
10095
setView(10.758276373601069, 59.92448055859924, 13) %>%
10196
addAwesomeMarkers(data=spdf,
@@ -109,27 +104,24 @@ m %>%
109104
) %>%
110105
addMiniMap(tiles = esri[[1]],
111106
toggleDisplay = T) %>%
112-
htmlwidgets::onRender("function(el, t) {
113-
var myMap = this;
114-
115-
var pubs = myMap.layerManager._byGroup.pubs;
116-
var pubs2 = new L.FeatureGroup();
117-
118-
for(pub in pubs) {
119-
var m = new L.CircleMarker(pubs[pub]._latlng,
120-
{radius: 2});
121-
pubs2.addLayer(m);
122-
123-
}
124-
var layers = new L.LayerGroup([myMap.minimap._layer, pubs2]);
125-
126-
myMap.minimap.changeLayer(layers);
127-
128-
myMap.on('baselayerchange',
129-
function (e) {
130-
debugger;
131-
myMap.minimap.changeLayer(
132-
new L.LayerGroup([L.tileLayer.provider(e.name),
133-
pubs2]));
134-
});
135-
}")
107+
htmlwidgets::onRender("
108+
function(el, t) {
109+
var myMap = this.getMap();
110+
111+
var pubs = myMap.layerManager._byGroup.pubs;
112+
var pubs2 = new L.FeatureGroup();
113+
114+
for(pub in pubs) {
115+
var m = new L.CircleMarker(pubs[pub]._latlng, {radius: 2});
116+
pubs2.addLayer(m);
117+
}
118+
var layers = new L.LayerGroup([myMap.minimap._layer, pubs2]);
119+
120+
myMap.minimap.changeLayer(layers);
121+
122+
myMap.on('baselayerchange',
123+
function (e) {
124+
myMap.minimap.changeLayer(
125+
new L.LayerGroup([L.tileLayer.provider(e.name), pubs2]));
126+
});
127+
}")

0 commit comments

Comments
 (0)