-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathitowns_3d_tiles_layer_style.html
145 lines (132 loc) · 5 KB
/
itowns_3d_tiles_layer_style.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
<!DOCTYPE html>
<html>
<head>
<title>itowns 3DTiles layer style</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" />
</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/extents.json',
'./assets/config/crs.json',
'./assets/config/frame3D_planars.json',
'./assets/config/layer/3DTiles_Lyon.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
);
configs['3DTiles_Lyon'].forEach((layerConfig) => {
udviz.itowns.View.prototype.addLayer.call(
view,
new udviz.itowns.C3DTilesLayer(
layerConfig['id'],
{
name: layerConfig['id'],
source: new udviz.itowns.C3DTilesSource({
url: layerConfig['url'],
}),
},
view
)
);
});
const myStyle = new udviz.itowns.Style({
fill: {
color: function (feature) {
if (feature.userData.selectedColor)
return feature.userData.selectedColor;
if (feature.getInfo().batchTable.id % 13 == 0) return 'orange';
if (feature.getInfo().batchTable.id % 11 == 0) return 'brown';
if (feature.getInfo().batchTable.id % 7 == 0) return 'magenta';
if (feature.getInfo().batchTable.id % 5 == 0) return 'green';
if (feature.getInfo().batchTable.id % 3 == 0) return 'red';
if (feature.getInfo().batchTable.id % 2 == 0) return 'yellow';
return 'white';
},
opacity: function (feature) {
if (feature.batchId % 2 == 0) return 0.5;
return 1;
},
},
});
// apply style to layers
view
.getLayers()
.filter((el) => el.isC3DTilesLayer)
.forEach((layer) => {
layer.style = myStyle;
});
// userData styling example using a pick selection
const contextSelection = {
feature: null,
layer: null,
};
view.domElement.onclick = (event) => {
if (contextSelection.feature) {
// reset feature userData
contextSelection.feature.userData.selectedColor = null;
// and update style of its layer
contextSelection.layer.updateStyle();
// reset context selection
contextSelection.feature = null;
contextSelection.layer = null;
}
// get intersects based on the click event
const intersects = view.pickObjectsAt(
event,
0,
view.getLayers().filter((el) => el.isC3DTilesLayer)
);
if (intersects.length) {
// get featureClicked
const featureClicked =
intersects[0].layer.getC3DTileFeatureFromIntersectsArray(
intersects
);
if (featureClicked) {
// write in userData the selectedColor
featureClicked.userData.selectedColor = 'blue';
// and update its style layer
intersects[0].layer.updateStyle();
// set contextSelection
contextSelection.feature = featureClicked;
contextSelection.layer = intersects[0].layer;
}
}
view.notifyChange(); // need a redraw of the view
};
});
</script>
SCRIPT_TAG_RELOAD
</body>
</html>