-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from aodn/bugs/6008-fix-missing-centroid
Bugs/6008 fix missing centroid
- Loading branch information
Showing
3 changed files
with
108 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
src/components/map/mapbox/layers/__test__/Layers.nomapmock.test.tsx
This file contains 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,42 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { Feature, FeatureCollection, GeoJsonProperties, Point } from "geojson"; | ||
import { findSuitableVisiblePoint, isFeatureVisible } from "../Layers"; | ||
import * as turf from "@turf/turf"; | ||
import { LngLatBounds } from "mapbox-gl"; | ||
|
||
// Define the test where we do not need to mock the Map | ||
describe("Test case where no map mock needed", () => { | ||
it("should return the same feature collection if no map is provided", () => { | ||
const featureCollection: FeatureCollection<Point> = { | ||
type: "FeatureCollection", | ||
features: [], | ||
}; | ||
|
||
const result = findSuitableVisiblePoint(featureCollection, null); | ||
|
||
// Expect the same input to be returned since the map is null | ||
expect(result).toEqual(featureCollection); | ||
}); | ||
|
||
it("verfiy anti-meridian works for isFeatureVisible", () => { | ||
// The point value isn't too important as long as it is below 180 for x | ||
const target: Feature<Point, GeoJsonProperties> = { | ||
type: "Feature", | ||
geometry: { | ||
type: "Point", | ||
coordinates: [158.72, -25.95], | ||
}, | ||
properties: { | ||
name: "Example Point", | ||
description: "This is an example of a GeoJSON Point Feature", | ||
}, | ||
}; | ||
|
||
const bounds: LngLatBounds = new LngLatBounds([ | ||
[-203.62, -43.828], | ||
[-142.79, -8.759], | ||
]); | ||
// We set a LngLat where x is < -180 to create anti-meridian | ||
expect(isFeatureVisible(target, bounds)).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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