基于不同类别变量的地图上的相交圆

时间:2019-07-17 19:36:31

标签: leaflet r-leaflet

我正在尝试构建一个应用,在该应用中,我展示一些圆,这些圆表示从特定坐标开始的工人的半径。但是,我还希望包括类别变量,例如工人可以从事的客户以及工作的工作日(从星期一到星期五)。选择它们时,我只想在地图上显示具有特定组合的圆。例如,如果我选择Mon和Thr,并且还选择了客户X和Z,那么我只会看到Mon和Thr以及客户X和Z的圈子。我很难使这些交叉点高效地发生。

我考虑这样做的一种方法是找到不同变量之间的组合:因此,如果我有5个客户*和一周中的5天,那么我有25个不同的案例。但是,每个变量下都有很多类别,因此我的UI看起来真的很糟糕。

#Show days Monday and Tuesday 

coverage_Monday_XXXXX_Roberts <- coverage_data %>%
  filter(Days == "Monday", Manager == 'XXXXX Roberts')
coverage_Tuesday_XXXXX_Roberts <- coverage_data %>%
  filter(Days == 'Tuesday', Manager == 'XXXXX Roberts')

# 
coverage_Monday_YYYY_Gutierrez <- coverage_data %>%
  filter(Days == "Monday", Manager == 'YYYY Gutierrez')
coverage_Tuesday_YYYY_Gutierrez <- coverage_data %>%
   filter(Days == 'Tuesday', Manager == 'YYYY Gutierrez')


# #Create label for Monday cases

# #Create label for Monday cases
 coverage_Monday_XXXXX_Roberts$label <- paste("<p>", coverage_Monday_XXXXX_Roberts$Inspector.Name, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$Day, " ", coverage_Monday_XXXXX_Roberts$Region, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$City, ", ", coverage_Monday_XXXXX_Roberts$Postcode, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$State, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$Manager, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$Customer, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$Inspector.Skill, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$Days, "</p>",
                                "<p>", coverage_Monday_XXXXX_Roberts$Radius, "</p>",
                                sep="")

# #Create label for Tuesday cases
 coverage_Tuesday_XXXXX_Roberts$label <- paste("<p>", coverage_Tuesday_XXXXX_Roberts$Inspector.Name, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$Day, " ", coverage_Tuesday_XXXXX_Roberts$Region, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$City, ", ", coverage_Tuesday_XXXXX_Roberts$Postcode, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$State, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$Manager, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$Customer, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$Inspector.Skill, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$Days, "</p>",
                                 "<p>", coverage_Tuesday_XXXXX_Roberts$Radius, "</p>",
                                sep="")

 coverage_Monday_YYYY_Gutierrez$label <- paste("<p>", coverage_Monday_YYYY_Gutierrez$Inspector.Name, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$Day, " ", coverage_Monday_YYYY_Gutierrez$Region, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$City, ", ", coverage_Monday_YYYY_Gutierrez$Postcode, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$State, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$Manager, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$Customer, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$Inspector.Skill, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$Days, "</p>",
                                "<p>", coverage_Monday_YYYY_Gutierrez$Radius, "</p>",
                                sep="")

# Create label for Tuesday cases
 coverage_Tuesday_YYYY_Gutierrez$label <- paste("<p>", coverage_Tuesday_YYYY_Gutierrez$Inspector.Name, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$Day, " ", coverage_Tuesday_YYYY_Gutierrez$Region, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$City, ", ", coverage_Tuesday_YYYY_Gutierrez$Postcode, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$State, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$Manager, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$Customer, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$Inspector.Skill, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$Days, "</p>",
                                 "<p>", coverage_Tuesday_YYYY_Gutierrez$Radius, "</p>",
                                 sep="")



pal <- colorFactor(
  palette = 'Dark2',
  domain = coverage_data$Inpector.Name
)

map11 <- leaflet(coverage_data) %>%
  setView(lng = -95.7129, lat = 34.0902, zoom = 4.499) %>%
  addProviderTiles(providers$Esri.DeLorme) %>%

  ###### DAYS #######
addCircles(lng = coverage_Monday_XXXXX_Roberts$Longitude,
           lat = coverage_Monday_XXXXX_Roberts$Latitude,
           color = ~pal(coverage_Monday_XXXXX_Roberts$Inspector.Name),
           weight = 1,
           radius = coverage_Monday_XXXXX_Roberts$radius,
           opacity = 0.05,
           label = lapply(coverage_Monday_XXXXX_Roberts$label, HTML),
           fillOpacity = 0.05,
           group = "Monday: XXXXX Roberts") %>%

  addCircles(lng = coverage_Tuesday_XXXXX_Roberts$Longitude,
             lat = coverage_Tuesday_XXXXX_Roberts$Latitude,
             color = ~pal(coverage_Tuesday_XXXXX_Roberts$Inspector.Name),
             weight = 1,
             radius = coverage_Tuesday_XXXXX_Roberts$radius,
             opacity = 0.05,
             fillOpacity = 0.05,
             label = lapply(coverage_Tuesday_XXXXX_Roberts$label, HTML),
             group = "Tuesday: XXXXX Roberts") %>%

  addCircles(lng = coverage_Monday_YYYY_Gutierrez$Longitude,
             lat = coverage_Monday_YYYY_Gutierrez$Latitude,
             color = ~pal(coverage_Monday_YYYY_Gutierrez$Inspector.Name),
             weight = 1,
             radius = coverage_Monday_YYYY_Gutierrez$radius,
             opacity = 0.05,
             label = lapply(coverage_Monday_YYYY_Gutierrez$label, HTML),
             fillOpacity = 0.05,
             group = "Monday: YYYY Gutierrez") %>%

  addCircles(lng = coverage_Tuesday_YYYY_Gutierrez$Longitude,
             lat = coverage_Tuesday_YYYY_Gutierrez$Latitude,
             color = ~pal(coverage_Tuesday_YYYY_Gutierrez$Inspector.Name),
             weight = 1,
             radius = coverage_Tuesday_YYYY_Gutierrez$radius,
             opacity = 0.05,
             fillOpacity = 0.05,
             label = lapply(coverage_Tuesday_YYYY_Gutierrez$label, HTML),
             group = "Tuesday: YYYY_Gutierrez") %>%

  addLayersControl(
    overlayGroups= c("Monday: XXXXX Roberts", "Tuesday: XXXXX Roberts",# "Wednesday: XXXXX Roberts", "Thursday: XXXXX Roberts", "Friday: XXXXX Roberts",
                     "Monday: YYYY Gutierrez", "Tuesday: YYYY Gutierrez"), # "Wednesday: YYYY Gutierrez", "Thursday: YYYY Gutierrez", "Friday: YYYY Gutierrez"),

    options = layersControlOptions(collapsed = FALSE))

map11

在我的应用程序中,我希望能够选择日期(星期一和星期三)和客户(例如X和Z),从而看到可以在星期一和星期三做X和Z客户的所有工作人员的圈子。

0 个答案:

没有答案