Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
- run server fn at dragend
- double check cells that contain the circle entirely
- promise.allSettled
  • Loading branch information
TurtIeSocks committed Mar 19, 2023
1 parent c8b26e9 commit f3a66f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
5 changes: 4 additions & 1 deletion client/src/pages/map/markers/Point.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ export function KojiPoint({
}
})
circle.removeEventListener('pm:dragend')
circle.on('pm:dragend', function dragend({ layer }) {
circle.on('pm:dragend', async function dragend({ layer }) {
if (layer instanceof L.Circle) {
const { lat: newLat, lng: newLon } = circle.getLatLng()
useShapes.getState().setters.update(type, id, {
...useShapes.getState().Point[id],
geometry: { type: 'Point', coordinates: [newLon, newLat] },
})
useShapes.setState({
s2cellCoverage: await s2Coverage(id, newLat, newLon),
})
}
})
if (usePersist.getState().setActiveMode === 'hover') {
Expand Down
8 changes: 2 additions & 6 deletions client/src/services/fetches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,13 @@ export async function s2Coverage(id: Feature['id'], lat: number, lon: number) {
([, v]) => v !== id.toString(),
),
)
const aborts = s2cells.map(() => new AbortController())
await Promise.all(
s2cells.map(async (level, i) =>
await Promise.allSettled(
s2cells.map(async (level) =>
fetchWrapper<KojiResponse<string[]>>('/api/v1/s2/circle-coverage', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
signal: aborts[i].signal,
body: JSON.stringify({ lat, lon, radius, level }),
}).then((res) => {
if (res) {
Expand All @@ -444,8 +442,6 @@ export async function s2Coverage(id: Feature['id'], lat: number, lon: number) {
}),
),
)
aborts.forEach((a) => a.abort())

return s2cellCoverage
}
return {}
Expand Down
1 change: 1 addition & 0 deletions server/algorithms/src/s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn check_neighbors(
) {
let center = s2::latlng::LatLng::from_degrees(lat, lon);
let center_cell = CellID::from(center).parent(level as u64);
covered.lock().unwrap().insert(center_cell.0.to_string());
let mut next_neighbors: Vec<(f64, f64)> = Vec::new();
let current_neighbors = center_cell.edge_neighbors();

Expand Down

0 comments on commit f3a66f6

Please sign in to comment.