|
| 1 | +import viewer_schemas from "@geode/opengeodeweb-viewer/schemas.json"; |
| 2 | +const mesh_polyhedra_schemas = |
| 3 | + viewer_schemas.opengeodeweb_viewer.mesh.polyhedra; |
| 4 | + |
| 5 | +export function useMeshPolyhedraStyle() { |
| 6 | + /** State **/ |
| 7 | + const dataStyleStore = useDataStyleStore(); |
| 8 | + |
| 9 | + /** Getters **/ |
| 10 | + function polyhedraVisibility(id) { |
| 11 | + return dataStyleStore.styles[id].polyhedra.visibility; |
| 12 | + } |
| 13 | + function polyhedraActiveColoring(id) { |
| 14 | + return dataStyleStore.styles[id].polyhedra.coloring.active; |
| 15 | + } |
| 16 | + function polyhedraColor(id) { |
| 17 | + return dataStyleStore.styles[id].polyhedra.coloring.color; |
| 18 | + } |
| 19 | + function polyhedraVertexAttribute(id) { |
| 20 | + return dataStyleStore.styles[id].polyhedra.coloring.vertex; |
| 21 | + } |
| 22 | + function polyhedraPolygonAttribute(id) { |
| 23 | + return dataStyleStore.styles[id].polyhedra.coloring.polygon; |
| 24 | + } |
| 25 | + function polyhedraPolyhedronAttribute(id) { |
| 26 | + return dataStyleStore.styles[id].polyhedra.coloring.polyhedron; |
| 27 | + } |
| 28 | + |
| 29 | + /** Actions **/ |
| 30 | + function setPolyhedraVisibility(id, visibility) { |
| 31 | + viewer_call( |
| 32 | + { |
| 33 | + schema: mesh_polyhedra_schemas.visibility, |
| 34 | + params: { id, visibility }, |
| 35 | + }, |
| 36 | + { |
| 37 | + response_function: () => { |
| 38 | + dataStyleStore.styles[id].polyhedra.visibility = visibility; |
| 39 | + console.log( |
| 40 | + "setPolyhedraVisibility", |
| 41 | + dataStyleStore.styles[id].polyhedra.visibility |
| 42 | + ); |
| 43 | + }, |
| 44 | + } |
| 45 | + ); |
| 46 | + } |
| 47 | + function setPolyhedraActiveColoring(id, type) { |
| 48 | + if (type == "color") |
| 49 | + setPolyhedraColor(id, dataStyleStore.styles[id].polyhedra.coloring.color); |
| 50 | + else if (type == "vertex") { |
| 51 | + const vertex = dataStyleStore.styles[id].polyhedra.coloring.vertex; |
| 52 | + if (vertex !== null) setPolyhedraVertexAttribute(id, vertex); |
| 53 | + } else if (type == "polyhedron") { |
| 54 | + const polyhedron = |
| 55 | + dataStyleStore.styles[id].polyhedra.coloring.polyhedron; |
| 56 | + if (polyhedron !== null) setPolyhedraPolyhedronAttribute(id, polyhedron); |
| 57 | + } else throw new Error("Unknown polyhedra coloring type: " + type); |
| 58 | + dataStyleStore.styles[id].polyhedra.coloring.active = type; |
| 59 | + console.log( |
| 60 | + "setPolyhedraActiveColoring", |
| 61 | + dataStyleStore.styles[id].polyhedra.coloring.active |
| 62 | + ); |
| 63 | + } |
| 64 | + function setPolyhedraColor(id, color) { |
| 65 | + viewer_call( |
| 66 | + { |
| 67 | + schema: mesh_polyhedra_schemas.color, |
| 68 | + params: { id, color }, |
| 69 | + }, |
| 70 | + { |
| 71 | + response_function: () => { |
| 72 | + dataStyleStore.styles[id].polyhedra.coloring.color = color; |
| 73 | + console.log( |
| 74 | + "setPolyhedraColor", |
| 75 | + dataStyleStore.styles[id].polyhedra.coloring.color |
| 76 | + ); |
| 77 | + }, |
| 78 | + } |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + function setPolyhedraVertexAttribute(id, vertex_attribute) { |
| 83 | + viewer_call( |
| 84 | + { |
| 85 | + schema: mesh_polyhedra_schemas.vertex_attribute, |
| 86 | + params: { id, ...vertex_attribute }, |
| 87 | + }, |
| 88 | + { |
| 89 | + response_function: () => { |
| 90 | + dataStyleStore.styles[id].polyhedra.coloring.vertex = |
| 91 | + vertex_attribute; |
| 92 | + console.log( |
| 93 | + "setPolyhedraVertexAttribute", |
| 94 | + dataStyleStore.styles[id].polyhedra.coloring.vertex |
| 95 | + ); |
| 96 | + }, |
| 97 | + } |
| 98 | + ); |
| 99 | + } |
| 100 | + |
| 101 | + function setPolyhedraPolyhedronAttribute(id, polyhedron_attribute) { |
| 102 | + viewer_call( |
| 103 | + { |
| 104 | + schema: mesh_polyhedra_schemas.polyhedron_attribute, |
| 105 | + params: { id, ...polyhedron_attribute }, |
| 106 | + }, |
| 107 | + { |
| 108 | + response_function: () => { |
| 109 | + dataStyleStore.styles[id].polyhedra.coloring.polyhedron = |
| 110 | + polyhedron_attribute; |
| 111 | + console.log( |
| 112 | + "setPolyhedraPolyhedronAttribute", |
| 113 | + dataStyleStore.styles[id].polyhedra.coloring.polyhedron |
| 114 | + ); |
| 115 | + }, |
| 116 | + } |
| 117 | + ); |
| 118 | + } |
| 119 | + |
| 120 | + function applyPolyhedraStyle(id, style) { |
| 121 | + setPolyhedraVisibility(id, style.visibility); |
| 122 | + setPolyhedraActiveColoring(id, style.coloring.active); |
| 123 | + } |
| 124 | + |
| 125 | + return { |
| 126 | + polyhedraVisibility, |
| 127 | + polyhedraActiveColoring, |
| 128 | + polyhedraColor, |
| 129 | + polyhedraVertexAttribute, |
| 130 | + polyhedraPolygonAttribute, |
| 131 | + polyhedraPolyhedronAttribute, |
| 132 | + setPolyhedraVisibility, |
| 133 | + setPolyhedraActiveColoring, |
| 134 | + setPolyhedraColor, |
| 135 | + setPolyhedraVertexAttribute, |
| 136 | + setPolyhedraPolyhedronAttribute, |
| 137 | + applyPolyhedraStyle, |
| 138 | + }; |
| 139 | +} |
0 commit comments