@@ -32,5 +32,104 @@ m %>%
32
32
addMiniMap(
33
33
tiles = esri [[1 ]],
34
34
toggleDisplay = T ) %> %
35
- htmlwidgets :: onRender(" function(el, x) { var myMap = this; this.on('baselayerchange', function (e) { myMap.minimap.changeLayer(L.tileLayer.provider(e.name)); }) }" )
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
+ }" )
36
42
43
+ # ' <br/><br/>
44
+ # ' Another advanced use case
45
+ # ' Minimap with markers.
46
+ # ' Note the use of 'group' ID to find markers in main map and add corresponding CircleMarkers in minimap.
47
+ # ' The V8 part is simply to read the JSON embeded in the Javascript.<br/>
48
+ # ' For a geojson file `jsonlite::fromfromJSON()` or `geojsonio::regeojson_read()` will do
49
+ # '
50
+ jsURL <- ' https://rawgit.com/Norkart/Leaflet-MiniMap/master/example/local_pubs_restaurant_norway.js'
51
+ v8 <- V8 :: v8()
52
+ v8 $ source(jsURL )
53
+ geoJson <- geojsonio :: as.json(v8 $ get(' pubsGeoJSON' ))
54
+
55
+ # This is the kicker, convert geojson to a Spatial object.
56
+ # This then allows us to use formulas in our markers, polygons etc.
57
+ spdf <- geojsonio :: geojson_sp(geoJson )
58
+
59
+ icons <- awesomeIconList(
60
+ pub = makeAwesomeIcon(icon = ' glass' , library = ' fa' , markerColor = ' red' ),
61
+ restaurant = makeAwesomeIcon(icon = ' cutlery' , library = ' fa' , markerColor = ' blue' )
62
+ )
63
+
64
+ leaflet() %> % addTiles() %> %
65
+ setView(10.758276373601069 , 59.92448055859924 , 13 ) %> %
66
+ addAwesomeMarkers(data = spdf ,
67
+ label = ~ stringr :: str_c(amenity ,' : ' , name ),
68
+ icon = ~ icons [amenity ],
69
+ options = markerOptions(riseOnHover = TRUE , opacity = 0.75 ),
70
+ group = ' pubs' ) %> %
71
+ addMiniMap() %> %
72
+ htmlwidgets :: onRender(" function(el, t) {
73
+ var myMap = this;
74
+
75
+ var pubs = myMap.layerManager._byGroup.pubs;
76
+ var pubs2 = new L.FeatureGroup();
77
+
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
+ }" )
88
+
89
+ # ' <br/><br/>
90
+ # ' Finally combine the approaches in last 2 examples
91
+ # ' Minimap w/ changable layers and circle markers.
92
+ m <- leaflet()
93
+ esri <- providers %> %
94
+ purrr :: keep(~ grepl(' ^Esri' ,. ))
95
+
96
+ esri %> %
97
+ purrr :: walk(function (x ) m <<- m %> % addProviderTiles(x ,group = x ))
98
+
99
+ m %> %
100
+ setView(10.758276373601069 , 59.92448055859924 , 13 ) %> %
101
+ addAwesomeMarkers(data = spdf ,
102
+ label = ~ stringr :: str_c(amenity ,' : ' , name ),
103
+ icon = ~ icons [amenity ],
104
+ options = markerOptions(riseOnHover = TRUE , opacity = 0.75 ),
105
+ group = ' pubs' ) %> %
106
+ addLayersControl(
107
+ baseGroups = names(esri ),
108
+ options = layersControlOptions(collapsed = FALSE )
109
+ ) %> %
110
+ addMiniMap(tiles = esri [[1 ]],
111
+ 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
+ }" )
0 commit comments