【问题标题】:leaflet search don't make a search传单搜索 不要搜索
【发布时间】:2022-09-30 21:21:10
【问题描述】:

我想制作一张地图来比较同一点的 2 个坐标。是1500个不同的点。

DFINAL<-
structure(list(ACCENUMB = c(\"G 2771\", \"G 2771A\", \"G 6386\", \"G 7225\", 
\"G 7225A\", \"G 7253B\", \"G 7479\", \"G 7479A\", \"G 7479B\", \"G 7479C\"
), LATITUDE = c(21.09, 22.09, 18.88, -13.67, -13.21, 2.67, 16.32, 
18.4, 15.32, 12.32), LONGITUDE = c(-104.42, -104.42, -99.15, 
-72.88, -72.88, -75.98, -99.82, -99.82, -99.82, -99.82), ORIGCTY = c(\"MEX\", 
\"MEX\", \"MEX\", \"PER\", \"PER\", \"COL\", \"MEX\", \"MEX\", \"MEX\", \"MEX\"
), LATITUD_NEW = c(21.17, 21.17, 18.9, -13.67, -13.67, 2.68, 
18.32, 18.32, 18.32, 18.32), LONGITUD_NEW = c(-104.37, -102.37, 
-99.15, -72.89, -75.89, -75.99, -99.82, -94.82, -93.82, -91.82
)), class = c(\"tbl_df\", \"tbl\", \"data.frame\"), row.names = c(NA, 
-10L))

代码运行良好,但是当我搜索 ACCENUMB 时不会加载。

library(tidyverse)
library(leaflet) 

NUM_ORIGCTY <- DFINAL$ORIGCTY %>% unique() %>% length()

Names_ORIGCTY <- DFINAL$ORIGCTY %>% unique()

Colores <- c(\"#5F11A3\",\"#FF1300\",\"#0F629C\", \"#F3E908\")

pal <- colorFactor(
  palette = c(\"#5F11A3\",\"#FF1300\",\"#0F0065\", \"#F70079\"),
  domain = DFINAL$ORIGCTY)


m3<-leaflet() %>%
  addTiles() %>%
  #setView(lng=-76.5, lat=2.2 , zoom=9) %>%
  addCircles(data=DFINAL,
    lng = ~LONGITUDE, 
    lat=~LATITUDE,
    color=~pal(ORIGCTY),
    fillOpacity =20,
    weight =9,
    popup = paste(\"<h3 style=\'color:#002053\'> DATOS </h3>\",
      \"<b style=\'color:#214173\'> ACCENUMB:</b>\",DFINAL$ACCENUMB,\"<br>\",
      \"<b style=\'color:#214173\'> PAIS:</b>\",DFINAL$ORIGCTY,\"<br>\",
      \"<b style=\'color:#214173\'> LATITUD:</b>\",DFINAL$LATITUDE,\"<br>\",
      \"<b style=\'color:#214173\'> LONGITUD:</b>\",DFINAL$LONGITUDE,\"<br>\"),
    group = ~ ORIGCTY) %>%
  
  addMarkers(data=DFINAL,
    lng = ~LONGITUD_NEW, 
    lat=~LATITUD_NEW,
    group = \'ACCENUMB\',
    popup = paste(\"<h3 style=\'color:#008000\'> DATOS </h3>\",
      \"<b style=\'color:#AAAA39\'> ACCENUMB:</b>\",DFINAL$ACCENUMB,\"<br>\",
      \"<b style=\'color:#AAAA39\'> PAIS:</b>\",DFINAL$ORIGCTY,\"<br>\",
      \"<b style=\'color:#AAAA39\'> LATITUD:</b>\",DFINAL$LATITUD_NEW,\"<br>\",
      \"<b style=\'color:#AAAA39\'> LONGITUD:</b>\",DFINAL$LONGITUD_NEW,\"<br>\")) %>% 
  
  addLegend(data = DFINAL,\'bottomright\', pal = pal,
    values = ~ ORIGCTY, title = \"PAISES\",
    opacity = 0.8,group = \"Leyenda\")  %>% 
  
  addLayersControl(overlayGroup=Names_ORIGCTY,
    options = layersControlOptions(collapsed=F)) %>%
  
  addResetMapButton() %>%
  
  #####
addSearchFeatures(
  targetGroups = \'ACCENUMB\', # group should match addMarkers() group
  options = searchFeaturesOptions(
    zoom=12, openPopup = TRUE, firstTipSubmit = TRUE,
    autoCollapse = TRUE, hideMarkerOnCollapse = TRUE
  )
) %>%
  addControl(\"<P><B>Hi!</B> Search for ...<br/>
              <ul><li>ACESSION NAME</li>\",
    position = \'topleft\')
  
m3

这个想法是当把ACCENUMB 搜索这个。

    标签: r leaflet tidyverse


    【解决方案1】:

    我用library(inlmisc)library(leaflet) 找到了解决方案。

    m2 <- leaflet() %>% 
      addTiles() %>% 
      addMarkers(label = ~ACCENUMB, popup = paste("<h3 style='color:#008000'> DIMARY</h3>",
        "<b style='color:#bb042b'> ACCESION: </b>",DFINAL$ACCENUMB, "<br>",
        "<b style='color:#bb042b'> LATITUD: </b>",DFINAL$LATITUD_NEW, "<br>",
        "<b style='color:#bb042b'> LONGITUD:</b>",DFINAL$LONGITUD_NEW,"<br>"), 
        clusterId = "cluster",
        group = "marker", lng = ~ LONGITUD_NEW,  lat= ~ LATITUD_NEW, data= DFINAL) %>% 
      
      AddSearchButton( group = "marker", zoom = 20,  # For add search box in the map.
        textPlaceholder = "Search accesion name...") %>%
      
      addCircles(label = ~ACCENUMB,
        data=DFINAL,
        lng = ~LONGITUDE, 
        lat=~LATITUDE,
       # color=~pal(ORIGCTY),
        fillOpacity = 1,
        weight =8,
        popup = paste("<h3 style='color:#008000'> ORACLE</h3>",
          "<b style='color:#bb042b'> ACCESION: </b>",DFINAL$ACCENUMB , "<br>",
          "<b style='color:#bb042b'> LATITUD: </b>",DFINAL$LATITUDE, "<br>",
          "<b style='color:#bb042b'> LONGITUD:</b>",DFINAL$LONGITUDE,"<br>"))
    
    m2
    

    当我输入名称时,最终地图进行搜索加入.

    【讨论】:

      猜你喜欢
      • 2022-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多