R Leaflet自定义归因字符串

时间:2017-07-06 15:26:19

标签: javascript r leaflet

使用R leaflet包时,如何在属性字符串中添加其他内容(即右下角的“Leaflet | ...”)?

例如,我如何在此地图上的归属文字中添加“数据源:...”之类的内容:

leaflet(data = quakes[1:20,]) %>% 
  addTiles() %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

2 个答案:

答案 0 :(得分:2)

您可以向attribution添加addTiles参数:

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

我很想知道如何使用addProviderTiles执行此操作,因为它似乎不接受attribution参数:/

编辑:好吧,我使用提供程序磁贴的解决方法就是使用这两个函数。我希望它实际上并没有同时调用两个磁贴,因为这有点浪费用户带宽 - 但是嘿,它看起来很好!

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

答案 1 :(得分:0)

正如@rensa怀疑的那样,他们的第二个选择确实确实嵌入并获取了两个图块集。但是,设置空白的urlTemplate似乎可以阻止它:

int a, c;
double b;
a = Convert.ToInt32(Console.ReadLine());

if (a < 100)
{
    b = a + a * 0.2;
    bFormatted = b.toString() + "%";
    Console.WriteLine(bFormatted);
}
else if (a > 200)
{
    b = a + a * 0.3;
    bFormatted = b.toString() + "%";
    Console.WriteLine(bFormatted);
}
else if (a == 300)
{
    b = a + a * 0.4;
    bFormatted = b.toString() + "%";
    Console.WriteLine(bFormatted);
}
else 
    aFormatted = a.toString() + "%";
    Console.WriteLine(aFormatted);