1- import React from 'react' ;
1+ import React , { useEffect } from 'react' ;
22import { useState } from 'react' ;
33import MlNavigationTools , { MlNavigationToolsProps } from './MlNavigationTools' ;
44import noNavToolsDecorator from '../../decorators/NoNavToolsDecorator' ;
@@ -9,6 +9,7 @@ import FormGroup from '@mui/material/FormGroup';
99import FormControlLabel from '@mui/material/FormControlLabel' ;
1010import Sidebar from '../../ui_components/Sidebar' ;
1111import TopToolbar from '../../ui_components/TopToolbar' ;
12+ import useMap from '../../hooks/useMap' ;
1213
1314const storyoptions = {
1415 title : 'MapComponents/MlNavigationTools' ,
@@ -25,34 +26,35 @@ export default storyoptions;
2526const Template = ( props : MlNavigationToolsProps ) => < MlNavigationTools { ...props } /> ;
2627
2728const catalogueTemplate = ( ) => {
29+ const mapHook = useMap ( ) ;
2830 const [ openSidebar , setOpenSidebar ] = useState ( true ) ;
29- const [ ThreeDButton , setThreeDButton ] = useState ( false ) ;
30- const [ CenterLocationButton , setCenterLocationButton ] = useState ( false ) ;
31- const [ ZoomButtons , setZoomButtons ] = useState ( true ) ;
32- const [ FollowGpsButton , setFollowGpsButton ] = useState ( false ) ;
33- const [ showCustomButton , setShowCustomButton ] = useState < boolean > ( false ) ;
31+ const [ threeDButton , setThreeDButton ] = useState ( false ) ;
32+ const [ globeButton , setGlobeButton ] = useState ( false ) ;
33+ const [ centerLocationButton , setCenterLocationButton ] = useState ( false ) ;
34+ const [ zoomButtons , setZoomButtons ] = useState ( true ) ;
35+ const [ followGpsButton , setFollowGpsButton ] = useState ( false ) ;
36+ const [ showCustomButton , setShowCustomButton ] = useState ( false ) ;
3437 const [ alternativePosition , setAlternativePosition ] = useState ( false ) ;
3538
36- const handleChange1 = ( ) => {
37- setThreeDButton ( ! ThreeDButton ) ;
38- } ;
39- const handleChange2 = ( ) => {
40- setCenterLocationButton ( ! CenterLocationButton ) ;
41- } ;
42- const handleChange3 = ( ) => {
43- setZoomButtons ( ! ZoomButtons ) ;
44- } ;
45- const handleChange4 = ( ) => {
46- setFollowGpsButton ( ! FollowGpsButton ) ;
47- } ;
48-
49- const handleCustomButtonChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
50- setShowCustomButton ( event . target . checked ) ;
51- } ;
52-
53- const handleAlternativePositionChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
54- setAlternativePosition ( event . target . checked ) ;
55- } ;
39+ const tools = [
40+ { text : 'Alternative Position' , const : alternativePosition , setter : setAlternativePosition } ,
41+ { text : 'Show 2D/3D Button' , const : threeDButton , setter : setThreeDButton } ,
42+ { text : 'Show Globe Button' , const : globeButton , setter : setGlobeButton } ,
43+ {
44+ text : 'Show CenterLocation Button' ,
45+ const : centerLocationButton ,
46+ setter : setCenterLocationButton ,
47+ } ,
48+ { text : 'Show Zoom Buttons' , const : zoomButtons , setter : setZoomButtons } ,
49+ { text : 'Show FollowGPS Button' , const : followGpsButton , setter : setFollowGpsButton } ,
50+ { text : 'Add a custom Button' , const : showCustomButton , setter : setShowCustomButton } ,
51+ ] ;
52+
53+ useEffect ( ( ) => {
54+ if ( globeButton && mapHook . map ) {
55+ mapHook . map . easeTo ( { zoom : 2 } ) ;
56+ }
57+ } , [ globeButton , mapHook . map ] ) ;
5658
5759 return (
5860 < >
@@ -71,40 +73,24 @@ const catalogueTemplate = () => {
7173 />
7274 < Sidebar open = { openSidebar } setOpen = { setOpenSidebar } name = { 'Navigation Tools' } >
7375 < FormGroup >
74- < FormControlLabel
75- control = {
76- < Switch checked = { alternativePosition } onChange = { handleAlternativePositionChange } />
77- }
78- label = "Alternative Position"
79- />
80- < FormControlLabel
81- control = { < Switch checked = { ThreeDButton } onChange = { handleChange1 } /> }
82- label = "Show 2D/3D Button"
83- />
84- < FormControlLabel
85- control = { < Switch checked = { CenterLocationButton } onChange = { handleChange2 } /> }
86- label = "Show CenterLocation Button"
87- />
88- < FormControlLabel
89- control = { < Switch checked = { ZoomButtons } onChange = { handleChange3 } /> }
90- label = "Show Zoom Buttons"
91- />
92- < FormControlLabel
93- control = { < Switch checked = { FollowGpsButton } onChange = { handleChange4 } /> }
94- label = "Show FollowGPS Button"
95- />
96- < FormControlLabel
97- control = { < Switch checked = { showCustomButton } onChange = { handleCustomButtonChange } /> }
98- label = "Add a custom Button"
99- />
76+ { tools . map ( ( tool , text ) => (
77+ < FormControlLabel
78+ key = { text }
79+ control = {
80+ < Switch checked = { tool . const } onChange = { ( ) => tool . setter ( ( current ) => ! current ) } />
81+ }
82+ label = { tool . text }
83+ />
84+ ) ) }
10085 </ FormGroup >
10186 </ Sidebar >
10287 < MlNavigationTools
10388 sx = { alternativePosition ? { top : '80px' } : undefined }
104- show3DButton = { ThreeDButton }
105- showCenterLocationButton = { CenterLocationButton }
106- showZoomButtons = { ZoomButtons }
107- showFollowGpsButton = { FollowGpsButton }
89+ show3DButton = { threeDButton }
90+ showGlobeButton = { globeButton }
91+ showCenterLocationButton = { centerLocationButton }
92+ showZoomButtons = { zoomButtons }
93+ showFollowGpsButton = { followGpsButton }
10894 >
10995 { showCustomButton ? (
11096 < Button
@@ -132,6 +118,12 @@ No3dButton.args = {
132118 show3DButton : false ,
133119} ;
134120
121+ export const ShowGlobeButton = Template . bind ( { } ) ;
122+ ShowGlobeButton . parameters = { } ;
123+ ShowGlobeButton . args = {
124+ showGlobeButton : true ,
125+ } ;
126+
135127export const ShowCenterLocationButton = Template . bind ( { } ) ;
136128ShowCenterLocationButton . parameters = { } ;
137129ShowCenterLocationButton . args = {
0 commit comments