bruce-cesium 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bruce-cesium.es5.js +1018 -559
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +1015 -556
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/bruce-cesium.js +30 -30
- package/dist/lib/rendering/entity-render-engine.js +848 -848
- package/dist/lib/rendering/entity-render-engine.js.map +1 -1
- package/dist/lib/rendering/menu-item-manager.js +252 -252
- package/dist/lib/rendering/render-addons/measure-addon.js +186 -186
- package/dist/lib/rendering/render-addons/render-addon.js +2 -2
- package/dist/lib/rendering/render-helper.js +296 -279
- package/dist/lib/rendering/render-helper.js.map +1 -1
- package/dist/lib/rendering/render-managers/common/shared-getters.js +31 -31
- package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js +146 -146
- package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js.map +1 -1
- package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js +143 -143
- package/dist/lib/rendering/render-managers/entities/entities-render-manager.js +234 -234
- package/dist/lib/rendering/render-managers/entities/entities-render-manager.js.map +1 -1
- package/dist/lib/rendering/render-managers/entities/entity-render-manager.js +139 -139
- package/dist/lib/rendering/render-managers/entities/entity-render-manager.js.map +1 -1
- package/dist/lib/rendering/render-managers/render-manager.js +50 -50
- package/dist/lib/rendering/render-managers/tilesets/tileset-cad-render-manager.js +236 -236
- package/dist/lib/rendering/render-managers/tilesets/tileset-cad-render-manager.js.map +1 -1
- package/dist/lib/rendering/render-managers/tilesets/tileset-osm-render-manager.js +320 -320
- package/dist/lib/rendering/render-managers/tilesets/tileset-osm-render-manager.js.map +1 -1
- package/dist/lib/rendering/tile-render-engine.js +822 -542
- package/dist/lib/rendering/tile-render-engine.js.map +1 -1
- package/dist/lib/rendering/tileset-render-engine.js +499 -499
- package/dist/lib/rendering/tileset-render-engine.js.map +1 -1
- package/dist/lib/rendering/view-render-engine.js +300 -138
- package/dist/lib/rendering/view-render-engine.js.map +1 -1
- package/dist/lib/rendering/visuals-register.js +394 -394
- package/dist/lib/utils/drawing-utils.js +42 -42
- package/dist/lib/utils/entity-utils.js +99 -99
- package/dist/lib/utils/measure-utils.js +34 -34
- package/dist/lib/utils/view-utils.js +34 -34
- package/dist/lib/utils/view-utils.js.map +1 -1
- package/dist/lib/viewer/cesium-view-monitor.js +231 -231
- package/dist/lib/viewer/viewer-utils.js +85 -85
- package/dist/types/rendering/render-helper.d.ts +1 -1
- package/dist/types/rendering/tile-render-engine.d.ts +60 -44
- package/dist/types/utils/view-utils.d.ts +1 -1
- package/package.json +76 -73
|
@@ -1,500 +1,500 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.TilesetRenderEngine = void 0;
|
|
51
|
-
var bruce_models_1 = require("bruce-models");
|
|
52
|
-
var Cesium = require("cesium");
|
|
53
|
-
function colorToCColor(color) {
|
|
54
|
-
return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
|
|
55
|
-
}
|
|
56
|
-
var TilesetRenderEngine;
|
|
57
|
-
(function (TilesetRenderEngine) {
|
|
58
|
-
function ApplyPosition(cTileset, tileset, coords) {
|
|
59
|
-
if (tileset.type == bruce_models_1.Tileset.EType.Cad) {
|
|
60
|
-
var settings = tileset.settings;
|
|
61
|
-
var location_1;
|
|
62
|
-
var transform = void 0;
|
|
63
|
-
// Position using root entity + ucs.
|
|
64
|
-
if (coords === null || coords === void 0 ? void 0 : coords.ucs) {
|
|
65
|
-
location_1 = coords.ucs.location;
|
|
66
|
-
transform = coords.transform;
|
|
67
|
-
}
|
|
68
|
-
// Position using tileset.
|
|
69
|
-
else {
|
|
70
|
-
transform = settings.transform;
|
|
71
|
-
location_1 = settings.location;
|
|
72
|
-
}
|
|
73
|
-
if (!(location_1 === null || location_1 === void 0 ? void 0 : location_1.latitude)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
transform = __assign({ heading: 0, pitch: 0, roll: 0, scale: 1, x: 0, y: 0, z: 0 }, transform);
|
|
77
|
-
if (transform.scale <= 0) {
|
|
78
|
-
transform.scale = 0.000001;
|
|
79
|
-
}
|
|
80
|
-
var pos = Cesium.Cartesian3.fromDegrees(location_1.longitude, location_1.latitude, location_1.altitude);
|
|
81
|
-
var hpr = Cesium.HeadingPitchRoll.fromDegrees(transform.heading, transform.pitch, transform.roll, new Cesium.HeadingPitchRoll());
|
|
82
|
-
var root = cTileset.root;
|
|
83
|
-
root.transform = Cesium.Transforms.headingPitchRollToFixedFrame(pos, hpr);
|
|
84
|
-
var scaleMatrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(transform.scale, transform.scale, transform.scale), new Cesium.Matrix4());
|
|
85
|
-
root.transform = Cesium.Matrix4.multiply(root.transform, scaleMatrix, root.transform);
|
|
86
|
-
root.transform = Cesium.Matrix4.multiplyByTranslation(root.transform, new Cesium.Cartesian3(transform.x, transform.y, transform.z), root.transform);
|
|
87
|
-
// Force matrix to update
|
|
88
|
-
root.updateTransform();
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
throw ("Not implemented.");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
TilesetRenderEngine.ApplyPosition = ApplyPosition;
|
|
95
|
-
function ApplySettings(cTileset, tileset) {
|
|
96
|
-
if (tileset.type == bruce_models_1.Tileset.EType.Cad) {
|
|
97
|
-
var settings = tileset.settings;
|
|
98
|
-
var maxScreenSpaceError = settings.maximumScreenSpaceError;
|
|
99
|
-
if (maxScreenSpaceError || maxScreenSpaceError == 0) {
|
|
100
|
-
cTileset.maximumScreenSpaceError = maxScreenSpaceError;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
throw ("Not implemented.");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
TilesetRenderEngine.ApplySettings = ApplySettings;
|
|
108
|
-
function Render(params) {
|
|
109
|
-
var api = params.apiGetter.getApi(params.apiGetter.accountId
|
|
110
|
-
if (params.tileset.type == bruce_models_1.Tileset.EType.Cad) {
|
|
111
|
-
var cTileset_1 = new Cesium.Cesium3DTileset({
|
|
112
|
-
url: bruce_models_1.Tileset.GetPublicFileUrl(api, params.tileset.id, "tileset.json") + "?generation=" + params.tileset.generateVersion
|
|
113
|
-
});
|
|
114
|
-
params.viewer.scene.primitives.add(cTileset_1);
|
|
115
|
-
cTileset_1.readyPromise.then(function () {
|
|
116
|
-
ApplySettings(cTileset_1, params.tileset);
|
|
117
|
-
ApplyPosition(cTileset_1, params.tileset, params.coords);
|
|
118
|
-
});
|
|
119
|
-
return cTileset_1;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
throw ("Not implemented.");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
TilesetRenderEngine.Render = Render;
|
|
126
|
-
var CadStyler = /** @class */ (function () {
|
|
127
|
-
function CadStyler(api, cTileset, fallbackStyleId, styleMapping) {
|
|
128
|
-
this.disposed = false;
|
|
129
|
-
this.loadedEntities = {};
|
|
130
|
-
this.styleMappingLoaded = false;
|
|
131
|
-
this.styleMappingsLoaded = {};
|
|
132
|
-
this.fallbackStyle = null;
|
|
133
|
-
this.runningQueues = 0;
|
|
134
|
-
this.recordLoadQueue = [];
|
|
135
|
-
this.recordCheckQueue = [];
|
|
136
|
-
this.api = api;
|
|
137
|
-
this.cTileset = cTileset;
|
|
138
|
-
this.fallbackStyleId = fallbackStyleId;
|
|
139
|
-
this.styleMapping = styleMapping;
|
|
140
|
-
this.loadStyles();
|
|
141
|
-
}
|
|
142
|
-
Object.defineProperty(CadStyler.prototype, "Disposed", {
|
|
143
|
-
get: function () {
|
|
144
|
-
return this.disposed;
|
|
145
|
-
},
|
|
146
|
-
enumerable: false,
|
|
147
|
-
configurable: true
|
|
148
|
-
});
|
|
149
|
-
CadStyler.prototype.QueueEntities = function (entities) {
|
|
150
|
-
for (var i = 0; i < entities.length; i++) {
|
|
151
|
-
var entity = entities[i];
|
|
152
|
-
this.queueTilesetFeatureStyle(entity);
|
|
153
|
-
}
|
|
154
|
-
if (this.recordLoadQueue.length > 0) {
|
|
155
|
-
this.processQueue();
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
CadStyler.prototype.processQueue = function () {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
-
var MAX_BATCHES, BATCH_DELAY, batch, rerun, entityIds, entities, _loop_1, this_1, i;
|
|
161
|
-
var _this = this;
|
|
162
|
-
return __generator(this, function (_a) {
|
|
163
|
-
switch (_a.label) {
|
|
164
|
-
case 0:
|
|
165
|
-
MAX_BATCHES = 2;
|
|
166
|
-
BATCH_DELAY = 200;
|
|
167
|
-
if (this.runningQueues >= MAX_BATCHES) {
|
|
168
|
-
return [2 /*return*/];
|
|
169
|
-
}
|
|
170
|
-
else if (this.disposed) {
|
|
171
|
-
return [2 /*return*/];
|
|
172
|
-
}
|
|
173
|
-
this.runningQueues += 1;
|
|
174
|
-
batch = [];
|
|
175
|
-
rerun = false;
|
|
176
|
-
_a.label = 1;
|
|
177
|
-
case 1:
|
|
178
|
-
_a.trys.push([1, , 4, 5]);
|
|
179
|
-
batch = this.getEntitiesForQueue();
|
|
180
|
-
entityIds = batch.map(function (x) { return x.entityId; });
|
|
181
|
-
if (!(entityIds.length > 0)) return [3 /*break*/, 3];
|
|
182
|
-
return [4 /*yield*/, bruce_models_1.Entity.GetListByIds(this.api, entityIds)];
|
|
183
|
-
case 2:
|
|
184
|
-
entities = _a.sent();
|
|
185
|
-
_loop_1 = function (i) {
|
|
186
|
-
var record = entities[i];
|
|
187
|
-
var feature = batch.find(function (x) { var _a; return (x === null || x === void 0 ? void 0 : x.entityId) == ((_a = record === null || record === void 0 ? void 0 : record.Bruce) === null || _a === void 0 ? void 0 : _a.ID); });
|
|
188
|
-
if (feature) {
|
|
189
|
-
this_1.styleTilesetFeatureFullData(feature, record);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
this_1 = this;
|
|
193
|
-
for (i = 0; i < entities.length; i++) {
|
|
194
|
-
_loop_1(i);
|
|
195
|
-
}
|
|
196
|
-
rerun = batch.length > 0;
|
|
197
|
-
_a.label = 3;
|
|
198
|
-
case 3: return [3 /*break*/, 5];
|
|
199
|
-
case 4:
|
|
200
|
-
setTimeout(function () {
|
|
201
|
-
_this.runningQueues -= 1;
|
|
202
|
-
if (rerun) {
|
|
203
|
-
_this.processQueue();
|
|
204
|
-
}
|
|
205
|
-
}, BATCH_DELAY);
|
|
206
|
-
return [7 /*endfinally*/];
|
|
207
|
-
case 5: return [2 /*return*/];
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
CadStyler.prototype.getEntitiesForQueue = function () {
|
|
213
|
-
var BATCH_SIZE = 30;
|
|
214
|
-
var batchHashes = this.recordLoadQueue.splice(0, BATCH_SIZE);
|
|
215
|
-
var entities = [];
|
|
216
|
-
for (var i = 0; i < batchHashes.length; i++) {
|
|
217
|
-
var id = batchHashes[i];
|
|
218
|
-
var entity = this.loadedEntities[id];
|
|
219
|
-
if (entity) {
|
|
220
|
-
entities.push(entity);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return entities;
|
|
224
|
-
};
|
|
225
|
-
CadStyler.prototype.Dispose = function () {
|
|
226
|
-
if (this.disposed) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
this.disposed = true;
|
|
230
|
-
clearInterval(this.queueLoadInterval);
|
|
231
|
-
clearInterval(this.queueCheckInterval);
|
|
232
|
-
};
|
|
233
|
-
CadStyler.prototype.loadStyles = function () {
|
|
234
|
-
var _a, _b;
|
|
235
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
236
|
-
var fallbackStyleId, data, e_1, styleMapping, modelTree, entityTypeIds, _loop_2, i, i, styleMap, styleId, entityType, e_2, data, e_3;
|
|
237
|
-
return __generator(this, function (_c) {
|
|
238
|
-
switch (_c.label) {
|
|
239
|
-
case 0:
|
|
240
|
-
fallbackStyleId = this.fallbackStyleId;
|
|
241
|
-
if (!(fallbackStyleId && fallbackStyleId > 0)) return [3 /*break*/, 4];
|
|
242
|
-
_c.label = 1;
|
|
243
|
-
case 1:
|
|
244
|
-
_c.trys.push([1, 3, , 4]);
|
|
245
|
-
return [4 /*yield*/, bruce_models_1.Style.Get(this.api, fallbackStyleId)];
|
|
246
|
-
case 2:
|
|
247
|
-
data = _c.sent();
|
|
248
|
-
this.fallbackStyle = data;
|
|
249
|
-
return [3 /*break*/, 4];
|
|
250
|
-
case 3:
|
|
251
|
-
e_1 = _c.sent();
|
|
252
|
-
console.error(e_1);
|
|
253
|
-
return [3 /*break*/, 4];
|
|
254
|
-
case 4:
|
|
255
|
-
styleMapping = this.styleMapping;
|
|
256
|
-
if (!styleMapping) {
|
|
257
|
-
styleMapping = [];
|
|
258
|
-
}
|
|
259
|
-
this.styleMapping = styleMapping;
|
|
260
|
-
// It is default style.
|
|
261
|
-
// We have to get all possible entity type ids and append them to mapping.
|
|
262
|
-
if (!fallbackStyleId) {
|
|
263
|
-
try {
|
|
264
|
-
modelTree = (_b = (_a = this.cTileset) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.modelTree;
|
|
265
|
-
if (modelTree) {
|
|
266
|
-
entityTypeIds = this.getEntityTypeIdsFromModelTree(modelTree);
|
|
267
|
-
_loop_2 = function (i) {
|
|
268
|
-
var entityTypeId = entityTypeIds[i];
|
|
269
|
-
if (styleMapping.findIndex(function (x) { return x.EntityTypeID == entityTypeId; }) <= -1) {
|
|
270
|
-
styleMapping.push({
|
|
271
|
-
EntityTypeID: entityTypeId,
|
|
272
|
-
StyleID: null,
|
|
273
|
-
style: null
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
for (i = 0; i < entityTypeIds.length; i++) {
|
|
278
|
-
_loop_2(i);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
catch (e) {
|
|
283
|
-
console.log(e);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
i = 0;
|
|
287
|
-
_c.label = 5;
|
|
288
|
-
case 5:
|
|
289
|
-
if (!(i < styleMapping.length)) return [3 /*break*/, 15];
|
|
290
|
-
if (this.disposed) {
|
|
291
|
-
return [3 /*break*/, 15];
|
|
292
|
-
}
|
|
293
|
-
styleMap = styleMapping[i];
|
|
294
|
-
if (!!styleMap.style) return [3 /*break*/, 13];
|
|
295
|
-
styleId = styleMap.StyleID;
|
|
296
|
-
if (!!styleId) return [3 /*break*/, 9];
|
|
297
|
-
_c.label = 6;
|
|
298
|
-
case 6:
|
|
299
|
-
_c.trys.push([6, 8, , 9]);
|
|
300
|
-
return [4 /*yield*/, bruce_models_1.EntityType.Get(this.api, styleMap.EntityTypeID)];
|
|
301
|
-
case 7:
|
|
302
|
-
entityType = _c.sent();
|
|
303
|
-
styleId = entityType === null || entityType === void 0 ? void 0 : entityType["DisplaySetting.ID"];
|
|
304
|
-
return [3 /*break*/, 9];
|
|
305
|
-
case 8:
|
|
306
|
-
e_2 = _c.sent();
|
|
307
|
-
console.error(e_2);
|
|
308
|
-
return [3 /*break*/, 9];
|
|
309
|
-
case 9:
|
|
310
|
-
if (!styleId) return [3 /*break*/, 13];
|
|
311
|
-
_c.label = 10;
|
|
312
|
-
case 10:
|
|
313
|
-
_c.trys.push([10, 12, , 13]);
|
|
314
|
-
return [4 /*yield*/, bruce_models_1.Style.Get(this.api, styleId)];
|
|
315
|
-
case 11:
|
|
316
|
-
data = _c.sent();
|
|
317
|
-
if (data) {
|
|
318
|
-
styleMap.style = data;
|
|
319
|
-
styleMap.StyleID = styleId;
|
|
320
|
-
}
|
|
321
|
-
return [3 /*break*/, 13];
|
|
322
|
-
case 12:
|
|
323
|
-
e_3 = _c.sent();
|
|
324
|
-
console.error(e_3);
|
|
325
|
-
return [3 /*break*/, 13];
|
|
326
|
-
case 13:
|
|
327
|
-
if (styleMap.EntityTypeID && styleMap.style) {
|
|
328
|
-
this.styleMappingsLoaded[styleMap.EntityTypeID] = true;
|
|
329
|
-
this.processTilesetFeatureCheckQueue();
|
|
330
|
-
this.processQueue();
|
|
331
|
-
}
|
|
332
|
-
_c.label = 14;
|
|
333
|
-
case 14:
|
|
334
|
-
i++;
|
|
335
|
-
return [3 /*break*/, 5];
|
|
336
|
-
case 15:
|
|
337
|
-
this.styleMappingLoaded = true;
|
|
338
|
-
if (!!this.disposed) return [3 /*break*/, 17];
|
|
339
|
-
return [4 /*yield*/, this.processTilesetFeatureCheckQueue()];
|
|
340
|
-
case 16:
|
|
341
|
-
_c.sent();
|
|
342
|
-
this.processQueue();
|
|
343
|
-
_c.label = 17;
|
|
344
|
-
case 17: return [2 /*return*/];
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
CadStyler.prototype.getEntityTypeIdsFromModelTree = function (modelTree) {
|
|
350
|
-
var entityTypeIds = [];
|
|
351
|
-
this.digEntityTypeIdsFromModelTreeBranch(modelTree, entityTypeIds);
|
|
352
|
-
return entityTypeIds;
|
|
353
|
-
};
|
|
354
|
-
CadStyler.prototype.digEntityTypeIdsFromModelTreeBranch = function (branch, arr) {
|
|
355
|
-
if (branch) {
|
|
356
|
-
// Does not yet include this entity type id.
|
|
357
|
-
if (branch.typeId && !arr.includes(branch.typeId)) {
|
|
358
|
-
arr.push(branch.typeId);
|
|
359
|
-
}
|
|
360
|
-
if (branch.children) {
|
|
361
|
-
for (var i = 0; i < branch.children.length; i++) {
|
|
362
|
-
var child = branch.children[i];
|
|
363
|
-
this.digEntityTypeIdsFromModelTreeBranch(child, arr);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
CadStyler.prototype.processTilesetFeatureCheckQueue = function () {
|
|
369
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
370
|
-
var BATCH_CHECK_SIZE;
|
|
371
|
-
var _this = this;
|
|
372
|
-
return __generator(this, function (_a) {
|
|
373
|
-
BATCH_CHECK_SIZE = 1000;
|
|
374
|
-
return [2 /*return*/, new Promise(function (res) {
|
|
375
|
-
clearInterval(_this.queueCheckInterval);
|
|
376
|
-
_this.queueCheckInterval = setInterval(function () {
|
|
377
|
-
if (_this.disposed) {
|
|
378
|
-
clearInterval(_this.queueCheckInterval);
|
|
379
|
-
res();
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
// Construct batch for loaded styles.
|
|
383
|
-
var batch = [];
|
|
384
|
-
if (_this.styleMappingLoaded) {
|
|
385
|
-
batch = _this.recordCheckQueue.splice(0, BATCH_CHECK_SIZE);
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
for (var i = 0; i < _this.recordCheckQueue.length; i++) {
|
|
389
|
-
var hash = _this.recordCheckQueue[i];
|
|
390
|
-
var entity = _this.loadedEntities[hash];
|
|
391
|
-
if (entity) {
|
|
392
|
-
var entityTypeId = entity.entityTypeId;
|
|
393
|
-
if (entityTypeId) {
|
|
394
|
-
if (_this.styleMappingsLoaded[entityTypeId] == true) {
|
|
395
|
-
batch.push(hash);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
if (batch.length >= BATCH_CHECK_SIZE) {
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
var _loop_3 = function (i) {
|
|
404
|
-
var hash = batch[i];
|
|
405
|
-
var index = _this.recordCheckQueue.findIndex(function (x) { return x == hash; });
|
|
406
|
-
if (index > -1) {
|
|
407
|
-
_this.recordCheckQueue.splice(index, 1);
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
for (var i = 0; i < batch.length; i++) {
|
|
411
|
-
_loop_3(i);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
if (batch.length) {
|
|
415
|
-
for (var i = 0; i < batch.length; i++) {
|
|
416
|
-
var item = batch[i];
|
|
417
|
-
var entity = _this.loadedEntities[item];
|
|
418
|
-
if (entity) {
|
|
419
|
-
_this.queueTilesetFeatureStyle(entity);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
clearInterval(_this.queueCheckInterval);
|
|
425
|
-
res();
|
|
426
|
-
}
|
|
427
|
-
}, 50);
|
|
428
|
-
})];
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
};
|
|
432
|
-
CadStyler.prototype.queueTilesetFeatureStyle = function (entity) {
|
|
433
|
-
if (this.styleMappingLoaded || this.styleMappingsLoaded[entity.entityTypeId] == true) {
|
|
434
|
-
var needsData = this.getTilesetFeatureNeedsFullData(entity.entityId, entity.entityTypeId);
|
|
435
|
-
if (needsData) {
|
|
436
|
-
if (this.recordLoadQueue.findIndex(function (x) { return x == entity.entityId; })) {
|
|
437
|
-
this.recordLoadQueue.push(entity.entityId);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
this.styleTilesetFeature(entity);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
this.recordCheckQueue.push(entity.entityId);
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
CadStyler.prototype.styleTilesetFeature = function (entity) {
|
|
449
|
-
this.styleTilesetFeatureFullData(entity, null);
|
|
450
|
-
};
|
|
451
|
-
CadStyler.prototype.styleTilesetFeatureFullData = function (entity, data) {
|
|
452
|
-
var _a;
|
|
453
|
-
var style = this.getTilesetFeatureStyle(entity.entityId, entity.entityTypeId);
|
|
454
|
-
if (!style) {
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
var bColor = (((_a = style.modelStyle) === null || _a === void 0 ? void 0 : _a.fillColor) ? bruce_models_1.Calculator.GetValue(style.modelStyle.fillColor, data, []) : null);
|
|
458
|
-
if (bColor != null) {
|
|
459
|
-
var cColor = colorToCColor(bColor);
|
|
460
|
-
var visual = entity.visual;
|
|
461
|
-
if (visual && visual instanceof Cesium.Cesium3DTileFeature) {
|
|
462
|
-
visual.color = cColor;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
CadStyler.prototype.getTilesetFeatureStyle = function (entityId, entityTypeId) {
|
|
467
|
-
var _a, _b, _c;
|
|
468
|
-
// Locate what style is applicable to the feature.
|
|
469
|
-
var style = null;
|
|
470
|
-
if (entityTypeId) {
|
|
471
|
-
style = (_a = this.styleMapping.find(function (x) { return x.EntityTypeID == entityTypeId; })) === null || _a === void 0 ? void 0 : _a.style;
|
|
472
|
-
}
|
|
473
|
-
if (!style) {
|
|
474
|
-
style = this.fallbackStyle;
|
|
475
|
-
}
|
|
476
|
-
if (!style) {
|
|
477
|
-
return null;
|
|
478
|
-
}
|
|
479
|
-
if (!((_c = (_b = style.Settings) === null || _b === void 0 ? void 0 : _b.modelStyle) === null || _c === void 0 ? void 0 : _c.customize)) {
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
return style.Settings;
|
|
483
|
-
};
|
|
484
|
-
CadStyler.prototype.getTilesetFeatureNeedsFullData = function (entityId, entityTypeId) {
|
|
485
|
-
var _a;
|
|
486
|
-
var style = this.getTilesetFeatureStyle(entityId, entityTypeId);
|
|
487
|
-
if (!style) {
|
|
488
|
-
return false;
|
|
489
|
-
}
|
|
490
|
-
var fill = (_a = style === null || style === void 0 ? void 0 : style.modelStyle) === null || _a === void 0 ? void 0 : _a.fillColor;
|
|
491
|
-
if (!fill || fill.length <= 0) {
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
return fill[0].type != 0;
|
|
495
|
-
};
|
|
496
|
-
return CadStyler;
|
|
497
|
-
}());
|
|
498
|
-
TilesetRenderEngine.CadStyler = CadStyler;
|
|
499
|
-
})(TilesetRenderEngine = exports.TilesetRenderEngine || (exports.TilesetRenderEngine = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.TilesetRenderEngine = void 0;
|
|
51
|
+
var bruce_models_1 = require("bruce-models");
|
|
52
|
+
var Cesium = require("cesium");
|
|
53
|
+
function colorToCColor(color) {
|
|
54
|
+
return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
|
|
55
|
+
}
|
|
56
|
+
var TilesetRenderEngine;
|
|
57
|
+
(function (TilesetRenderEngine) {
|
|
58
|
+
function ApplyPosition(cTileset, tileset, coords) {
|
|
59
|
+
if (tileset.type == bruce_models_1.Tileset.EType.Cad) {
|
|
60
|
+
var settings = tileset.settings;
|
|
61
|
+
var location_1;
|
|
62
|
+
var transform = void 0;
|
|
63
|
+
// Position using root entity + ucs.
|
|
64
|
+
if (coords === null || coords === void 0 ? void 0 : coords.ucs) {
|
|
65
|
+
location_1 = coords.ucs.location;
|
|
66
|
+
transform = coords.transform;
|
|
67
|
+
}
|
|
68
|
+
// Position using tileset.
|
|
69
|
+
else {
|
|
70
|
+
transform = settings.transform;
|
|
71
|
+
location_1 = settings.location;
|
|
72
|
+
}
|
|
73
|
+
if (!(location_1 === null || location_1 === void 0 ? void 0 : location_1.latitude)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
transform = __assign({ heading: 0, pitch: 0, roll: 0, scale: 1, x: 0, y: 0, z: 0 }, transform);
|
|
77
|
+
if (transform.scale <= 0) {
|
|
78
|
+
transform.scale = 0.000001;
|
|
79
|
+
}
|
|
80
|
+
var pos = Cesium.Cartesian3.fromDegrees(location_1.longitude, location_1.latitude, location_1.altitude);
|
|
81
|
+
var hpr = Cesium.HeadingPitchRoll.fromDegrees(transform.heading, transform.pitch, transform.roll, new Cesium.HeadingPitchRoll());
|
|
82
|
+
var root = cTileset.root;
|
|
83
|
+
root.transform = Cesium.Transforms.headingPitchRollToFixedFrame(pos, hpr);
|
|
84
|
+
var scaleMatrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(transform.scale, transform.scale, transform.scale), new Cesium.Matrix4());
|
|
85
|
+
root.transform = Cesium.Matrix4.multiply(root.transform, scaleMatrix, root.transform);
|
|
86
|
+
root.transform = Cesium.Matrix4.multiplyByTranslation(root.transform, new Cesium.Cartesian3(transform.x, transform.y, transform.z), root.transform);
|
|
87
|
+
// Force matrix to update
|
|
88
|
+
root.updateTransform();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw ("Not implemented.");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
TilesetRenderEngine.ApplyPosition = ApplyPosition;
|
|
95
|
+
function ApplySettings(cTileset, tileset) {
|
|
96
|
+
if (tileset.type == bruce_models_1.Tileset.EType.Cad) {
|
|
97
|
+
var settings = tileset.settings;
|
|
98
|
+
var maxScreenSpaceError = settings.maximumScreenSpaceError;
|
|
99
|
+
if (maxScreenSpaceError || maxScreenSpaceError == 0) {
|
|
100
|
+
cTileset.maximumScreenSpaceError = maxScreenSpaceError;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw ("Not implemented.");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
TilesetRenderEngine.ApplySettings = ApplySettings;
|
|
108
|
+
function Render(params) {
|
|
109
|
+
var api = params.apiGetter.getApi(params.apiGetter.accountId);
|
|
110
|
+
if (params.tileset.type == bruce_models_1.Tileset.EType.Cad) {
|
|
111
|
+
var cTileset_1 = new Cesium.Cesium3DTileset({
|
|
112
|
+
url: bruce_models_1.Tileset.GetPublicFileUrl(api, params.tileset.id, "tileset.json") + "?generation=" + params.tileset.generateVersion
|
|
113
|
+
});
|
|
114
|
+
params.viewer.scene.primitives.add(cTileset_1);
|
|
115
|
+
cTileset_1.readyPromise.then(function () {
|
|
116
|
+
ApplySettings(cTileset_1, params.tileset);
|
|
117
|
+
ApplyPosition(cTileset_1, params.tileset, params.coords);
|
|
118
|
+
});
|
|
119
|
+
return cTileset_1;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
throw ("Not implemented.");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
TilesetRenderEngine.Render = Render;
|
|
126
|
+
var CadStyler = /** @class */ (function () {
|
|
127
|
+
function CadStyler(api, cTileset, fallbackStyleId, styleMapping) {
|
|
128
|
+
this.disposed = false;
|
|
129
|
+
this.loadedEntities = {};
|
|
130
|
+
this.styleMappingLoaded = false;
|
|
131
|
+
this.styleMappingsLoaded = {};
|
|
132
|
+
this.fallbackStyle = null;
|
|
133
|
+
this.runningQueues = 0;
|
|
134
|
+
this.recordLoadQueue = [];
|
|
135
|
+
this.recordCheckQueue = [];
|
|
136
|
+
this.api = api;
|
|
137
|
+
this.cTileset = cTileset;
|
|
138
|
+
this.fallbackStyleId = fallbackStyleId;
|
|
139
|
+
this.styleMapping = styleMapping;
|
|
140
|
+
this.loadStyles();
|
|
141
|
+
}
|
|
142
|
+
Object.defineProperty(CadStyler.prototype, "Disposed", {
|
|
143
|
+
get: function () {
|
|
144
|
+
return this.disposed;
|
|
145
|
+
},
|
|
146
|
+
enumerable: false,
|
|
147
|
+
configurable: true
|
|
148
|
+
});
|
|
149
|
+
CadStyler.prototype.QueueEntities = function (entities) {
|
|
150
|
+
for (var i = 0; i < entities.length; i++) {
|
|
151
|
+
var entity = entities[i];
|
|
152
|
+
this.queueTilesetFeatureStyle(entity);
|
|
153
|
+
}
|
|
154
|
+
if (this.recordLoadQueue.length > 0) {
|
|
155
|
+
this.processQueue();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
CadStyler.prototype.processQueue = function () {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
+
var MAX_BATCHES, BATCH_DELAY, batch, rerun, entityIds, entities, _loop_1, this_1, i;
|
|
161
|
+
var _this = this;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
MAX_BATCHES = 2;
|
|
166
|
+
BATCH_DELAY = 200;
|
|
167
|
+
if (this.runningQueues >= MAX_BATCHES) {
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
else if (this.disposed) {
|
|
171
|
+
return [2 /*return*/];
|
|
172
|
+
}
|
|
173
|
+
this.runningQueues += 1;
|
|
174
|
+
batch = [];
|
|
175
|
+
rerun = false;
|
|
176
|
+
_a.label = 1;
|
|
177
|
+
case 1:
|
|
178
|
+
_a.trys.push([1, , 4, 5]);
|
|
179
|
+
batch = this.getEntitiesForQueue();
|
|
180
|
+
entityIds = batch.map(function (x) { return x.entityId; });
|
|
181
|
+
if (!(entityIds.length > 0)) return [3 /*break*/, 3];
|
|
182
|
+
return [4 /*yield*/, bruce_models_1.Entity.GetListByIds(this.api, entityIds)];
|
|
183
|
+
case 2:
|
|
184
|
+
entities = _a.sent();
|
|
185
|
+
_loop_1 = function (i) {
|
|
186
|
+
var record = entities[i];
|
|
187
|
+
var feature = batch.find(function (x) { var _a; return (x === null || x === void 0 ? void 0 : x.entityId) == ((_a = record === null || record === void 0 ? void 0 : record.Bruce) === null || _a === void 0 ? void 0 : _a.ID); });
|
|
188
|
+
if (feature) {
|
|
189
|
+
this_1.styleTilesetFeatureFullData(feature, record);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
this_1 = this;
|
|
193
|
+
for (i = 0; i < entities.length; i++) {
|
|
194
|
+
_loop_1(i);
|
|
195
|
+
}
|
|
196
|
+
rerun = batch.length > 0;
|
|
197
|
+
_a.label = 3;
|
|
198
|
+
case 3: return [3 /*break*/, 5];
|
|
199
|
+
case 4:
|
|
200
|
+
setTimeout(function () {
|
|
201
|
+
_this.runningQueues -= 1;
|
|
202
|
+
if (rerun) {
|
|
203
|
+
_this.processQueue();
|
|
204
|
+
}
|
|
205
|
+
}, BATCH_DELAY);
|
|
206
|
+
return [7 /*endfinally*/];
|
|
207
|
+
case 5: return [2 /*return*/];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
CadStyler.prototype.getEntitiesForQueue = function () {
|
|
213
|
+
var BATCH_SIZE = 30;
|
|
214
|
+
var batchHashes = this.recordLoadQueue.splice(0, BATCH_SIZE);
|
|
215
|
+
var entities = [];
|
|
216
|
+
for (var i = 0; i < batchHashes.length; i++) {
|
|
217
|
+
var id = batchHashes[i];
|
|
218
|
+
var entity = this.loadedEntities[id];
|
|
219
|
+
if (entity) {
|
|
220
|
+
entities.push(entity);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return entities;
|
|
224
|
+
};
|
|
225
|
+
CadStyler.prototype.Dispose = function () {
|
|
226
|
+
if (this.disposed) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.disposed = true;
|
|
230
|
+
clearInterval(this.queueLoadInterval);
|
|
231
|
+
clearInterval(this.queueCheckInterval);
|
|
232
|
+
};
|
|
233
|
+
CadStyler.prototype.loadStyles = function () {
|
|
234
|
+
var _a, _b;
|
|
235
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
236
|
+
var fallbackStyleId, data, e_1, styleMapping, modelTree, entityTypeIds, _loop_2, i, i, styleMap, styleId, entityType, e_2, data, e_3;
|
|
237
|
+
return __generator(this, function (_c) {
|
|
238
|
+
switch (_c.label) {
|
|
239
|
+
case 0:
|
|
240
|
+
fallbackStyleId = this.fallbackStyleId;
|
|
241
|
+
if (!(fallbackStyleId && fallbackStyleId > 0)) return [3 /*break*/, 4];
|
|
242
|
+
_c.label = 1;
|
|
243
|
+
case 1:
|
|
244
|
+
_c.trys.push([1, 3, , 4]);
|
|
245
|
+
return [4 /*yield*/, bruce_models_1.Style.Get(this.api, fallbackStyleId)];
|
|
246
|
+
case 2:
|
|
247
|
+
data = _c.sent();
|
|
248
|
+
this.fallbackStyle = data;
|
|
249
|
+
return [3 /*break*/, 4];
|
|
250
|
+
case 3:
|
|
251
|
+
e_1 = _c.sent();
|
|
252
|
+
console.error(e_1);
|
|
253
|
+
return [3 /*break*/, 4];
|
|
254
|
+
case 4:
|
|
255
|
+
styleMapping = this.styleMapping;
|
|
256
|
+
if (!styleMapping) {
|
|
257
|
+
styleMapping = [];
|
|
258
|
+
}
|
|
259
|
+
this.styleMapping = styleMapping;
|
|
260
|
+
// It is default style.
|
|
261
|
+
// We have to get all possible entity type ids and append them to mapping.
|
|
262
|
+
if (!fallbackStyleId) {
|
|
263
|
+
try {
|
|
264
|
+
modelTree = (_b = (_a = this.cTileset) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.modelTree;
|
|
265
|
+
if (modelTree) {
|
|
266
|
+
entityTypeIds = this.getEntityTypeIdsFromModelTree(modelTree);
|
|
267
|
+
_loop_2 = function (i) {
|
|
268
|
+
var entityTypeId = entityTypeIds[i];
|
|
269
|
+
if (styleMapping.findIndex(function (x) { return x.EntityTypeID == entityTypeId; }) <= -1) {
|
|
270
|
+
styleMapping.push({
|
|
271
|
+
EntityTypeID: entityTypeId,
|
|
272
|
+
StyleID: null,
|
|
273
|
+
style: null
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
for (i = 0; i < entityTypeIds.length; i++) {
|
|
278
|
+
_loop_2(i);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (e) {
|
|
283
|
+
console.log(e);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
i = 0;
|
|
287
|
+
_c.label = 5;
|
|
288
|
+
case 5:
|
|
289
|
+
if (!(i < styleMapping.length)) return [3 /*break*/, 15];
|
|
290
|
+
if (this.disposed) {
|
|
291
|
+
return [3 /*break*/, 15];
|
|
292
|
+
}
|
|
293
|
+
styleMap = styleMapping[i];
|
|
294
|
+
if (!!styleMap.style) return [3 /*break*/, 13];
|
|
295
|
+
styleId = styleMap.StyleID;
|
|
296
|
+
if (!!styleId) return [3 /*break*/, 9];
|
|
297
|
+
_c.label = 6;
|
|
298
|
+
case 6:
|
|
299
|
+
_c.trys.push([6, 8, , 9]);
|
|
300
|
+
return [4 /*yield*/, bruce_models_1.EntityType.Get(this.api, styleMap.EntityTypeID)];
|
|
301
|
+
case 7:
|
|
302
|
+
entityType = _c.sent();
|
|
303
|
+
styleId = entityType === null || entityType === void 0 ? void 0 : entityType["DisplaySetting.ID"];
|
|
304
|
+
return [3 /*break*/, 9];
|
|
305
|
+
case 8:
|
|
306
|
+
e_2 = _c.sent();
|
|
307
|
+
console.error(e_2);
|
|
308
|
+
return [3 /*break*/, 9];
|
|
309
|
+
case 9:
|
|
310
|
+
if (!styleId) return [3 /*break*/, 13];
|
|
311
|
+
_c.label = 10;
|
|
312
|
+
case 10:
|
|
313
|
+
_c.trys.push([10, 12, , 13]);
|
|
314
|
+
return [4 /*yield*/, bruce_models_1.Style.Get(this.api, styleId)];
|
|
315
|
+
case 11:
|
|
316
|
+
data = _c.sent();
|
|
317
|
+
if (data) {
|
|
318
|
+
styleMap.style = data;
|
|
319
|
+
styleMap.StyleID = styleId;
|
|
320
|
+
}
|
|
321
|
+
return [3 /*break*/, 13];
|
|
322
|
+
case 12:
|
|
323
|
+
e_3 = _c.sent();
|
|
324
|
+
console.error(e_3);
|
|
325
|
+
return [3 /*break*/, 13];
|
|
326
|
+
case 13:
|
|
327
|
+
if (styleMap.EntityTypeID && styleMap.style) {
|
|
328
|
+
this.styleMappingsLoaded[styleMap.EntityTypeID] = true;
|
|
329
|
+
this.processTilesetFeatureCheckQueue();
|
|
330
|
+
this.processQueue();
|
|
331
|
+
}
|
|
332
|
+
_c.label = 14;
|
|
333
|
+
case 14:
|
|
334
|
+
i++;
|
|
335
|
+
return [3 /*break*/, 5];
|
|
336
|
+
case 15:
|
|
337
|
+
this.styleMappingLoaded = true;
|
|
338
|
+
if (!!this.disposed) return [3 /*break*/, 17];
|
|
339
|
+
return [4 /*yield*/, this.processTilesetFeatureCheckQueue()];
|
|
340
|
+
case 16:
|
|
341
|
+
_c.sent();
|
|
342
|
+
this.processQueue();
|
|
343
|
+
_c.label = 17;
|
|
344
|
+
case 17: return [2 /*return*/];
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
CadStyler.prototype.getEntityTypeIdsFromModelTree = function (modelTree) {
|
|
350
|
+
var entityTypeIds = [];
|
|
351
|
+
this.digEntityTypeIdsFromModelTreeBranch(modelTree, entityTypeIds);
|
|
352
|
+
return entityTypeIds;
|
|
353
|
+
};
|
|
354
|
+
CadStyler.prototype.digEntityTypeIdsFromModelTreeBranch = function (branch, arr) {
|
|
355
|
+
if (branch) {
|
|
356
|
+
// Does not yet include this entity type id.
|
|
357
|
+
if (branch.typeId && !arr.includes(branch.typeId)) {
|
|
358
|
+
arr.push(branch.typeId);
|
|
359
|
+
}
|
|
360
|
+
if (branch.children) {
|
|
361
|
+
for (var i = 0; i < branch.children.length; i++) {
|
|
362
|
+
var child = branch.children[i];
|
|
363
|
+
this.digEntityTypeIdsFromModelTreeBranch(child, arr);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
CadStyler.prototype.processTilesetFeatureCheckQueue = function () {
|
|
369
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
370
|
+
var BATCH_CHECK_SIZE;
|
|
371
|
+
var _this = this;
|
|
372
|
+
return __generator(this, function (_a) {
|
|
373
|
+
BATCH_CHECK_SIZE = 1000;
|
|
374
|
+
return [2 /*return*/, new Promise(function (res) {
|
|
375
|
+
clearInterval(_this.queueCheckInterval);
|
|
376
|
+
_this.queueCheckInterval = setInterval(function () {
|
|
377
|
+
if (_this.disposed) {
|
|
378
|
+
clearInterval(_this.queueCheckInterval);
|
|
379
|
+
res();
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
// Construct batch for loaded styles.
|
|
383
|
+
var batch = [];
|
|
384
|
+
if (_this.styleMappingLoaded) {
|
|
385
|
+
batch = _this.recordCheckQueue.splice(0, BATCH_CHECK_SIZE);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
for (var i = 0; i < _this.recordCheckQueue.length; i++) {
|
|
389
|
+
var hash = _this.recordCheckQueue[i];
|
|
390
|
+
var entity = _this.loadedEntities[hash];
|
|
391
|
+
if (entity) {
|
|
392
|
+
var entityTypeId = entity.entityTypeId;
|
|
393
|
+
if (entityTypeId) {
|
|
394
|
+
if (_this.styleMappingsLoaded[entityTypeId] == true) {
|
|
395
|
+
batch.push(hash);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (batch.length >= BATCH_CHECK_SIZE) {
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
var _loop_3 = function (i) {
|
|
404
|
+
var hash = batch[i];
|
|
405
|
+
var index = _this.recordCheckQueue.findIndex(function (x) { return x == hash; });
|
|
406
|
+
if (index > -1) {
|
|
407
|
+
_this.recordCheckQueue.splice(index, 1);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
for (var i = 0; i < batch.length; i++) {
|
|
411
|
+
_loop_3(i);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (batch.length) {
|
|
415
|
+
for (var i = 0; i < batch.length; i++) {
|
|
416
|
+
var item = batch[i];
|
|
417
|
+
var entity = _this.loadedEntities[item];
|
|
418
|
+
if (entity) {
|
|
419
|
+
_this.queueTilesetFeatureStyle(entity);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
clearInterval(_this.queueCheckInterval);
|
|
425
|
+
res();
|
|
426
|
+
}
|
|
427
|
+
}, 50);
|
|
428
|
+
})];
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
CadStyler.prototype.queueTilesetFeatureStyle = function (entity) {
|
|
433
|
+
if (this.styleMappingLoaded || this.styleMappingsLoaded[entity.entityTypeId] == true) {
|
|
434
|
+
var needsData = this.getTilesetFeatureNeedsFullData(entity.entityId, entity.entityTypeId);
|
|
435
|
+
if (needsData) {
|
|
436
|
+
if (this.recordLoadQueue.findIndex(function (x) { return x == entity.entityId; })) {
|
|
437
|
+
this.recordLoadQueue.push(entity.entityId);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
this.styleTilesetFeature(entity);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
this.recordCheckQueue.push(entity.entityId);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
CadStyler.prototype.styleTilesetFeature = function (entity) {
|
|
449
|
+
this.styleTilesetFeatureFullData(entity, null);
|
|
450
|
+
};
|
|
451
|
+
CadStyler.prototype.styleTilesetFeatureFullData = function (entity, data) {
|
|
452
|
+
var _a;
|
|
453
|
+
var style = this.getTilesetFeatureStyle(entity.entityId, entity.entityTypeId);
|
|
454
|
+
if (!style) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
var bColor = (((_a = style.modelStyle) === null || _a === void 0 ? void 0 : _a.fillColor) ? bruce_models_1.Calculator.GetValue(style.modelStyle.fillColor, data, []) : null);
|
|
458
|
+
if (bColor != null) {
|
|
459
|
+
var cColor = colorToCColor(bColor);
|
|
460
|
+
var visual = entity.visual;
|
|
461
|
+
if (visual && visual instanceof Cesium.Cesium3DTileFeature) {
|
|
462
|
+
visual.color = cColor;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
CadStyler.prototype.getTilesetFeatureStyle = function (entityId, entityTypeId) {
|
|
467
|
+
var _a, _b, _c;
|
|
468
|
+
// Locate what style is applicable to the feature.
|
|
469
|
+
var style = null;
|
|
470
|
+
if (entityTypeId) {
|
|
471
|
+
style = (_a = this.styleMapping.find(function (x) { return x.EntityTypeID == entityTypeId; })) === null || _a === void 0 ? void 0 : _a.style;
|
|
472
|
+
}
|
|
473
|
+
if (!style) {
|
|
474
|
+
style = this.fallbackStyle;
|
|
475
|
+
}
|
|
476
|
+
if (!style) {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
if (!((_c = (_b = style.Settings) === null || _b === void 0 ? void 0 : _b.modelStyle) === null || _c === void 0 ? void 0 : _c.customize)) {
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
return style.Settings;
|
|
483
|
+
};
|
|
484
|
+
CadStyler.prototype.getTilesetFeatureNeedsFullData = function (entityId, entityTypeId) {
|
|
485
|
+
var _a;
|
|
486
|
+
var style = this.getTilesetFeatureStyle(entityId, entityTypeId);
|
|
487
|
+
if (!style) {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
var fill = (_a = style === null || style === void 0 ? void 0 : style.modelStyle) === null || _a === void 0 ? void 0 : _a.fillColor;
|
|
491
|
+
if (!fill || fill.length <= 0) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
return fill[0].type != 0;
|
|
495
|
+
};
|
|
496
|
+
return CadStyler;
|
|
497
|
+
}());
|
|
498
|
+
TilesetRenderEngine.CadStyler = CadStyler;
|
|
499
|
+
})(TilesetRenderEngine = exports.TilesetRenderEngine || (exports.TilesetRenderEngine = {}));
|
|
500
500
|
//# sourceMappingURL=tileset-render-engine.js.map
|