1
votes

So I am making a Leaflet map. I am using a json which lists countries as Latlng points, and their corresponding attribute (called CTH values). I am trying to use this value to set the area of circle markers on these Latlng points to be proportional to the CTH value, but I am struggling to figure out how.

This is what I've written

    function addCTHValueMarkers () {

       CTHValueLayer = L.geoJSON(CTHValue,  {
                    pointToLayer: function (feature, latlng) {
                        return new L.circleMarker(latlng, {
                        fillOpacity: 0.6,
                        radius: setRadius(feature.properties.CTHValue)
                       })
                    }
    });

   CTHValueLayer.addTo(map);
   }

I was originally going to use the radius but I need area to make them actually proportional, can someone show me how I set the area? Do I make a seperate function to work out area, then pass this to the radius? How do I do this?

Whenever I try to refer to (feature.properties.CTHValue) outside of the CTHValueLayer = L.geojson(CTHValue { }) argument it doesn't work, can someone show me how I can access the CTH Value from within my geojson in a seperate function, so I can pass the CTHValue to an area calculation

1
no :( i now know i have to use area not radius, but idk how to do that either.sophhGIS
im trying to do it like this: function updatePropSymbols() { var props = (feature.properties.CTHValue); var radius = setRadius(props); } function setRadius(props) { var scaleFactor = 0.01; var area = props * scaleFactor; return Math.sqrt(area / Math.PI); } but I get an error in the console saying "feature is undefined" i think its bc its in a seperate function to my initialising the json so it doesnt recognise feature.properties.CTHValue. so how do i pass the CTH value from my json into the radius function?sophhGIS
Hey, please stop with the duplicate questions! I think you're up to 6 now on this one problem.peeebeee
well im stuck and was told to use this forum when im stuck?? im on a deadline. i have tried to do it myself and updated each time with what ive tried to do. i cannot move on until ive done this and i urgently need to move onsophhGIS

1 Answers

-1
votes

So probably you need to use L.circle instead L.circleMarker. Because circleMarker it's a Marker and doesn't have size