admin管理员组文章数量:1277297
I'm using the leaflet library in R, which is a wrapper to the leaflet.js library. I'm wondering if it is possible to add a query or search button using the R interface (or some hack to the underlying code)? There are search plug-ins to the javascript library here .html#search--popups, but I can't figure out how to get them to work with the javascript that es out from the R library.
As a minimal example, I want to add to the following the ability to search for "location 1" in the following map, and have it display the popup:
library(leaflet)
df = read.csv(textConnection(
'Name, Lat, Long
<b>location 1</b>,42.3401, -71.0589
<b>location 2</b>,42.3501, -71.0689'))
leaflet(df) %>%
addTiles() %>%
setView(lng=-71.0589,lat=42.3301, zoom=12) %>%
addMarkers(~Long, ~Lat, popup = ~Name
)
I'm using the leaflet library in R, which is a wrapper to the leaflet.js library. I'm wondering if it is possible to add a query or search button using the R interface (or some hack to the underlying code)? There are search plug-ins to the javascript library here http://leafletjs./plugins.html#search--popups, but I can't figure out how to get them to work with the javascript that es out from the R library.
As a minimal example, I want to add to the following the ability to search for "location 1" in the following map, and have it display the popup:
library(leaflet)
df = read.csv(textConnection(
'Name, Lat, Long
<b>location 1</b>,42.3401, -71.0589
<b>location 2</b>,42.3501, -71.0689'))
leaflet(df) %>%
addTiles() %>%
setView(lng=-71.0589,lat=42.3301, zoom=12) %>%
addMarkers(~Long, ~Lat, popup = ~Name
)
Share
Improve this question
asked Jun 13, 2016 at 20:35
DevonDevon
6901 gold badge10 silver badges19 bronze badges
3 Answers
Reset to default 5A plete working example of adding a search bar using the leafletplugins package is here:
devtools::install_github('byzheng/leaflet')
library(leaflet)
library(leafletplugins)
df = read.csv(textConnection(
'Name, Lat, Long, Name2
<b>location 1</b>,42.3401, -71.0589, Loc 1
<b>location 2</b>,42.3501, -71.0689, Loc 2'))
leaflet(df) %>%
addTiles() %>%
setView(lng=-71.0589,lat=42.3301, zoom=12) %>%
addMarkers(~Long, ~Lat, popup = ~Name, group = 'marker', label = ~Name2) %>%
addSearchMarker('marker', position='topleft', propertyName = 'label')
It appears that there is a search plugin for the R leaflet package: https://github./byzheng/leafletplugins
Check out the inlmisc
package and AddSearchButton
df = read.csv(textConnection(
'Name, Lat, Long
<b>location 1</b>,42.3401, -71.0589
<b>location 2</b>,42.3501, -71.0689'))
map=leaflet(df) %>%
addTiles() %>%
setView(lng=-71.0589,lat=42.3301, zoom=12) %>%
addMarkers(~Long, ~Lat, popup = ~Name, group="marker")
map=inlmisc::AddSearchButton(map, group = "marker", zoom = 15,
textPlaceholder = "Search here")
本文标签: javascriptSearch button for Leaflet R mapStack Overflow
版权声明:本文标题:javascript - Search button for Leaflet R map? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741292580a2370632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论