11import React , { useState } from 'react' ;
22
33import MlSketchTool from './MlSketchTool' ;
4+ import { Feature } from 'geojson' ;
45
56import mapContextDecorator from '../../decorators/MapContextDecorator' ;
67import Sidebar from '../../ui_components/Sidebar' ;
78import TopToolbar from '../../ui_components/TopToolbar' ;
8- import { Box , Button , Theme , useMediaQuery } from '@mui/material' ;
9+ import { Button , Paper , Typography } from '@mui/material' ;
910
1011const storyoptions = {
1112 title : 'MapComponents/MlSketchTool' ,
@@ -40,33 +41,31 @@ const Template = () => {
4041} ;
4142
4243const catalgoueTemplate = ( ) => {
43- const mediaIsMobile = useMediaQuery ( ( theme : Theme ) => theme . breakpoints . down ( 'lg' ) ) ;
44+ // const mediaIsMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('lg'));
4445
4546 const [ openSidebar , setOpenSidebar ] = useState ( true ) ;
47+ const [ instructionText , setInstructionText ] = useState ( 'Select a sketch tool.' ) ;
48+
49+ const getInstructionText = ( drawMode ?: keyof MapboxDraw . Modes , selectedGeoJson ?: Feature ) => {
50+ if ( drawMode === 'simple_select' && selectedGeoJson ) {
51+ const geoType = selectedGeoJson . geometry . type ;
52+ return `Edit ${ geoType } : Click the geometry to edit.` ;
53+ }
54+
55+ switch ( drawMode ) {
56+ case 'draw_point' :
57+ return 'Click to draw point.' ;
58+ case 'draw_line_string' :
59+ return 'Click to add vertices. Double-click to finish drawing.' ;
60+ case 'draw_polygon' :
61+ return 'Click to add vertices. Double-click to finish drawing.' ;
62+ default :
63+ return 'Select a sketch tool.' ;
64+ }
65+ } ;
66+
4667 return (
4768 < >
48- < Box
49- sx = { {
50- position : 'fixed' ,
51- width : { xs : '100%' , sm : 'auto' } ,
52- top : { xs : '62px' , sm : '22px' } ,
53- right : { xs : '0px' , sm : '180px' } ,
54- paddingRight : { xs : '20px' , sm : '0px' } ,
55- color : '#009ee0' ,
56- backgroundColor : '#fff' ,
57- textAlign : 'right' ,
58- fontSize : '16px' ,
59- fontFamily : 'sans-serif' ,
60- display : 'flex' ,
61- flexDirection : 'column' ,
62- gap : '5px' ,
63- zIndex : 5000 ,
64- } }
65- >
66- { mediaIsMobile
67- ? 'Zum Beenden erneut auf denselben Punkt klicken.'
68- : 'Die Zeichnung kann beendet werden, indem erneut auf den zuletzt gezeichneten Punkt geklickt wird.' }
69- </ Box >
7069 < TopToolbar
7170 buttons = {
7271 < >
@@ -81,8 +80,30 @@ const catalgoueTemplate = () => {
8180 }
8281 />
8382 < Sidebar open = { openSidebar } setOpen = { setOpenSidebar } name = { 'Sketch Tool' } >
84- < MlSketchTool onChange = { ( state ) => console . log ( state ) } />
83+ < MlSketchTool
84+ onChange = { ( state ) => {
85+ const { drawMode, selectedGeoJson } = state ;
86+ setInstructionText ( getInstructionText ( drawMode , selectedGeoJson ) ) ;
87+ } }
88+ />
8589 </ Sidebar >
90+
91+ < Paper
92+ sx = { {
93+ position : 'fixed' ,
94+ bottom : '25px' ,
95+ left : '50%' ,
96+ padding : '10px' ,
97+ zIndex : 101 ,
98+ } }
99+ >
100+ < Typography >
101+ { /* {mediaIsMobile
102+ ? 'Zum Beenden erneut auf denselben Punkt klicken.'
103+ : 'Die Zeichnung kann beendet werden, indem erneut auf den zuletzt gezeichneten Punkt geklickt wird.'} */ }
104+ { instructionText }
105+ </ Typography >
106+ </ Paper >
86107 </ >
87108 ) ;
88109} ;
0 commit comments