React: Leaflet Icon

This entry is part 8 of 9 in the series React: Leaflet
(Last Updated On: )

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):

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

Create Icon:

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

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.

  1. L.marker([51.5, -0.09], {icon: myIcon}).addTo(this.map);
Series Navigation<< React: Leaflet ControlReact: Leaflet Markers >>