-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwidget_workspace.html
228 lines (206 loc) · 8.57 KB
/
widget_workspace.html
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
<!DOCTYPE html>
<html>
<head>
<title>widget workspace</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./assets/css/examples.css" />
<link rel="stylesheet" href="./assets/css/loading_screen.css" />
<link rel="stylesheet" href="./assets/css/widget_workspace.css" />
</head>
<body>
<script src="../dist/RUN_MODE/bundle.js"></script>
<script src="./assets/js/loadingScreen.js"></script>
<script type="text/javascript">
const udviz = window.udviz;
udviz
.loadMultipleJSON([
'./assets/config/crs.json',
'./assets/config/extents.json',
'./assets/config/layer/workspace_tileset.json',
'./assets/config/layer/base_maps.json',
'./assets/config/layer/elevation.json',
'./assets/config/widget/workspace_widget.json',
'./assets/config/server/sparql_workspace_server.json',
])
.then((configs) => {
udviz.proj4.default.defs(
configs['crs'][0].name,
configs['crs'][0].transform
);
const extent = new udviz.itowns.Extent(
configs['extents'][0].name,
parseInt(configs['extents'][0].west),
parseInt(configs['extents'][0].east),
parseInt(configs['extents'][0].south),
parseInt(configs['extents'][0].north)
);
// create a itowns planar view
const viewDomElement = document.createElement('div');
viewDomElement.classList.add('full_screen');
document.body.appendChild(viewDomElement);
const view = new udviz.itowns.PlanarView(viewDomElement, extent);
// eslint-disable-next-line no-constant-condition
if ('RUN_MODE' == 'production')
loadingScreen(view, ['UD-VIZ', 'UDVIZ_VERSION']);
// init scene 3D
udviz.initScene(
view.camera.camera3D,
view.mainLoop.gfxEngine.renderer,
view.scene
);
// add a 3DTiles temporal layer
const extensions = new udviz.itowns.C3DTExtensions();
extensions.registerExtension(udviz.extensions3DTilesTemporal.ID, {
[udviz.itowns.C3DTilesTypes.batchtable]:
udviz.extensions3DTilesTemporal.C3DTTemporalBatchTable,
[udviz.itowns.C3DTilesTypes.boundingVolume]:
udviz.extensions3DTilesTemporal.C3DTTemporalBoundingVolume,
[udviz.itowns.C3DTilesTypes.tileset]:
udviz.extensions3DTilesTemporal.C3DTTemporalTileset,
});
configs['workspace_tileset'].forEach((layerConfig) => {
const c3DTilesLayer = new udviz.itowns.C3DTilesLayer(
layerConfig.id,
{
name: layerConfig.id,
source: new udviz.itowns.C3DTilesSource({
url: layerConfig.url,
}),
registeredExtensions: extensions,
},
view
);
udviz.itowns.View.prototype.addLayer.call(view, c3DTilesLayer);
});
view.addLayer(
new udviz.itowns.ColorLayer(configs['base_maps'][0]['name'], {
updateStrategy: {
type: udviz.itowns.STRATEGY_DICHOTOMY,
options: {},
},
source: new udviz.itowns.WMSSource({
extent: extent,
name: configs['base_maps'][0].source['name'],
url: configs['base_maps'][0].source['url'],
version: configs['base_maps'][0].source['version'],
crs: extent.crs,
format: configs['base_maps'][0].source['format'],
}),
transparent: true,
})
);
const isTextureFormat =
configs['elevation']['format'] == 'image/jpeg' ||
configs['elevation']['format'] == 'image/png';
view.addLayer(
new udviz.itowns.ElevationLayer(
configs['elevation']['layer_name'],
{
useColorTextureElevation: isTextureFormat,
colorTextureElevationMinZ: isTextureFormat
? configs['elevation']['colorTextureElevationMinZ']
: null,
colorTextureElevationMaxZ: isTextureFormat
? configs['elevation']['colorTextureElevationMaxZ']
: null,
source: new udviz.itowns.WMSSource({
extent: extent,
url: configs['elevation']['url'],
name: configs['elevation']['name'],
crs: extent.crs,
heightMapWidth: 256,
format: configs['elevation']['format'],
}),
}
)
);
// //// SPARQL Workspace widget
const temporalWrappers = new Map();
view
.getLayers()
.filter(
(el) =>
el.isC3DTilesLayer &&
el.registeredExtensions.isExtensionRegistered(
udviz.extensions3DTilesTemporal.ID
)
)
.forEach((layer) => {
temporalWrappers.set(
layer.id,
new udviz.extensions3DTilesTemporal.Temporal3DTilesLayerWrapper(
layer
)
);
});
const sparqlWorkspaceWidgetView =
new udviz.widgetWorkspace.SparqlWorkspaceQueryWindow(
new udviz.widgetSPARQL.SparqlEndpointResponseProvider(
configs['sparql_workspace_server']
),
configs['workspace_widget']
);
sparqlWorkspaceWidgetView.domElement.classList.add(
'widget_workspace'
);
// Add UI
document.body.appendChild(sparqlWorkspaceWidgetView.domElement);
// Add listeners for D3Canvas node events. Three events are possible 'click', 'mouseover', and 'mouseout'
sparqlWorkspaceWidgetView.d3Graph.addEventListener(
'click',
(event) => {
// Get clicked node's data, if nodeData.type is 'Version' or 'VersionTransition', select the appropriate
// temporalwrapper that contains the 3DTiles representation of the version or transition,
// then set the time of the temporal wrapper to visualize the 3DTiles representation of the version or transition.
const nodeData =
sparqlWorkspaceWidgetView.d3Graph.data.getNodeByIndex(
event.datum.index
);
const nodeType = udviz.getUriLocalname(nodeData.type);
if (nodeType == 'Version' || nodeType == 'VersionTransition') {
/* find the first scenario that contains the clicked node,
* find the temporal the geometry layer with the same name, and
* set the current time to the averaged timestamps linked to the node
*/
const scenarioLayerName =
sparqlWorkspaceWidgetView.getScenarioLayerNameByIndex(
event.datum.index,
view
);
const scenarioLayer = view
.getLayers()
.filter((el) => el.isC3DTilesLayer)
.find((layer) => {
return layer.name == scenarioLayerName;
});
console.debug(scenarioLayer);
// if a layer is found, make sure it is visible and hide all other layers
if (scenarioLayer) {
view
.getLayers()
.filter((el) => el.isC3DTilesLayer)
.forEach(
(layer) => (layer.visible = layer == scenarioLayer)
);
// Calculate the average timestamp of the clicked node
const timestamps =
sparqlWorkspaceWidgetView.getBitemporalTimestampsByIndex(
event.datum.index
);
const timestampAverage =
(timestamps.validTo - timestamps.validFrom) / 2 +
timestamps.validFrom;
// set style temporal layer with the date
temporalWrappers.get(scenarioLayer.id).styleDate =
timestampAverage;
view.notifyChange();
}
}
}
);
});
</script>
SCRIPT_TAG_RELOAD
</body>
</html>