[GIS] Changing marker shape to circles in Leaflet

leafletmarkerssymbology

I was wondering how to change the default marker shape in a Leaflet map to circles

$.ajax("data/StatesPopulation.geojson", {
        dataType: "json",
        success: function(response){
            L.geoJson(response, {
                onEachFeature: onEachFeature
            }).addTo(mymap);
        }
 });

Best Answer

Within the L.geoJson function you can call the pointToLayer function.

To create circles you can do something like:

$.ajax("data/StatesPopulation.geojson", {
  dataType: "json",
  success: function(response) {
    L.geoJson(response, {
      pointToLayer: function(feature, latlng) {
        return new L.CircleMarker(latlng, {
          radius: 5,
          color: '#FF0000'
        });
      },
      onEachFeature: onEachFeature
    }).addTo(mymap);
  }
});

In this documentation you can see a more detailed example.