I have a Leaflet javascript web application which uses WMS to make calls to GeoServer. The returned object is Geometry plus attributes. While the Geometry (polygons) render fine as Counties in the US, I need to make the Counties layer to show different colors, based on County populations.
Here is code to load the WMS data:
var wmscounty = L.tileLayer.wms("<?php echo $geoserverwms_url; ?>", {
layers: '<?php echo $geoserverwms_layer_countypop; ?>',
format: 'image/png',
transparent: true,
version: '1.1.1',
attribution: "countypopulation"
}
wmscounty.addTo(map);
The code I could possibly use set the layer's styles are:
function getColorCounties(d) {
return d > 1000000 ? '#800026' :
d > 50000 ? '#FED976' :
'#FFEDA0';
}
function styleCounties(feature) {
return {
weight: 2,
fillColor: getColorCounties(feature.properties.COUNTY_POP)
};
}
I don't know how to pass the 'feature' object to the styleCounties() function? Should it be in some onAdd() function? Or some 'forEach'. There are some examples available but I can't find any for Leaflet/WMS.
Thanks!