-
Notifications
You must be signed in to change notification settings - Fork 0
Updates to map UI #4
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
289e02c
Implement coderabbit sugestions. Updated preview card UI
birthrand d14f6e2
Merge remote-tracking branch 'origin/main' into dev
birthrand 0bb0f4d
Adjust map UI overlay controls
birthrand 891b3b2
Implement proper boundary controls
birthrand 0c2223a
Implement offline mode using asyncstorage
birthrand 9e77aa8
Refactor map components to improve country selection handling and enh…
birthrand 12adc6b
Refined map components to improve handling of boundary country presse…
birthrand c21463d
Remove map and navigation debug logging.
birthrand fbc9b74
Enhance map functionality by adding earcut for improved boundary hit …
birthrand 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,199 @@ | ||
| import type { ThreeEvent } from "@react-three/fiber/native"; | ||
| import { useCallback, useEffect, useMemo } from "react"; | ||
| import * as THREE from "three"; | ||
|
|
||
| import type { MapZoomTier } from "@/components/map/world-map-view"; | ||
| import { buildGlobeBoundaryHitTargets } from "@/lib/globe-boundary-fills"; | ||
| import { logGlobeTap } from "@/lib/globe-tap-debug"; | ||
| import { | ||
| countryNamesMatch, | ||
| filterBoundaryPolygonsByMapContext, | ||
| getCountryBoundaryPolygons, | ||
| } from "@/lib/map-country-boundaries"; | ||
| import { areRegionBoundariesTappable } from "@/lib/map-signal-sources"; | ||
| import { useMapUiStore } from "@/store/use-map-ui-store"; | ||
| import type { MapCountry } from "@/types/country"; | ||
|
|
||
| const countriesGeoJson = require("@/assets/geo/ne_50m_admin_0_countries/ne_50m_admin_0_countries.json"); | ||
|
|
||
| type GlobeBoundaryHitTargetsProps = { | ||
| boundaryCountries: MapCountry[]; | ||
| selectedName: string | null; | ||
| focusedRegion: string | null; | ||
| boundaryFocusRegion?: string | null; | ||
| zoomTier: MapZoomTier; | ||
| onBoundaryCountryPress: (country: MapCountry) => void; | ||
| /** Skip taps that exceeded the orbit drag threshold. */ | ||
| consumeTapThresholdExceeded: () => boolean; | ||
| /** Reset drag guard when R3F sees a new pointer down. */ | ||
| beginPointerTap: () => void; | ||
| }; | ||
|
|
||
| function BoundaryHitMesh({ | ||
| geometry, | ||
| onPress, | ||
| beginPointerTap, | ||
| }: { | ||
| geometry: THREE.BufferGeometry; | ||
| onPress: () => void; | ||
| beginPointerTap: () => void; | ||
| }) { | ||
| useEffect(() => { | ||
| return () => geometry.dispose(); | ||
| }, [geometry]); | ||
|
|
||
| const handlePointerDown = useCallback(() => { | ||
| beginPointerTap(); | ||
| }, [beginPointerTap]); | ||
|
|
||
| const handlePress = useCallback( | ||
| (event: ThreeEvent<MouseEvent>) => { | ||
| event.stopPropagation(); | ||
| onPress(); | ||
| }, | ||
| [onPress], | ||
| ); | ||
|
|
||
| return ( | ||
| <mesh | ||
| geometry={geometry} | ||
| onPointerDown={handlePointerDown} | ||
| onPointerUp={handlePress} | ||
| > | ||
| <meshBasicMaterial | ||
| transparent | ||
| opacity={0} | ||
| depthWrite={false} | ||
| side={THREE.DoubleSide} | ||
| /> | ||
| </mesh> | ||
| ); | ||
| } | ||
|
|
||
| export function GlobeBoundaryHitTargets({ | ||
| boundaryCountries, | ||
| selectedName, | ||
| focusedRegion, | ||
| boundaryFocusRegion = focusedRegion, | ||
| zoomTier, | ||
| onBoundaryCountryPress, | ||
| consumeTapThresholdExceeded, | ||
| beginPointerTap, | ||
| }: GlobeBoundaryHitTargetsProps) { | ||
| const showBoundaryLines = useMapUiStore((s) => s.showBoundaryLines); | ||
| const boundaryStyle = useMapUiStore((s) => s.boundaryStyle); | ||
|
|
||
| const highlightCountryName = selectedName; | ||
| const showCountryHighlight = | ||
| !!highlightCountryName && boundaryStyle.countryHighlightEnabled; | ||
| const boundariesTappable = areRegionBoundariesTappable( | ||
| boundaryFocusRegion, | ||
| zoomTier, | ||
| { allowWorldZoomGlobe: true }, | ||
| ); | ||
| const showBoundaryStrokes = | ||
| boundaryStyle.strokeColorEnabled && showBoundaryLines; | ||
| const showWorldBoundaries = | ||
| showBoundaryLines && !boundaryFocusRegion && !highlightCountryName; | ||
|
|
||
| const countryBoundaries = useMemo(() => { | ||
| const all = getCountryBoundaryPolygons(countriesGeoJson); | ||
| return filterBoundaryPolygonsByMapContext(all, { | ||
| selectedCountryName: highlightCountryName, | ||
| focusedRegion: boundaryFocusRegion, | ||
| countries: boundaryCountries, | ||
| showWorldBoundaries, | ||
| }); | ||
| }, [ | ||
| boundaryCountries, | ||
| boundaryFocusRegion, | ||
| highlightCountryName, | ||
| showWorldBoundaries, | ||
| ]); | ||
|
|
||
| const hitTargets = useMemo( | ||
| () => buildGlobeBoundaryHitTargets(countryBoundaries), | ||
| [countryBoundaries], | ||
| ); | ||
|
|
||
| const handleBoundaryPress = useCallback( | ||
| (countryName: string | null) => { | ||
| if (consumeTapThresholdExceeded()) { | ||
| logGlobeTap({ | ||
| source: "boundary-mesh", | ||
| stage: "skip", | ||
| outcome: "ignored-drag-threshold", | ||
| country: countryName, | ||
| }); | ||
| return; | ||
| } | ||
| if (!countryName) { | ||
| logGlobeTap({ | ||
| source: "boundary-mesh", | ||
| stage: "skip", | ||
| outcome: "missing-country-name", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const country = | ||
| boundaryCountries.find((entry) => | ||
| countryNamesMatch(entry.name, countryName), | ||
| ) ?? null; | ||
| if (country) { | ||
| logGlobeTap({ | ||
| source: "boundary-mesh", | ||
| stage: "input", | ||
| outcome: "boundary-mesh-hit", | ||
| country: country.name, | ||
| region: country.region, | ||
| focusedRegion, | ||
| boundaryFocusRegion, | ||
| cameraTier: zoomTier, | ||
| }); | ||
| onBoundaryCountryPress(country); | ||
| return; | ||
| } | ||
|
|
||
| logGlobeTap({ | ||
| source: "boundary-mesh", | ||
| stage: "skip", | ||
| outcome: "country-not-in-list", | ||
| country: countryName, | ||
| focusedRegion, | ||
| boundaryFocusRegion, | ||
| cameraTier: zoomTier, | ||
| }); | ||
| }, | ||
| [ | ||
| boundaryCountries, | ||
| boundaryFocusRegion, | ||
| consumeTapThresholdExceeded, | ||
| focusedRegion, | ||
| onBoundaryCountryPress, | ||
| zoomTier, | ||
| ], | ||
| ); | ||
|
|
||
| if ( | ||
| !boundariesTappable || | ||
| !showBoundaryStrokes || | ||
| showCountryHighlight || | ||
| hitTargets.length === 0 | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <group> | ||
| {hitTargets.map((target) => ( | ||
| <BoundaryHitMesh | ||
| key={target.id} | ||
| geometry={target.geometry} | ||
| onPress={() => handleBoundaryPress(target.countryName)} | ||
| beginPointerTap={beginPointerTap} | ||
| /> | ||
| ))} | ||
| </group> | ||
| ); | ||
| } |
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
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.