-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: initial implementation of showing clustered responses #119
base: main
Are you sure you want to change the base?
Conversation
3f48dad
to
5c5f7f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! The code shows significant improvements in both functionality and structure 🚀
The code is ready to merge as is, but feel free to implement my suggestions before or after merge.
|
||
const source = map.value.getSource('responses') as GeoJSONSource; | ||
source.getClusterExpansionZoom(cluster.properties.cluster_id, (err, zoom) => { | ||
if (err || zoom == null) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe adding error logging here like this?
if (err || zoom == null) {
console.error('Failed to get cluster expansion zoom:', err);
return;
}
if (!map.value) return; | ||
|
||
const feature = map.value.queryRenderedFeatures({ | ||
layers: ['unclustered-points', 'clusters'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move magic strings to constants:
const LAYER_IDS = {
CLUSTERS: 'clusters',
UNCLUSTERED_POINTS: 'unclustered-points',
SELECTED_RESPONSE: 'selected-response'
} as const;
.map(Number) | ||
.sort(); | ||
|
||
return responses.value.filter((r) => responseNumbers.includes(r.number)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My coding assistant suggests a performance optimization here. Your current implementation has a complexity of O(n) lookup, but you can use Map for O(1) lookups:
const responseMap = new Map(responses.value.map(r => [r.number, r]));
const selectedResponses = responseNumbers.map(n => responseMap.get(n)).filter(Boolean);
This PR adds the ability to see clusters of responses on the Atlas. Previously if multiple responses were too close together you could only see one of them.
This feature respects the Atlas max zoom setting which allows admins to control the maximum "declustering" zoom point. Previously it was hard coded that all clusters disappeared at a certain zoom level because you could only see responses on their own, not in a cluster.