I am using GetFeatureInfo to create a popup for different layers and features in a map in Leaflet. I have up to 3 layers that can be visible and overlapping at any given time. If I put the option "feature_count=3" in my request to GeoServer it works great with the exception of when I am zoomed out and features are very small. When this happens and only one layer is visible I will often get 3 results in the popup for that layer. It seems that since the location I click on might refer to more than one feature in a layer, it returns three features for that layer. I have different code that inserts only visible layers into the code below.
How do I ensure that when clicking the map, only one feature's info per layer is returned in the popup? I wish the "feature_count" option referred to how many features to return per layer.
Is there an option in GeoServer that I am missing or an option in my code? Do I have to generate a different link like the one above for each layer?