React: Leaflet Icon

This entry is part 8 of 9 in the series React: Leaflet

In this tutorial I will demonstrate how to add an icon to the map. Refer to the documentation for more information.

Before We Begin:

Create Folders/Files:

  • app
    • folder: leaflet
      • folder: images
        • file: yourimage.png

Import Image(s):

import yourimage from "../images/yourimage.png";

Create Icon:

var myIcon = L.icon({
     iconUrl: plusimg,
     iconSize:     [75, 75], // size of the icon
     iconAnchor:   [22, 94], // point of the icon which will correspond to marker's location
});

Add to Map:

[51.5, -0.09] refers to the position on the map you want to add it to. Refer to the marker tutorial for further information on markers.

L.marker([51.5, -0.09], {icon: myIcon}).addTo(this.map);