简体   繁体   English

在传单地图上绘制几个标记

[英]Plot severals markers on a leaflet map

Hi i'm trying to learn how to use a leaflet map on shiny, I used that example : 嗨,我正在尝试学习如何在发亮的地方使用传单地图,我使用了以下示例:

http://glimmer.rstudio.com/jcheng/leaflet-demo/ http://glimmer.rstudio.com/jcheng/leaflet-demo/

Here is the code repository : 这是代码库:

https://github.com/jcheng5/leaflet-shiny/blob/master/inst/example/ https://github.com/jcheng5/leaflet-shiny/blob/master/inst/example/

I'm would like to replace circles by markers by replacing the addCircle function by addMarker . 我想通过更换以取代标记圈addCircle按功能addMarker

The actual function is : (line 98 of Server.R) 实际的功能是:(Server.R的第98行)

map$addCircle(
  cities$Lat,
  cities$Long,
  sqrt(cities[[popCol()]]) * radiusFactor / max(5, input$map_zoom)^2,
  row.names(cities),
  list(
    weight=1.2,
    fill=TRUE,
    color='#4A9'
  )
)

And I just replaced it by : 我只是将其替换为:

map$addMarker(
  cities$Lat,
  cities$Long,
  row.names(cities)
)

But it only plot the marker on the first city of the data frame. 但它只会将标记绘制在数据框的第一个城市上。 And after if you move and zoom randomly on the map some other markers can appear... 如果您在地图上随意移动和缩放,则可能会显示其他标记...

Why addCircle draws a circle for each cities and addMarker behaves "randomly" ? 为什么addCircle为每个城市绘制一个圆圈,并且addMarker表现为“随机”?

How can I draw severals marker at once on the plot ? 如何在情节上一次绘制几个标记?
The loop bellow works but ideally I don't want to loop manually if it's possible. 循环波纹管工作,但理想情况下,如果可能的话,我不想手动循环。

for(i in 1:nrow(cities)){
    map$addMarker(
      cities$Lat[i],
      cities$Long[i],
      i
    )
}

Thank you 谢谢

I had the same problem, it is because you remove the radius. 我有同样的问题,这是因为您删除了半径。 By looking at the code for the function createLeafletMap, we can see that addCircle needs these arguments: 通过查看函数createLeafletMap的代码,我们可以看到addCircle需要以下参数:

addCircle(lat, lng, radius, layerId = NULL, options=list(), eachOptions=list())

it really need radius. 它真的需要半径。 to solve your problem just write: 要解决您的问题,只需写:

map$addMarker(
  cities$Lat,
  cities$Long,
  100,
  row.names(cities)
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM