【问题标题】:upload a R leaflet to Arcgis Online将 R 传单上传到 Arcgis Online
【发布时间】:2022-11-07 14:46:41
【问题描述】:

基于How to show/hide legend with control layer panel with leaflet? 的数据示例

有谁知道是否可以将包含 R 中生成的传单的 html 文件上传到 ArcGis Online 帐户?或者是否有另一种方法(不一定是 html 文件)可以识别 ArcGis Online 中的标签、弹出窗口和动态图例,就像它们在 R 中呈现的方式一样? 谢谢!

library(leaflet)

cities1 <- data.frame(City = factor(c("Boston", "Hartford", 
                                      "New York City", "Philadelphia", "Pittsburgh", "Providence")),
                      Lat = c(42.3601, 41.7627, 40.7127, 39.95, 40.4397, 41.8236),
                      Long = c(-71.0589, -72.6743, -74.0059, -75.1667, -79.9764, -71.4222), 
                      Pop = c(645966L, 125017L, 8406000L, 1553000L, 305841L, 177994L),
                      Type = factor(c("C", "D", "A", "A", "B", "C")))

cities2 <- data.frame(City = factor(c("Baltimore", "Ithaca", "Wareham")),
                      Lat = c(39.299236, 42.443962, 41.761452), 
                      Long = c(-76.609383, -76.501884, -70.719734), 
                      Pop = c(609032L, 30569L, 22666L),
                      Type = factor(letters[1:3]))

pal1 <- colorFactor("viridis", domain = cities1$Type) #create some color coding for each city
pal2 <- colorFactor("Set1", domain = cities2$Type)

leaflet(cities1) %>% 
  addTiles() %>%
  addCircles(data = cities1, lng = ~Long, lat = ~Lat, weight = 1, group="one",
             radius = ~sqrt(Pop) * 30, color = ~pal1(Type), opacity = .9,
             label = cities1$City,
             popup =  paste0("<font size=2 color=#045FB4>", "<b>Population: </b>",cities1$Pop,"</font>", "</br>")) %>% # add a pop-up
  addLegend(pal = pal1, values = ~Type, group  = "one", layerId = "one") %>%
  addCircles(data = cities2, lng = ~Long, lat = ~Lat, weight = 1, group = "two",
             radius = ~sqrt(Pop) * 30, color = ~pal2(Type), opacity = .9,
             popup =  paste0("<font size=2 color=#045FB4>", "<b>City: </b>",cities2$Pop,"</font>", "</br>")) %>%
  addLegend(pal = pal2, values = ~Type, data = cities2, group = "two", layerId = "two") %>%
  addLayersControl(
    baseGroups = c("one", "two"),
    options = layersControlOptions(collapsed = FALSE),
    position = "topleft"
  ) %>% 

# the code below makes the legend reactive when a layer is turned off.

  htmlwidgets::onRender("
    function() { 
      var map = this;
      var legends = map.controls._controlsById;
      function addActualLegend() {
         var sel = $('.leaflet-control-layers-base').find('input[type=\"radio\"]:checked').siblings('span').text().trim();
         $.each(map.controls._controlsById, (nm) => map.removeControl(map.controls.get(nm)));
         map.addControl(legends[sel]);
      }
      $('.leaflet-control-layers-base').on('click', addActualLegend);
      addActualLegend();
   }")

【问题讨论】:

    标签: r leaflet arcgis arcgis-server arcgis-online


    【解决方案1】:

    你有没有解决这个问题?

    【讨论】:

    猜你喜欢
    • 2017-06-12
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    相关资源
    最近更新 更多