0

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);
        }
 });

1 Answer 1

4

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.

5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.