It looks like you're happy with the overall setup but want to refine the cluster visualization by only changing the circle color based on the point count, while keeping the circle size fixed. That's a straightforward adjustment!
In the original code, the circle radius was set to a static value (20 pixels). I'll modify the Layer to make the color dynamic (as I suggested before) but ensure the radius remains constant. This way, clusters won't grow in size; they'll just change color to indicate density.
Updated Code Snippet
Here's the updated <Layer> for the clusters. I'll replace the relevant part in your code:
tsx
<Layer
id="clusters"
type="circle"
filter={["has", "point_count"]}
paint={{
// Only change the circle color based on point count
"circle-color": [
"step",
["get", "point_count"],
"#51bbd6", // Default color for clusters with fewer than 10 points
10,
"#f1f075", // Color for clusters with 10-29 points
30,
"#f28cb1", // Color for clusters with 30 or more points
],
// Keep the circle radius fixed (no changes based on point count)
"circle-radius": 20, // Static radius, as in your original code
"circle-stroke-width": 1,
"circle-stroke-color": "#fff",
}}
/>
What's Changed?
Circle Color: This remains dynamic and uses a "step" expression to change based on the number of points in the cluster. I kept the color thresholds from my previous suggestion for consistency, but you can tweak the colors or thresholds as needed (e.g., if you want different color values).
Circle Radius: I removed the dynamic radius logic and set it back to a fixed value of 20 (matching your original code). This ensures that clusters don't change size, only their color.
Full Context in Your Component
Replace the existing <Layer id="clusters" ... /> in your MapMapboxCluster component with the updated version above. Your full code would look like this (just the relevant part shown for brevity):
tsx
<Source
id="markers"
type="geojson"
data={convertToGeoJSON(markers)}
cluster={true}
clusterMaxZoom={14} // You can keep or adjust this as per your earlier calibration
clusterRadius={50} // And this one too
>
<Layer
id="clusters"
type="circle"
filter={["has", "point_count"]}
paint={{
"circle-color": [
"step",
["get", "point_count"],
"#51bbd6",
10,
"#f1f075",
30,
"#f28cb1",
],
"circle-radius": 20,
"circle-stroke-width": 1,
"circle-stroke-color": "#fff",
}}
/>
<Layer
id="cluster-count"
type="symbol"
filter={["has", "point_count"]}
layout={{
"text-field": "{point_count_abbreviated}",
"text-size": 14,
}}
/>
<Layer
id="unclustered-point"
type="circle"
filter={["!", ["has", "point_count"]]}
paint={{
"circle-color": "#007AFF",
"circle-radius": 6,
"circle-stroke-width": 1,
"circle-stroke-color": "#fff",
}}
/>
</Source>
Tips for Further Customization
Color Choices: The colors I used (#51bbd6, #f1f075, #f28cb1) are just examples. Feel free to replace them with your own palette for better branding or visibility.
Thresholds: The steps (e.g., 10, 30) are arbitrary. If your data has different densities, adjust these numbers to better reflect your markers (e.g., change to 5 and 20 if you have smaller clusters).
Testing: After making this change, test the map at different zoom levels to ensure the color changes are intuitive and don't affect performance.
If this doesn't quite hit the mark or you want to adjust the colors, thresholds, or anything else, let me know—I can refine it further! 😊