@@ -7,6 +7,40 @@ import {
77import "./wrapper.css" ;
88export default function Wrapper ( ) {
99 const [ isReadOnly , setIsReadOnly ] = useState ( false ) ;
10+ const [ isEvalscriptSelected , setIsEvalscriptSelected ] = useState ( true ) ;
11+ const [ processGraph ] = useState ( {
12+ load2 : {
13+ process_id : "load_collection" ,
14+ arguments : {
15+ id : "sentinel-2-l2a" ,
16+ spatial_extent : { } ,
17+ temporal_extent : [ "2022-03-26T00:00:00Z" , "2022-03-26T23:59:59Z" ] ,
18+ bands : [ "B08" , "B04" , "B03" ] ,
19+ resampling : "BICUBIC" ,
20+ } ,
21+ } ,
22+ highlight : {
23+ process_id : "highlight_compression" ,
24+ arguments : {
25+ data : {
26+ from_node : "load2" ,
27+ } ,
28+ maxInput : 0.4 ,
29+ clipInput : 0.8 ,
30+ maxOutput : 1 ,
31+ } ,
32+ } ,
33+ save5 : {
34+ process_id : "save_result" ,
35+ arguments : {
36+ format : "PNG" ,
37+ data : {
38+ from_node : "highlight" ,
39+ } ,
40+ } ,
41+ result : true ,
42+ } ,
43+ } ) ;
1044 const [ evalscript , setEvalscript ] =
1145 useState ( `let ndvi = (B08 - B04) / (B08 + B04);
1246
@@ -138,36 +172,65 @@ export default function Wrapper() {
138172 return (
139173 < div
140174 style = { {
141- height : "200vh " ,
175+ height : "100vh " ,
142176 display : "flex" ,
143- alignItems : "center " ,
144- width : 400 ,
177+ alignItems : "flex-start " ,
178+ width : 600 ,
145179 background : "black" ,
146180 } }
147181 className = "panel"
148182 >
149- < textarea name = "" id = "" value = "asd" cols = "30" rows = "10" > </ textarea >
150- < div style = { { height : 400 } } >
151- < CodeEditor
152- themeLight = { themeEoBrowserLight }
153- themeDark = { themeEoBrowserDark }
154- value = { evalscript }
155- onChange = { ( code ) => setEvalscript ( code ) }
156- editorTheme = "dark"
157- portalId = "root"
158- onRunEvalscriptClick = { ( ) => console . log ( "running function from shortcut! Ctrl+Enter" ) }
159- runEvalscriptOnShortcut
160- isReadOnly = { isReadOnly }
161- readOnlyMessage = { `Editor is in read only mode. Untick "Load script from URL" to enable it again.` }
162- />
183+ { /* <textarea name="" id="" value="asd" cols="30" rows="10"></textarea> */ }
184+ < div style = { { height : "60vh" } } >
163185 < h1 style = { { color : "white" } } >
164- Wrapper to simulate parent div in apps like EOB and RB
186+ Wrapper to simulate parent div in apps like EOB and CB
165187 </ h1 >
166188
167189 < button onClick = { ( ) => setIsReadOnly ( ( prev ) => ! prev ) } >
168190 Toggle read only
169191 </ button >
170192 < button onClick = { ( ) => updateCode ( ) } > Inject Evalscript</ button >
193+ < button onClick = { ( ) => setIsEvalscriptSelected ( ! isEvalscriptSelected ) } >
194+ Switch between JSON and Evalscript
195+ </ button >
196+ { isEvalscriptSelected ? (
197+ < CodeEditor
198+ themeLight = { themeEoBrowserLight }
199+ themeDark = { themeEoBrowserDark }
200+ value = { evalscript }
201+ isReadOnly = { isReadOnly }
202+ isEditable = { true }
203+ language = "javascript"
204+ editorTheme = "dark"
205+ portalId = "root"
206+ onChange = { ( code ) => {
207+ try {
208+ JSON . parse ( code ) ;
209+ } catch ( error ) {
210+ if ( isEvalscriptSelected ) {
211+ setEvalscript ( code ) ;
212+ }
213+ }
214+ } }
215+ onRunEvalscriptClick = { ( ) =>
216+ console . log ( "running function from shortcut! Ctrl+Enter" )
217+ }
218+ runEvalscriptOnShortcut
219+ readOnlyMessage = { `Editor is in read only mode. Untick "Load script from URL" to enable it again.` }
220+ />
221+ ) : (
222+ < CodeEditor
223+ themeLight = { themeEoBrowserLight }
224+ themeDark = { themeEoBrowserDark }
225+ value = { JSON . stringify ( processGraph , null , "\t" ) }
226+ isReadOnly = { true }
227+ isEditable = { false }
228+ language = "json"
229+ editorTheme = "dark"
230+ portalId = "root"
231+ onChange = { ( ) => { } }
232+ />
233+ ) }
171234 </ div >
172235 </ div >
173236 ) ;
0 commit comments