custom marker icon with react-leaflet

后端 未结 3 1762
挽巷
挽巷 2021-01-03 23:56

I tried everything I found on the web, Stackoverflow and Github, and I still can\'t make it.

I want to make a custom marker with a custom icon, but with my code belo

3条回答
  •  轮回少年
    2021-01-04 00:45

    You don't need to use require. instead of giving iconUrl = "../assets/name" you only need to import your png or svg then you can give the source to your iconUrl. look at the example below:

    // first import your image or svg

    import heart from "../../images/other/love.svg";
    

    // give the source to your icon

    let loveIcon = L.icon({
      iconUrl: heart,
      iconRetinaUrl: heart,
      iconAnchor: [5, 55],
      popupAnchor: [10, -44],
      iconSize: [25, 55],
    });
    

    // simply add it to your map

    L.marker([28, 50], {
           icon: loveIcon,
         }).addTo(map);
    

提交回复
热议问题