0

我开始在 R's Shiny 中使用传单,我正在使用 RStudio。我想创建一个带有起点和终点标记的地图,这些标记可以通过用户输入进行更改。因为我有很多标记要管理,所以我想使用集群插件所以我创建了一个闪亮的服务器:

server <- function(input, output, session) {

  reactiveData <- reactiveValues(
    origs = df.origins.total,
    dests = df.destinations.total
  )
  mydata <- reactive({
    mydf = data.frame(orig_lat=df.origins.total$lat,
                      orig_lon=df.origins.total$lon,
                      dest_lat=df.destinations.total$lat,
                      dest_lon=df.destinations.total$lon)
    print(str(mydf))
    return(mydf)
  })
  observe({
    leafletProxy("map",data=mydata()) %>%
      clearGroup("Destinations") %>%
      addMarkers(
        lng=~dest_lon,
        lat=~dest_lat,
        icon = uix.destMarker,
        group = "Destinations",
        clusterOptions = markerClusterOptions(
        )) 

  })
  observe({
    leafletProxy("map",data=mydata()) %>%
      clearGroup("Origins") %>%
      addMarkers(
        lng=~orig_lon,
        lat=~orig_lat,
        icon = uix.origMarker,
        group = "Origins",
        clusterOptions = markerClusterOptions(

        ))  
  })
  observe({
    leafletProxy("map",data=mydata()) %>%
      addLayersControl(overlayGroups = c("Origins","Destinations"))  
  })

  output$map <- renderLeaflet({
    leaflet() %>%
      addTiles()%>%
  })


}

奇怪的是,这段代码有时有效,有时无效,这意味着:它要么向我显示起点和终点,要么只显示终点。当只显示目的地时,我正在使用 Firefox 的检查器,它告诉我:

TypeError: _leaflet2.default.markerClusterGroup is undefined
leaflet.js:1273:7

这导致了这条线

clusterGroup = _leaflet2.default.markerClusterGroup.layerSupport(clusterOptions);

我想我已经正确安装了这些软件包,因为它们有时可以工作。即使发生错误,聚类仍然适用于显示的标记。我的数据集每个都有大约 2400 个标记。将所有观察者调用合并到一个观察者中也不会改变行为。我的数据集很大吗?我必须使用不同的顺序吗?我真的没有任何想法,任何帮助将不胜感激!

4

1 回答 1

0

问题是/是 iconCreatFunction 没有被 LeafletProxy 很好地支持。就我而言,不幸的是,我不得不为我的集群摆脱leafletProxy,而只使用leaflet,这是一个很大的性能问题。

另一种解决方案可能是从插件自定义相应的文件:MarkerCluster.css、MarkerCluster.Default.css、leaflet.markercluster.js(我没有这样做,因为我不知道如何区分两种类型的标记必须单独聚类)。

帮助我的相关问题,我希望它能帮助其他开发人员解决同样的问题:

markercluster 是否与 LeafletProxy() 和选项 iconCreateFunction 一起使用?

使用 leafletProxy 添加标记时,iconCreateFunction 不起作用

于 2018-03-19T10:15:42.077 回答