-
-
Notifications
You must be signed in to change notification settings - Fork 928
fix: GeoJSON export #1283
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
Merged
Merged
fix: GeoJSON export #1283
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| name: Unit Tests | ||
| on: | ||
| pull_request: | ||
| branches: [ master ] | ||
| jobs: | ||
| test: | ||
| timeout-minutes: 60 | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - uses: actions/setup-node@v5 | ||
| with: | ||
| node-version: '24' | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| - name: Run Unit tests | ||
| run: npm run test |
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,97 @@ | ||
| import { expect, describe, it } from 'vitest' | ||
| import { getLongitude, getLatitude, getCoordinates } from './commonUtils' | ||
|
|
||
| describe('getLongitude', () => { | ||
| const mapCoordinates = { lonW: -10, lonT: 20 }; | ||
| const graphWidth = 1000; | ||
|
|
||
| it('should calculate longitude at the left edge (x=0)', () => { | ||
| expect(getLongitude(0, mapCoordinates, graphWidth, 2)).toBe(-10); | ||
| }); | ||
|
|
||
| it('should calculate longitude at the right edge (x=graphWidth)', () => { | ||
| expect(getLongitude(1000, mapCoordinates, graphWidth, 2)).toBe(10); | ||
| }); | ||
|
|
||
| it('should calculate longitude at the center (x=graphWidth/2)', () => { | ||
| expect(getLongitude(500, mapCoordinates, graphWidth, 2)).toBe(0); | ||
| }); | ||
|
|
||
| it('should respect decimal precision', () => { | ||
| // 333/1000 * 20 = 6.66, -10 + 6.66 = -3.34 | ||
| expect(getLongitude(333, mapCoordinates, graphWidth, 4)).toBe(-3.34); | ||
| }); | ||
|
|
||
| it('should handle different map coordinate ranges', () => { | ||
| const wideMap = { lonW: -180, lonT: 360 }; | ||
| expect(getLongitude(500, wideMap, graphWidth, 2)).toBe(0); | ||
| expect(getLongitude(0, wideMap, graphWidth, 2)).toBe(-180); | ||
| expect(getLongitude(1000, wideMap, graphWidth, 2)).toBe(180); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getLatitude', () => { | ||
| const mapCoordinates = { latN: 60, latT: 40 }; | ||
| const graphHeight = 800; | ||
|
|
||
| it('should calculate latitude at the top edge (y=0)', () => { | ||
| expect(getLatitude(0, mapCoordinates, graphHeight, 2)).toBe(60); | ||
| }); | ||
|
|
||
| it('should calculate latitude at the bottom edge (y=graphHeight)', () => { | ||
| expect(getLatitude(800, mapCoordinates, graphHeight, 2)).toBe(20); | ||
| }); | ||
|
|
||
| it('should calculate latitude at the center (y=graphHeight/2)', () => { | ||
| expect(getLatitude(400, mapCoordinates, graphHeight, 2)).toBe(40); | ||
| }); | ||
|
|
||
| it('should respect decimal precision', () => { | ||
| // 60 - (333/800 * 40) = 60 - 16.65 = 43.35 | ||
| expect(getLatitude(333, mapCoordinates, graphHeight, 4)).toBe(43.35); | ||
| }); | ||
|
|
||
| it('should handle equator-centered maps', () => { | ||
| const equatorMap = { latN: 45, latT: 90 }; | ||
| expect(getLatitude(400, equatorMap, graphHeight, 2)).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getCoordinates', () => { | ||
| const mapCoordinates = { lonW: -10, lonT: 20, latN: 60, latT: 40 }; | ||
| const graphWidth = 1000; | ||
| const graphHeight = 800; | ||
|
|
||
| it('should return [longitude, latitude] tuple', () => { | ||
| const result = getCoordinates(500, 400, mapCoordinates, graphWidth, graphHeight, 2); | ||
| expect(result).toEqual([0, 40]); | ||
| }); | ||
|
|
||
| it('should calculate coordinates at top-left corner', () => { | ||
| const result = getCoordinates(0, 0, mapCoordinates, graphWidth, graphHeight, 2); | ||
| expect(result).toEqual([-10, 60]); | ||
| }); | ||
|
|
||
| it('should calculate coordinates at bottom-right corner', () => { | ||
| const result = getCoordinates(1000, 800, mapCoordinates, graphWidth, graphHeight, 2); | ||
| expect(result).toEqual([10, 20]); | ||
| }); | ||
|
|
||
| it('should respect decimal precision for both coordinates', () => { | ||
| const result = getCoordinates(333, 333, mapCoordinates, graphWidth, graphHeight, 4); | ||
| expect(result[0]).toBe(-3.34); // longitude | ||
| expect(result[1]).toBe(43.35); // latitude | ||
| }); | ||
|
|
||
| it('should use default precision of 2 decimals', () => { | ||
| const result = getCoordinates(333, 333, mapCoordinates, graphWidth, graphHeight); | ||
| expect(result[0]).toBe(-3.34); | ||
| expect(result[1]).toBe(43.35); | ||
| }); | ||
|
|
||
| it('should handle global map coordinates', () => { | ||
| const globalMap = { lonW: -180, lonT: 360, latN: 90, latT: 180 }; | ||
| const result = getCoordinates(500, 400, globalMap, graphWidth, graphHeight, 2); | ||
| expect(result).toEqual([0, 0]); // center of the world | ||
| }); | ||
| }); |
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
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.