forked from NASA-AMMOS/MMGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerModal.js
More file actions
445 lines (412 loc) · 13.8 KB
/
Copy pathLayerModal.js
File metadata and controls
445 lines (412 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import React from "react";
import { useSelector, useDispatch } from "react-redux";
import {
getLayerByUUID,
traverseLayers,
insertLayerAfterUUID,
getIn,
setIn,
} from "../../../../../core/utils";
import {
setModal,
setSnackBarText,
setConfiguration,
} from "../../../../../core/ConfigureStore";
import { inject } from "../../../../../core/injectables";
import {
getHiddenFieldsForEngine,
stripHiddenFields,
} from "./layerFieldVisibility";
import Button from "@mui/material/Button";
import Dialog from "@mui/material/Dialog";
import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import Tooltip from "@mui/material/Tooltip";
import IconButton from "@mui/material/IconButton";
import Divider from "@mui/material/Divider";
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
import CloseSharpIcon from "@mui/icons-material/CloseSharp";
import LayersIcon from "@mui/icons-material/Layers";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import { makeStyles, useTheme } from "@mui/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
import Maker from "../../../../../core/Maker";
import dataConfig from "../../../../../metaconfigs/layer-data-config.json";
import headerConfig from "../../../../../metaconfigs/layer-header-config.json";
import modelConfig from "../../../../../metaconfigs/layer-model-config.json";
import queryConfig from "../../../../../metaconfigs/layer-query-config.json";
import tileConfig from "../../../../../metaconfigs/layer-tile-config.json";
import vectorConfig from "../../../../../metaconfigs/layer-vector-config.json";
import vectortileConfig from "../../../../../metaconfigs/layer-vectortile-config.json";
import velocityConfig from "../../../../../metaconfigs/layer-velocity-config.json";
import imageConfig from "../../../../../metaconfigs/layer-image-config.json";
import videoConfig from "../../../../../metaconfigs/layer-video-config.json";
const useStyles = makeStyles((theme) => ({
Modal: {
margin: theme.headHeights[1],
[theme.breakpoints.down("xs")]: {
margin: "6px",
},
"& .MuiDialog-container": {
width: "100%",
transform: "translateX(-50%) translateY(-50%)",
left: "50%",
top: "50%",
position: "absolute",
marginLeft: "111px",
},
},
contents: {
height: "100%",
width: "100%",
maxWidth: "80% !important",
maxHeight: "calc(100% - 32px) !important",
},
heading: {
height: theme.headHeights[2],
boxSizing: "border-box",
background: theme.palette.swatches.p[0],
padding: `4px ${theme.spacing(2)} 4px ${theme.spacing(4)} !important`,
},
title: {
padding: `8px 0px`,
fontSize: theme.typography.pxToRem(16),
fontWeight: "bold",
textTransform: "uppercase",
},
content: {
padding: "0px !important",
height: `calc(100% - ${theme.headHeights[2]}px)`,
overflowY: "auto",
},
closeIcon: {
padding: theme.spacing(1.5),
height: "100%",
margin: "4px 0px",
},
flexBetween: {
display: "flex",
justifyContent: "space-between",
},
subtitle: {
fontSize: "14px !important",
width: "100%",
marginBottom: "8px !important",
color: theme.palette.swatches.grey[300],
letterSpacing: "0.2px",
},
subtitle2: {
fontSize: "12px !important",
fontStyle: "italic",
width: "100%",
marginBottom: "8px !important",
color: theme.palette.swatches.grey[400],
},
missionNameInput: {
width: "100%",
margin: "8px 0px 4px 0px !important",
},
backgroundIcon: {
margin: "7px 8px 0px 0px",
},
dialogActions: {
display: "flex !important",
justifyContent: "space-between !important",
background: `${theme.palette.swatches.grey[150]} !important`,
padding: "8px 14px !important",
},
removeButton: {
background: `${theme.palette.swatches.red[500]} !important`,
color: `${theme.palette.swatches.grey[1000]} !important`,
border: "none !important",
},
uuid: {
color: theme.palette.swatches.grey[600],
fontSize: "14px",
},
actionsRight: {
display: "flex",
},
cloneButton: {
color: `${theme.palette.swatches.grey[900]} !important`,
},
divider: {
borderColor: `${theme.palette.swatches.grey[300]} !important`,
margin: "0px 10px !important",
},
doneButton: {
background: `${theme.palette.swatches.p[0]} !important`,
color: `${theme.palette.swatches.grey[150]} !important`,
border: "none !important",
width: "100px",
},
}));
/**
* Layer types each engine supports for the Layer Type dropdown.
* Mirrors ENGINE_LAYER_SUPPORT in src/essence/Basics/MapEngines/types/engine.ts.
* Structural types are filtered per engine because not all engines support layer
* tree grouping.
*/
const ENGINE_LAYER_SUPPORT = {
leaflet: ["vector", "tile", "vectortile", "data", "image", "video", "velocity"],
deckgl: [
"GeoJsonLayer",
"TileLayer",
"Tile3DLayer",
"PointCloudLayer",
"MVTLayer",
"ScatterplotLayer",
],
};
const ENGINE_STRUCTURAL_LAYER_TYPES = {
leaflet: ["header", "query", "model"],
deckgl: [],
};
/**
* Layer metaconfigs keyed by stored layer type.
*/
const LAYER_TYPE_CONFIGS = {
data: dataConfig,
header: headerConfig,
model: modelConfig,
query: queryConfig,
tile: tileConfig,
vector: vectorConfig,
vectortile: vectortileConfig,
velocity: velocityConfig,
image: imageConfig,
video: videoConfig,
GeoJsonLayer: vectorConfig,
ScatterplotLayer: vectorConfig,
TileLayer: tileConfig,
BitmapLayer: tileConfig,
Tile3DLayer: tileConfig,
PointCloudLayer: tileConfig,
MVTLayer: vectortileConfig,
};
const MODAL_NAME = "layer";
const LayerModal = (props) => {
const c = useStyles();
const modal = useSelector((state) => state.core.modal[MODAL_NAME]);
const configuration = useSelector((state) => state.core.configuration);
const layerUUID = modal && modal.layerUUID ? modal.layerUUID : null;
const layer = getLayerByUUID(configuration.layers, layerUUID) || {};
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
const dispatch = useDispatch();
let config = LAYER_TYPE_CONFIGS[layer.type] || {};
const mapEngine = configuration?.msv?.mapEngine || "leaflet";
config = inject(config);
if (mapEngine !== "leaflet" && ENGINE_LAYER_SUPPORT[mapEngine] && config.tabs) {
const allowedTypes = [
...ENGINE_LAYER_SUPPORT[mapEngine],
...(ENGINE_STRUCTURAL_LAYER_TYPES[mapEngine] ?? []),
];
config = JSON.parse(JSON.stringify(config));
config.tabs.forEach((tab) => {
tab.rows.forEach((row) => {
row.components.forEach((comp) => {
if (comp.field === "type" && comp.type === "dropdown") {
const filtered = comp.options.filter((opt) =>
allowedTypes.includes(opt)
);
ENGINE_LAYER_SUPPORT[mapEngine].forEach((t) => {
if (!filtered.includes(t)) filtered.push(t);
});
comp.options = filtered;
}
});
});
});
}
// Hide engine-specific or deck-only fields for all engines (including leaflet).
config = stripHiddenFields(config, getHiddenFieldsForEngine(mapEngine, layer.type));
const handleClose = (skipSetConfiguration) => {
if (skipSetConfiguration !== true) {
const nextConfiguration = JSON.parse(JSON.stringify(configuration));
traverseLayers(nextConfiguration.layers, (l, path, index) => {
if (layer.uuid === l.uuid) {
// We're repopulating all the layers values to trim it exactly to its spec
// (otherwise defaults may be missing and switching layer types would mix parameters)
let completedLayer = {
uuid: l.uuid,
sublayers: l.sublayers || [],
};
config.tabs.forEach((t) => {
t.rows.forEach((r) => {
r.components.forEach((c) => {
// Skip non-field components (such as the map)
if (c.field == null) return;
const currentValue = getIn(l, c.field.split("."), null);
if (currentValue != null)
setIn(completedLayer, c.field.split("."), currentValue, true);
if (c.type === "dropdown" || c.type === "colordropdown") {
const currentValue = getIn(l, c.field);
if (currentValue == null) {
setIn(
completedLayer,
c.field.split("."),
c.options[0],
true
);
}
} else if (c.type === "checkbox" || c.type === "switch") {
const currentValue = getIn(l, c.field);
if (currentValue == null && c.defaultChecked != null) {
setIn(
completedLayer,
c.field.split("."),
c.defaultChecked,
true
);
}
} else if (c.type === "slider") {
const currentValue = getIn(l, c.field);
if (currentValue == null && c.default != null) {
setIn(
completedLayer,
c.field.split("."),
c.default || c.min || 0,
true
);
}
} else if (c.type === "colorpicker") {
const currentValue = getIn(l, c.field);
if (currentValue == null) {
setIn(
completedLayer,
c.field.split("."),
c.default || "#FFFFFF",
true
);
}
}
});
});
});
// Clear and copy while maintaining reference
Object.keys(l).forEach((key) => {
delete l[key];
});
// Setting these here just so that the show up first in the object
l.name = completedLayer.name;
l.uuid = completedLayer.uuid;
Object.keys(completedLayer).forEach((key) => {
l[key] = completedLayer[key];
});
}
});
dispatch(setConfiguration(nextConfiguration));
}
// close modal
dispatch(setModal({ name: MODAL_NAME, on: false }));
};
return (
<Dialog
className={c.Modal}
fullScreen={isMobile}
open={modal !== false}
onClose={handleClose}
aria-labelledby="responsive-dialog-title"
PaperProps={{
className: c.contents,
}}
>
<DialogTitle className={c.heading}>
<div className={c.flexBetween}>
<div className={c.flexBetween}>
<LayersIcon className={c.backgroundIcon} />
<div className={c.title}>{layer.name}</div>
</div>
<IconButton
className={c.closeIcon}
title="Close"
aria-label="close"
onClick={handleClose}
>
<CloseSharpIcon fontSize="inherit" />
</IconButton>
</div>
</DialogTitle>
<DialogContent className={c.content}>
<Maker config={config} layer={layer} inlineHelp={true} />
</DialogContent>
<DialogActions className={c.dialogActions}>
<div>
<Button
className={c.removeButton}
variant="outlined"
startIcon={<DeleteForeverIcon size="small" />}
onClick={() => {
const nextConfiguration = JSON.parse(
JSON.stringify(configuration)
);
traverseLayers(nextConfiguration.layers, (l, path, index) => {
if (layer.uuid === l.uuid) {
return "remove";
}
});
dispatch(setConfiguration(nextConfiguration));
dispatch(
setSnackBarText({
text: `Removed '${layer.name}'.`,
severity: "success",
})
);
handleClose(true);
}}
>
Remove Layer
</Button>
</div>
<div className={c.uuid}>{`Layer UUID: ${layer.uuid}${
typeof layer.uuid === "number"
? " (Will be formally assigned upon saving)"
: ""
}`}</div>
<div className={c.actionsRight}>
<Tooltip title="Clone Layer" placement="top" arrow>
<IconButton
className={c.cloneButton}
onClick={() => {
const nextConfiguration = JSON.parse(
JSON.stringify(configuration)
);
const clonedLayer = JSON.parse(JSON.stringify(layer));
window.newUUIDCount++;
const uuid = window.newUUIDCount;
clonedLayer.uuid = uuid;
if (clonedLayer.type === "header") clonedLayer.sublayers = [];
insertLayerAfterUUID(
nextConfiguration.layers,
clonedLayer,
layer.uuid
);
dispatch(setConfiguration(nextConfiguration));
dispatch(
setSnackBarText({
text: `Cloned '${layer.name}'.`,
severity: "success",
})
);
}}
>
<ContentCopyIcon fontSize="inherit" />
</IconButton>
</Tooltip>
<Divider className={c.divider} orientation="vertical" flexItem />
<Button
className={c.doneButton}
onClick={() => {
handleClose();
}}
>
Done
</Button>
</div>
</DialogActions>
</Dialog>
);
};
export default LayerModal;