forked from NASA-AMMOS/MMGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayerFieldVisibility.js
More file actions
75 lines (70 loc) · 2.54 KB
/
Copy pathlayerFieldVisibility.js
File metadata and controls
75 lines (70 loc) · 2.54 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
// Engine-aware field visibility for the layer config modal.
// - Non-leaflet engines hide engine-unsupported fields (ENGINE_HIDDEN_FIELDS).
// - Leaflet hides deck-only fields (DECK_ONLY_FIELDS), e.g. the client-side
// COG renderer option, which must be ABSENT (not just disabled) in Leaflet.
// Moved verbatim from LayerModal.js (keep existing entries).
export const ENGINE_HIDDEN_FIELDS = {
deckgl: {
_all: new Set([
"variables.markerIcon.shadowUrl",
"variables.markerIcon.shadowSize.0",
"variables.markerIcon.shadowSize.1",
"variables.markerIcon.shadowAnchor.0",
"variables.markerIcon.shadowAnchor.1",
]),
vector: new Set([
"shape",
"style.shapeIcon",
"style.shapeProp",
"style.shapeRotationOffset",
"style.animation",
]),
GeoJsonLayer: new Set([
"shape",
"style.shapeIcon",
"style.shapeProp",
"style.shapeRotationOffset",
"style.animation",
]),
ScatterplotLayer: new Set([
"shape",
"style.shapeIcon",
"style.shapeProp",
"style.shapeRotationOffset",
"style.animation",
]),
tile: new Set([]),
TileLayer: new Set([]),
BitmapLayer: new Set([]),
Tile3DLayer: new Set([]),
PointCloudLayer: new Set([]),
MVTLayer: new Set([]),
},
}
// Fields that only make sense for deck.gl missions and must be ABSENT
// (not just disabled) when the mission engine is leaflet.
export const DECK_ONLY_FIELDS = {
_all: ['cogRendererMode'],
}
function unionForType(map, layerType) {
if (!map) return new Set()
return new Set([...(map._all ?? []), ...(map[layerType] ?? [])])
}
export function getHiddenFieldsForEngine(mapEngine, layerType) {
if (mapEngine === 'leaflet') return unionForType(DECK_ONLY_FIELDS, layerType)
return unionForType(ENGINE_HIDDEN_FIELDS[mapEngine], layerType)
}
export function stripHiddenFields(config, hidden) {
if (!hidden || hidden.size === 0 || !config.tabs) return config
const cloned = JSON.parse(JSON.stringify(config))
cloned.tabs.forEach((tab) => {
tab.rows.forEach((row) => {
row.components = row.components.filter(
(comp) => !comp.field || !hidden.has(comp.field)
)
})
tab.rows = tab.rows.filter((row) => row.components.length > 0)
})
cloned.tabs = cloned.tabs.filter((tab) => tab.rows.length > 0)
return cloned
}