-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhideFeatures.js
More file actions
309 lines (252 loc) Β· 10.2 KB
/
Copy pathhideFeatures.js
File metadata and controls
309 lines (252 loc) Β· 10.2 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
/**
* geoBIM.app
* Β© 2026 Christof Lorenz. All rights reserved.
*
* Licensed under the Business Source License 1.1 (BSL 1.1)
* Non-commercial use, evaluation, research, and education permitted.
* Commercial use requires written permission.
* Contact: info@geobim.app
*
* Change Date: 2030-03-01 β converts to MIT License
*/
// ===============================
// CESIUM BIM VIEWER - HIDE FEATURES MODULE (COMPLETE v2.2)
// Click to hide individual BIM elements/features
// ===============================
'use strict';
(function() {
// State management for hidden features
BimViewer.hiddenFeatures = {
features: new Map(),
isHideMode: false,
counter: 0
};
// Toggle hide mode on/off
BimViewer.toggleHideMode = function() {
this.hiddenFeatures.isHideMode = !this.hiddenFeatures.isHideMode;
const toggleBtn = document.getElementById('toggleHideMode');
const indicator = document.getElementById('hideModeIndicator');
if (this.hiddenFeatures.isHideMode) {
if (window.BimCursor) BimCursor.set('hide');
toggleBtn.classList.add('active');
if (indicator) {
indicator.classList.add('active');
indicator.textContent = 'π HIDE MODE ACTIVE - Click on elements to hide them (ESC or H to exit)';
}
this.updateStatus('Hide mode activated - Click elements to hide', 'warning');
console.log('π Hide mode ACTIVATED');
} else {
if (window.BimCursor) BimCursor.clear();
toggleBtn.classList.remove('active');
if (indicator) {
indicator.classList.remove('active');
}
this.updateStatus('Hide mode deactivated', 'success');
console.log('ποΈ Hide mode DEACTIVATED');
}
this.updateHiddenFeaturesCount();
};
// Hide a specific feature
BimViewer.hideFeature = function(feature) {
if (!feature) return;
try {
const featureId = this.hiddenFeatures.counter++;
let elementType = 'Unknown Element';
try {
const className = feature.getProperty('className');
const name = feature.getProperty('Name') || feature.getProperty('name');
elementType = className || name || 'Element';
} catch (error) {
console.warn('β οΈ Could not get element properties:', error.message);
}
const originalColor = Cesium.Color.clone(feature.color, new Cesium.Color());
feature.show = false;
this.hiddenFeatures.features.set(featureId, {
feature: feature,
originalColor: originalColor,
elementType: elementType,
timestamp: new Date()
});
this.updateStatus(`Element hidden: ${elementType}`, 'success');
this.updateHiddenFeaturesList();
this.updateHiddenFeaturesCount();
console.log(`π Feature ${featureId} hidden:`, elementType);
} catch (error) {
console.error('β Error hiding feature:', error);
this.updateStatus('Error hiding element', 'error');
}
};
// Show a specific hidden feature
BimViewer.showHiddenFeature = function(featureId) {
const hiddenData = this.hiddenFeatures.features.get(featureId);
if (!hiddenData) {
console.warn(`β οΈ Feature ${featureId} not found in hidden features`);
return;
}
try {
hiddenData.feature.show = true;
hiddenData.feature.color = hiddenData.originalColor;
this.hiddenFeatures.features.delete(featureId);
this.updateStatus(`Element shown: ${hiddenData.elementType}`, 'success');
this.updateHiddenFeaturesList();
this.updateHiddenFeaturesCount();
console.log(`ποΈ Feature ${featureId} restored:`, hiddenData.elementType);
} catch (error) {
console.error(`β Error showing feature ${featureId}:`, error);
this.updateStatus('Error showing element', 'error');
}
};
// Show all hidden features
BimViewer.showAllHiddenFeatures = function() {
if (this.hiddenFeatures.features.size === 0) {
this.updateStatus('No hidden elements to show', 'warning');
return;
}
const count = this.hiddenFeatures.features.size;
try {
this.hiddenFeatures.features.forEach((hiddenData, featureId) => {
try {
hiddenData.feature.show = true;
hiddenData.feature.color = hiddenData.originalColor;
} catch (error) {
console.warn(`β οΈ Could not restore feature ${featureId}:`, error.message);
}
});
this.hiddenFeatures.features.clear();
this.updateStatus(`${count} element(s) shown`, 'success');
this.updateHiddenFeaturesList();
this.updateHiddenFeaturesCount();
console.log(`β
${count} hidden features restored`);
} catch (error) {
console.error('β Error showing all features:', error);
this.updateStatus('Error showing all elements', 'error');
}
};
// Update the list of hidden features in the UI
BimViewer.updateHiddenFeaturesList = function() {
const container = document.getElementById('hiddenFeaturesList');
if (!container) return;
if (this.hiddenFeatures.features.size === 0) {
container.innerHTML = '<div class="text-center text-muted text-small">No hidden elements</div>';
return;
}
let html = '';
this.hiddenFeatures.features.forEach((hiddenData, featureId) => {
const timeStr = hiddenData.timestamp.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
html += `
<div class="hidden-feature-item">
<div class="hidden-feature-info">
<div class="hidden-feature-name">π« ${hiddenData.elementType}</div>
<div class="hidden-feature-details">Hidden at ${timeStr}</div>
</div>
<div class="hidden-feature-controls">
<button class="hidden-feature-btn show-btn"
onclick="BimViewer.showHiddenFeature(${featureId})"
title="Show element">
ποΈ
</button>
</div>
</div>
`;
});
container.innerHTML = html;
};
// Update hidden features counter badge
BimViewer.updateHiddenFeaturesCount = function() {
const badge = document.getElementById('hiddenFeaturesCount');
if (!badge) return;
const count = this.hiddenFeatures.features.size;
if (count > 0) {
badge.textContent = count;
badge.style.display = 'inline-block';
} else {
badge.style.display = 'none';
}
};
// Re-apply hidden state after style changes (e.g. IFC/Revit filter)
// CesiumJS applies styles lazily during the next render pass, so we also
// schedule a second pass via requestAnimationFrame.
BimViewer.reapplyHiddenFeatures = function() {
if (this.hiddenFeatures.features.size === 0) return;
const apply = () => {
this.hiddenFeatures.features.forEach((hiddenData) => {
try {
hiddenData.feature.show = false;
} catch (error) {
// Feature may have been unloaded
}
});
};
// Apply immediately
apply();
// Re-apply after CesiumJS processes the style in the next render pass
requestAnimationFrame(apply);
console.log(`π Re-applied hidden state to ${this.hiddenFeatures.features.size} feature(s)`);
};
// Get current hide mode state
BimViewer.getHiddenFeaturesState = function() {
return {
isHideMode: this.hiddenFeatures.isHideMode,
hiddenCount: this.hiddenFeatures.features.size,
features: Array.from(this.hiddenFeatures.features.entries())
};
};
// β
FIXED: Store reference to ORIGINAL click handler WRAPPER
BimViewer._originalClickHandler = null;
// β
FIXED: Initialize hide features AFTER features.js is ready
BimViewer.initHideFeatures = function() {
console.log('π Initializing Hide Features...');
// Store original handler if not already stored
if (!this._originalClickHandler && typeof this.handleIFCSelection === 'function') {
this._originalClickHandler = this.handleIFCSelection.bind(this);
console.log('β
Original IFC selection handler stored');
}
// Replace with our wrapper
this.handleIFCSelection = async function(movement) {
// If hide mode is active, hide the clicked feature instead
if (this.hiddenFeatures.isHideMode) {
try {
const picked = await this.viewer.scene.pickAsync(movement.position);
if (picked && picked instanceof Cesium.Cesium3DTileFeature) {
this.hideFeature(picked);
} else {
this.updateStatus('No element found at click position', 'warning');
}
} catch (error) {
console.error('β Error in hide mode click handler:', error);
this.updateStatus('Error hiding element', 'error');
}
return; // Don't proceed with normal IFC selection
}
// Otherwise, use the original IFC selection handler (async)
if (this._originalClickHandler) {
await this._originalClickHandler(movement);
}
};
console.log('β
Hide Features click handler installed');
};
// Keyboard shortcuts
document.addEventListener('keydown', (event) => {
if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA') return;
const key = event.key.toLowerCase();
// H = Toggle hide mode
if (key === 'h' && !event.shiftKey && !event.ctrlKey && !event.altKey) {
event.preventDefault();
BimViewer.toggleHideMode();
}
// Shift+H = Show all hidden features
if (key === 'h' && event.shiftKey) {
event.preventDefault();
BimViewer.showAllHiddenFeatures();
}
});
console.log('β
Hide Features module loaded');
console.log('π‘ Usage:');
console.log(' - Press H to toggle hide mode');
console.log(' - Press Shift+H to show all hidden elements');
console.log(' - Click "π Hide Elements" button in toolbar');
})();