icon rotation in leaflet package

后端 未结 2 1756
有刺的猬
有刺的猬 2021-01-13 06:58

I\'m learning to program in R with the leaflet package. I want to give an angle to the icons, and am trying it with this code:

m <- leaflet()
m <- ad         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-13 07:18

    For your first point, I've found that you can load your image if it's stored in a directory named www.

    |
    |- app.R
    |- www
        |- icon_plane.pg
    

    Then you'll be able to load it with this piece of code

    onRender("function(el, x) {
              var planeIcon = L.icon({iconUrl: 'icon_plane.png', iconAnchor:[16, 16]});
              var pathPattern = L.marker([34.45, 127.07], {icon: planeIcon, rotationAngle: 90}).addTo(this);
              }")
    

    Becareful of loading correctly your js file. I spent a lot of time looking why my image wasn't showing and finally it was only because my script wasn't in the correct place.

提交回复
热议问题