I have been using leaflet to create some very cool maps, thanks for that!
I have added markers and pop-ups to the map and now I would like to be able to search these markers using a toolbar on the map. I have seen that this is possible in the js version of leaflet https://github.com/stefanocudini/leaflet-search#examples and I would really like to implement this in R.
Hey, I am interested in this too. Began looking at it today and got as far as adding the search feature to my map.
I have found that this method works for quite a few of the plugins with a good dose of trial and error.
This is where I learned the method of using Leaflets JS Plugins with R, but I'm sure there are other examples if you search them.
Unfortunately I haven't figured out how to actually search for my data yet.
I have markers and want to be able to search for them by name. I assume you have to associate a search tag/feature with each name in your data set but haven't searched/read up on it yet.
If someone can tell me it would be much appreciated - If I figure it out I'll edit this post.
library(htmlwidgets)
library(htmltools)
library (leaflet)
defaultExtentPlugin <- htmlDependency("Leaflet Search", "2.7.0", src = c(href = "pathfile you saved and unzipped the zip folder to/leaflet-search-master/src"), script = "leaflet-search.js", stylesheet = "leaflet-search.css")
registerPlugin <- function(map, plugin){
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leafletMap <- leaflet() %>%
# Add Home Button (default extent)
registerPlugin(defaultExtentPlugin) %>%
onRender("function(el, x) {
var searchLayer = L.layerGroup().addTo(this);
//... adding data in searchLayer ...
this.addControl( new L.Control.Search({layer: searchLayer}) );
//searchLayer is a L.LayerGroup contains searched markers
}") %>%
Already available in https://github.com/bhaskarvk/leaflet.extras/.
Demo http://rpubs.com/bhaskarvk/leaflet-search
Ah very good,
Thanks very much for that. Appreciate it.
Most helpful comment
Already available in https://github.com/bhaskarvk/leaflet.extras/.
Demo http://rpubs.com/bhaskarvk/leaflet-search