@@ -3,7 +3,7 @@ import {createRoot} from 'react-dom/client';
33import 'maplibre-gl/dist/maplibre-gl.css' ;
44import { Map } from 'react-map-gl/maplibre' ;
55import { ScatterplotLayer , ArcLayer , LineLayer } from '@deck.gl/layers' ;
6- import { lonLatToCell , cellToBoundary } from 'a5' ;
6+ import { lonLatToCell , cellToBoundary , cellToChildren , cellToParent } from 'a5' ;
77import DeckGL from '@deck.gl/react' ;
88import { MapView } from '@deck.gl/core' ;
99
@@ -19,6 +19,8 @@ const A5GREEN_DARK = [0, 128, 64] as [number, number, number];
1919const App : React . FC < { showCellId ?: boolean } > = ( { showCellId = true } ) => {
2020 const [ viewState , setViewState ] = useState ( INITIAL_VIEW_STATE ) ;
2121 const [ cellLocation , setCellLocation ] = useState ( [ INITIAL_VIEW_STATE . longitude , INITIAL_VIEW_STATE . latitude ] ) ;
22+ const [ showChildren , setShowChildren ] = useState ( false ) ;
23+ const [ showParent , setShowParent ] = useState ( false ) ;
2224
2325 const onViewStateChange = useCallback ( ( { viewState} ) => {
2426 const [ longitude , latitude ] = cellLocation ;
@@ -38,8 +40,10 @@ const App: React.FC<{showCellId?: boolean}> = ({showCellId = true}) => {
3840 // Memoize the entire cells calculation
3941 const data = useMemo ( ( ) => {
4042 const cellId = lonLatToCell ( cellLocation , resolution ) ;
41- return { cellId, children : [ cellId ] } ;
42- } , [ resolution , cellLocation ] ) ;
43+ const children = showChildren ? cellToChildren ( cellId ) : [ ] ;
44+ const parent = showParent ? cellToParent ( cellId ) : null ;
45+ return { cellId, children : [ cellId , ...children , ...( parent ? [ parent ] : [ ] ) ] } ;
46+ } , [ resolution , cellLocation , showChildren , showParent ] ) ;
4347
4448 // Convert cell boundaries to great circle arcs
4549 const arcs = useMemo ( ( ) => {
@@ -54,14 +58,18 @@ const App: React.FC<{showCellId?: boolean}> = ({showCellId = true}) => {
5458 } ) . flat ( ) ;
5559 } , [ data . children ] ) ;
5660
61+ const getColor = ( _ , info ) => {
62+ return info . index < 5 ? A5GREEN : [ 160 , 160 , 160 , 255 ] ;
63+ }
64+
5765 const polygonProps : any = {
5866 data : arcs ,
5967 getSourcePosition : d => d . source ,
6068 getTargetPosition : d => d . target ,
61- getSourceColor : A5GREEN ,
62- getTargetColor : A5GREEN ,
63- getColor : A5GREEN ,
64- getWidth : 2 ,
69+ getSourceColor : getColor ,
70+ getTargetColor : getColor ,
71+ getColor : getColor ,
72+ getWidth : ( _ , info ) => info . index < 5 ? 2 : 1 ,
6573 getHeight : 0 ,
6674 greatCircle : true ,
6775 widthUnits : 'pixels'
@@ -154,6 +162,24 @@ const App: React.FC<{showCellId?: boolean}> = ({showCellId = true}) => {
154162 < div > Cell ID (Hex): { `0x${ data . cellId . toString ( 16 ) . padStart ( 16 , '0' ) } ` } </ div >
155163 < div > Resolution: { resolution } </ div >
156164 < div > Location: [{ cellLocation [ 0 ] . toFixed ( 4 ) } , { cellLocation [ 1 ] . toFixed ( 4 ) } ]</ div >
165+ < div style = { { marginTop : '10px' } } >
166+ < label style = { { marginRight : '15px' } } >
167+ < input
168+ type = "checkbox"
169+ checked = { showChildren }
170+ onChange = { ( e ) => setShowChildren ( e . target . checked ) }
171+ />
172+ Show children
173+ </ label >
174+ < label >
175+ < input
176+ type = "checkbox"
177+ checked = { showParent }
178+ onChange = { ( e ) => setShowParent ( e . target . checked ) }
179+ />
180+ Show parent
181+ </ label >
182+ </ div >
157183 </ div >
158184 ) }
159185 </ >
0 commit comments