Skip to content

Commit bb8cdd1

Browse files
committed
Added "code editor"-like utils for gee scripts.
1 parent bfdeb5a commit bb8cdd1

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

src/utilities/codeEditorUtils.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
Code editor aliases.
3+
print and Export* mirror the functionality in the code editor;
4+
Map, Chart, and ui are ignored (empty skeleton classes)
5+
6+
*with the big caveat that tasks will be automatically submitted.
7+
*/
8+
9+
/*
10+
Prints one or more arguments to the console
11+
using getInfo if allowed.
12+
*/
13+
exports.print = function(...args){
14+
args.forEach((object)=>{
15+
if(object){
16+
if (typeof object === "object"){
17+
if ("getInfo" in object){
18+
console.log(object.getInfo());
19+
}else{
20+
console.log(object);
21+
}
22+
}else{
23+
console.log(object);
24+
}
25+
}
26+
});
27+
};
28+
29+
// eslint-disable-next-line @typescript-eslint/naming-convention
30+
exports.ExportMod = function(Export, errCallback){
31+
/*
32+
TODO: modify the Export class
33+
so that tasks are automatically started.
34+
This is a different behavior than the codeEditor,
35+
where tasks are added to a queue and the user
36+
needs to manually click each one.
37+
This would be difficult to mirror here, and
38+
it would be actually more convenient for
39+
a user to start them automatically.
40+
This will need to be specified in the documentation.
41+
*/
42+
//TODO: modify the Export class
43+
// so that it starts the tasks
44+
// automatically
45+
// For success callback, use a dummy function
46+
// for error callback, alert the user.
47+
//Export.table.toDriveOriginal = Export.table.toDrive;
48+
//Export.table.toDrive = function(...args){
49+
// return Export.table.toDriveOriginal(...args)
50+
// .start(()=>{}, errCallback);
51+
//};
52+
return Export;
53+
};
54+
55+
/*
56+
The rest are defined to be ignored:
57+
*/
58+
class MapConstructor{
59+
/*
60+
Empty Map Class whose functions expect
61+
the same arguments as in the code editor.
62+
*/
63+
constructor(){}
64+
add=function(item){};
65+
addLayer=function(eeObject,visParams,name,shown,opacity){};
66+
centerObject=function(object,zoom,onComplete){};
67+
clear=function(){};
68+
drawingTools=function(){};
69+
getBounds=function(asGeoJSON){};
70+
getCenter=function(){};
71+
getScale=function(){};
72+
getZoom=function(){};
73+
layers=function(){};
74+
onChangeBounds=function(callback){};
75+
onChangeCenter=function(callback){};
76+
onChangeZoom=function(callback){};
77+
onClick=function(callback){};
78+
onIdle=function(callback){};
79+
onTileLoaded=function(callback){};
80+
remove=function(item){};
81+
setCenter=function(lon,lat,zoom){};
82+
setControlVisibility=function(all,layerList,zoomControl,scaleControl,
83+
mapTypeControl,fullscreenControl,drawingToolsControl){};
84+
setGestureHandling=function(option){};
85+
setZoom=function(zoom){};
86+
style=function(){};
87+
unlisten=function(idOrType){};
88+
widgets=function(){};
89+
}
90+
91+
exports.Map = new MapConstructor();
92+
93+
class UIConstructor{
94+
constructor(){}
95+
// TODO
96+
}
97+
exports.ui = new UIConstructor();
98+
99+
class ChartArrayConstructor{
100+
constructor(){}
101+
values=function(array,axis,xLabels){};
102+
}
103+
class ChartFeatureConstructor{
104+
constructor(){}
105+
byFeature=function(features,xProperty,yProperties){};
106+
byProperty=function(features,xProperties,seriesProperty){};
107+
groups=function(features,xProperty,yProperty,seriesProperty){};
108+
histogram=function(features,property,maxBuckets,minBucketWidth,maxRaw){};
109+
}
110+
class ChartImageConstructor{
111+
constructor(){}
112+
byClass=function(image, classBand, region, reducer, scale, classLabels, xLabels){};
113+
byRegion=function(image, regions, reducer, scale, xProperty){};
114+
doySeries=function(imageCollection, region, regionReducer, scale, yearReducer, startDay, endDay){};
115+
doySeriesByRegion=function(imageCollection, bandName, regions, regionReducer, scale,
116+
yearReducer, seriesProperty, startDay, endDay){};
117+
doySeriesByYear=function(imageCollection, bandName, region, regionReducer, scale,
118+
sameDayReducer, startDay, endDay){};
119+
histogram=function(image, region, scale, maxBuckets, minBucketWidth, maxRaw){};
120+
regions=function(image, regions, reducer, scale, seriesProperty, xLabels){};
121+
series=function(imageCollection, region, reducer, scale, xProperty){};
122+
seriesByRegion=function(imageCollection, regions, reducer, band, scale, xProperty, seriesProperty){};
123+
}
124+
class ChartConstructor{
125+
/*
126+
Empty Chart Class whose functions expect
127+
the same arguments as in the code editor.
128+
*/
129+
constructor(){}
130+
array = new ChartArrayConstructor();
131+
feature = new ChartFeatureConstructor();
132+
image = new ChartImageConstructor();
133+
// eslint-disable-next-line @typescript-eslint/naming-convention
134+
Chart=function(dataTable, chartType, options, view){};
135+
setChartType=function(chartType){};
136+
setDataTable=function(dataTable){};
137+
setOptions=function(options){};
138+
setSeriesNames=function(seriesNames, seriesIndex){};
139+
setView=function(view){};
140+
transform=function(transformer){};
141+
}
142+
143+
exports.Chart = new ChartConstructor();

0 commit comments

Comments
 (0)