Change color of leaflet marker

后端 未结 5 1258
甜味超标
甜味超标 2020-12-05 08:15

Is there anyway to change the color of leaflet marker base on the value of some variable. In the following map, for example, I wish to assign marker color based on mag varia

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 08:27

    This one worked for me:

    Source: https://github.com/bhaskarvk/leaflet/blob/master/inst/examples/awesomeMarkers.R

    library(leaflet)
    
    icon.glyphicon <- makeAwesomeIcon(icon= 'flag', markerColor = 'blue', iconColor = 'black')
    icon.fa <- makeAwesomeIcon(icon = 'flag', markerColor = 'red', library='fa', iconColor = 'black')
    icon.ion <- makeAwesomeIcon(icon = 'home', markerColor = 'green', library='ion')
    
    # Marker + Label
    leaflet() %>% addTiles() %>%
      addAwesomeMarkers(
        lng=-118.456554, lat=34.078039,
        label='This is a label',
        icon = icon.glyphicon)
    
    leaflet() %>% addTiles() %>%
      addAwesomeMarkers(
        lng=-118.456554, lat=34.078039,
        label='This is a label',
        icon = icon.fa)
    
    leaflet() %>% addTiles() %>%
      addAwesomeMarkers(
        lng=-118.456554, lat=34.078039,
        label='This is a label',
        icon = icon.ion)
    
    # Marker + Static Label using custom label options
    leaflet() %>% addTiles() %>%
      addAwesomeMarkers(
        lng=-118.456554, lat=34.078039,
        label='This is a static label',
        labelOptions = labelOptions(noHide = T),
        icon = icon.fa)
    

提交回复
热议问题