我正在使用R中的传单库,它是leaflet.js库的包装器。我想知道是否可以使用R接口添加查询或搜索按钮(或者对底层代码进行一些破解)?这里有javascript库的搜索插件http://leafletjs.com/plugins.html#search--popups,但我无法弄清楚如何让它们使用来自R库的javascript。
作为一个最小的例子,我想在下面的地图中添加搜索“位置1”的功能,并让它显示弹出窗口:
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
)
答案 0 :(得分:2)
使用leafletplugins包添加搜索栏的完整工作示例如下:
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')
答案 1 :(得分:1)
看来R小册子包有一个搜索插件:https://github.com/byzheng/leafletplugins
答案 2 :(得分:0)
Check out inlmisc
软件包和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")