Repository navigation
feat: add auto-zoom minimap to play region map setting #21
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
Open
Puupuls
wants to merge
4
commits into
sourcelocation:master
Choose a base branch
from
Puupuls:feat/auto-zoom-minimap-play-region
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
565a8d1
feat: add auto-zoom minimap to play region map setting
Puupuls 10027ea
test: cover auto-zoom play-region bounds derivation
Puupuls 75ba20d
fix: coderabbit reccomendations
Puupuls 6bfe6f4
Merge remote-tracking branch 'origin/main' into feat/auto-zoom-minima…
Puupuls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { playRegionCorners } from './guess-map-bounds'; | ||
|
|
||
| describe('playRegionCorners', () => { | ||
| it('passes through a non-crossing region unchanged', () => { | ||
| expect(playRegionCorners({ minLat: 10, maxLat: 20, minLng: 30, maxLng: 40 })).toEqual([ | ||
| [10, 30], | ||
| [20, 40], | ||
| ]); | ||
| }); | ||
|
|
||
| it('unwraps the eastern edge for an antimeridian-crossing region', () => { | ||
| // Region runs east from +177 to -178, i.e. a narrow 5-degree band. | ||
| expect(playRegionCorners({ minLat: -18, maxLat: -17, minLng: 177, maxLng: -178 })).toEqual([ | ||
| [-18, 177], | ||
| [-17, 182], | ||
| ]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| export type PlayRegionBounds = { | ||
| minLat: number; | ||
| maxLat: number; | ||
| minLng: number; | ||
| maxLng: number; | ||
| }; | ||
|
|
||
| /** | ||
| * Converts stored play-region bounds into Leaflet corners. | ||
| * | ||
| * Longitude bounds follow the shortest-circular-interval convention: the region | ||
| * runs eastward from `minLng` to `maxLng`, and `maxLng < minLng` signals that it | ||
| * crosses the antimeridian. In that case the eastern edge is unwrapped past | ||
| * +180 so Leaflet frames the narrow region instead of the whole globe. | ||
| */ | ||
| export function playRegionCorners(bounds: PlayRegionBounds): [[number, number], [number, number]] { | ||
| const east = bounds.maxLng < bounds.minLng ? bounds.maxLng + 360 : bounds.maxLng; | ||
| return [ | ||
| [bounds.minLat, bounds.minLng], | ||
| [bounds.maxLat, east], | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| alter table maps drop column if exists auto_zoom_play_region; | ||
| alter table maps drop column if exists bounds_min_lat_e7; | ||
| alter table maps drop column if exists bounds_max_lat_e7; | ||
| alter table maps drop column if exists bounds_min_lng_e7; | ||
| alter table maps drop column if exists bounds_max_lng_e7; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| alter table maps add column if not exists auto_zoom_play_region boolean not null default false; | ||
| alter table maps add column if not exists bounds_min_lat_e7 integer; | ||
| alter table maps add column if not exists bounds_max_lat_e7 integer; | ||
| alter table maps add column if not exists bounds_min_lng_e7 integer; | ||
| alter table maps add column if not exists bounds_max_lng_e7 integer; | ||
|
|
||
| -- Latitude bounds are a plain min/max. | ||
| update maps m | ||
| set bounds_min_lat_e7 = b.min_lat, | ||
| bounds_max_lat_e7 = b.max_lat | ||
| from ( | ||
| select map_storage_id, min(lat_e7) as min_lat, max(lat_e7) as max_lat | ||
| from locations | ||
| group by map_storage_id | ||
| ) b | ||
| where b.map_storage_id = m.storage_id; | ||
|
|
||
| -- Longitude bounds use the shortest circular interval (the complement of the | ||
| -- largest empty gap between adjacent longitudes) so antimeridian-crossing maps | ||
| -- produce a narrow region. Stored as [min_lng_e7, max_lng_e7] traversed east; | ||
| -- min_lng_e7 > max_lng_e7 when the interval crosses the antimeridian. | ||
| with ordered as ( | ||
| select map_storage_id, lng_e7, | ||
| lead(lng_e7) over (partition by map_storage_id order by lng_e7) as next_lng, | ||
| min(lng_e7) over (partition by map_storage_id) as min_lng, | ||
| max(lng_e7) over (partition by map_storage_id) as max_lng | ||
| from (select distinct map_storage_id, lng_e7 from locations) d | ||
| ), | ||
| gaps as ( | ||
| select map_storage_id, (next_lng::bigint - lng_e7) as gap, next_lng as start_lng, lng_e7 as end_lng | ||
| from ordered | ||
| where next_lng is not null | ||
| union all | ||
| select map_storage_id, (min_lng::bigint + 3600000000 - max_lng) as gap, min_lng as start_lng, max_lng as end_lng | ||
| from ordered | ||
| where next_lng is null | ||
| ), | ||
| best as ( | ||
| select distinct on (map_storage_id) map_storage_id, start_lng, end_lng | ||
| from gaps | ||
| order by map_storage_id, gap desc, start_lng | ||
| ) | ||
| update maps m | ||
| set bounds_min_lng_e7 = b.start_lng, | ||
| bounds_max_lng_e7 = b.end_lng | ||
| from best b | ||
| where b.map_storage_id = m.storage_id; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.