bruce-cesium 0.4.1 → 0.4.2
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 +9 -1
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +8 -0
- 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/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 -296
- 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-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/entity-render-manager.js +139 -139
- 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-osm-render-manager.js +320 -320
- package/dist/lib/rendering/tile-render-engine.js +815 -815
- package/dist/lib/rendering/tileset-render-engine.js +499 -499
- package/dist/lib/rendering/view-render-engine.js +305 -305
- package/dist/lib/rendering/visuals-register.js +402 -394
- package/dist/lib/rendering/visuals-register.js.map +1 -1
- 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 +72 -72
- package/dist/lib/viewer/cesium-view-monitor.js +231 -231
- package/dist/lib/viewer/viewer-utils.js +85 -85
- package/dist/types/rendering/visuals-register.d.ts +2 -0
- package/package.json +76 -76
|
@@ -1,321 +1,321 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.TilesetOsmRenderManager = void 0;
|
|
40
|
-
var bruce_models_1 = require("bruce-models");
|
|
41
|
-
var Cesium = require("cesium");
|
|
42
|
-
var MAX_BATCHES = 2;
|
|
43
|
-
var BATCH_SIZE = 30;
|
|
44
|
-
var BATCH_DELAY = 200;
|
|
45
|
-
var MAX_RANGE = 3000;
|
|
46
|
-
var TilesetOsmRenderManager;
|
|
47
|
-
(function (TilesetOsmRenderManager) {
|
|
48
|
-
var Manager = /** @class */ (function () {
|
|
49
|
-
function Manager(viewer, visualsManager, apiGetter, monitor, item) {
|
|
50
|
-
this.disposed = false;
|
|
51
|
-
this.cTileset = null;
|
|
52
|
-
this.counter = 0;
|
|
53
|
-
this._loadedCesiumEntities = {};
|
|
54
|
-
this.totalLoaded = 0;
|
|
55
|
-
this.featureQueue = [];
|
|
56
|
-
this.sourceId = null;
|
|
57
|
-
this.entityTypeId = null;
|
|
58
|
-
this.queueCheckInterval = null;
|
|
59
|
-
this.processingQueue = 0;
|
|
60
|
-
this.viewer = viewer;
|
|
61
|
-
this.apiGetter = apiGetter;
|
|
62
|
-
this.item = item;
|
|
63
|
-
this.visualsManager = visualsManager;
|
|
64
|
-
this.monitor = monitor;
|
|
65
|
-
}
|
|
66
|
-
Object.defineProperty(Manager.prototype, "Disposed", {
|
|
67
|
-
get: function () {
|
|
68
|
-
return this.disposed;
|
|
69
|
-
},
|
|
70
|
-
enumerable: false,
|
|
71
|
-
configurable: true
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(Manager.prototype, "count", {
|
|
74
|
-
get: function () {
|
|
75
|
-
return ++this.counter;
|
|
76
|
-
},
|
|
77
|
-
enumerable: false,
|
|
78
|
-
configurable: true
|
|
79
|
-
});
|
|
80
|
-
Manager.prototype.Dispose = function () {
|
|
81
|
-
if (this.disposed) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
clearInterval(this.queueCheckInterval);
|
|
85
|
-
if (this.cTileset) {
|
|
86
|
-
this.cTileset.show = false;
|
|
87
|
-
}
|
|
88
|
-
this.visualsManager.RemoveByMenuItemId(this.item.id);
|
|
89
|
-
this.featureQueue = [];
|
|
90
|
-
};
|
|
91
|
-
Manager.prototype.Init = function () {
|
|
92
|
-
var _a, _b;
|
|
93
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
-
var menuItem;
|
|
95
|
-
var _this = this;
|
|
96
|
-
return __generator(this, function (_c) {
|
|
97
|
-
menuItem = this.item;
|
|
98
|
-
this.sourceId = (_a = menuItem.BruceEntity) === null || _a === void 0 ? void 0 : _a.SourceId;
|
|
99
|
-
this.entityTypeId = (_b = menuItem.BruceEntity) === null || _b === void 0 ? void 0 : _b["EntityType.ID"];
|
|
100
|
-
this.cTileset = Cesium.createOsmBuildings();
|
|
101
|
-
this.cTileset.show = true;
|
|
102
|
-
if (this.sourceId) {
|
|
103
|
-
if (menuItem.ghostLoading == true) {
|
|
104
|
-
this.cTileset.style = new Cesium.Cesium3DTileStyle({
|
|
105
|
-
color: "rgba(255, 255, 250, 0.98)"
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
this.viewer.scene.primitives.add(this.cTileset);
|
|
109
|
-
this.cTileset.tileLoad.addEventListener(function (tile) {
|
|
110
|
-
_this.mapCTile(tile);
|
|
111
|
-
});
|
|
112
|
-
this.queueCheckInterval = setInterval(function () {
|
|
113
|
-
if (_this.featureQueue.length > 0) {
|
|
114
|
-
_this.processQueue();
|
|
115
|
-
}
|
|
116
|
-
}, 5000);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this.viewer.scene.primitives.add(this.cTileset);
|
|
120
|
-
}
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
Manager.prototype.mapCTile = function (tile) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
-
var content, i, feature;
|
|
128
|
-
return __generator(this, function (_a) {
|
|
129
|
-
if (this.sourceId) {
|
|
130
|
-
content = tile.content;
|
|
131
|
-
for (i = 0; i < content.featuresLength; i++) {
|
|
132
|
-
feature = content.getFeature(i);
|
|
133
|
-
if (feature._counter == null) {
|
|
134
|
-
feature._counter = this.count;
|
|
135
|
-
}
|
|
136
|
-
if (feature._orgColor == null) {
|
|
137
|
-
feature._orgColor = feature.color;
|
|
138
|
-
}
|
|
139
|
-
this.featureQueue.push(feature);
|
|
140
|
-
}
|
|
141
|
-
this.processQueue();
|
|
142
|
-
}
|
|
143
|
-
return [2 /*return*/];
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
Manager.prototype.processQueue = function () {
|
|
148
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
-
var batch, rerun, e_1;
|
|
150
|
-
var _this = this;
|
|
151
|
-
return __generator(this, function (_a) {
|
|
152
|
-
switch (_a.label) {
|
|
153
|
-
case 0:
|
|
154
|
-
if (this.processingQueue >= MAX_BATCHES) {
|
|
155
|
-
return [2 /*return*/];
|
|
156
|
-
}
|
|
157
|
-
else if (this.Disposed) {
|
|
158
|
-
return [2 /*return*/];
|
|
159
|
-
}
|
|
160
|
-
this.processingQueue += 1;
|
|
161
|
-
batch = [];
|
|
162
|
-
rerun = false;
|
|
163
|
-
_a.label = 1;
|
|
164
|
-
case 1:
|
|
165
|
-
_a.trys.push([1, 4, 5, 6]);
|
|
166
|
-
batch = this.getVisualsForBatch();
|
|
167
|
-
if (!(batch.length > 0)) return [3 /*break*/, 3];
|
|
168
|
-
return [4 /*yield*/, this.mapTileBatch(batch)];
|
|
169
|
-
case 2:
|
|
170
|
-
_a.sent();
|
|
171
|
-
_a.label = 3;
|
|
172
|
-
case 3:
|
|
173
|
-
if (this.totalLoaded > 8000) {
|
|
174
|
-
rerun = this.removeFarAwayBatch();
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
rerun = this.featureQueue.length > 0 && batch.length > 0;
|
|
178
|
-
}
|
|
179
|
-
return [3 /*break*/, 6];
|
|
180
|
-
case 4:
|
|
181
|
-
e_1 = _a.sent();
|
|
182
|
-
console.error(e_1);
|
|
183
|
-
return [3 /*break*/, 6];
|
|
184
|
-
case 5:
|
|
185
|
-
setTimeout(function () {
|
|
186
|
-
_this.processingQueue -= 1;
|
|
187
|
-
if (rerun) {
|
|
188
|
-
_this.processQueue();
|
|
189
|
-
}
|
|
190
|
-
}, BATCH_DELAY);
|
|
191
|
-
return [7 /*endfinally*/];
|
|
192
|
-
case 6: return [2 /*return*/];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
Manager.prototype.getVisualsForBatch = function () {
|
|
198
|
-
var batch = [];
|
|
199
|
-
var features = this.featureQueue;
|
|
200
|
-
var bounds = this.monitor.GetBounds();
|
|
201
|
-
var rect = (bounds === null || bounds === void 0 ? void 0 : bounds.east) ? new Cesium.Rectangle(Cesium.Math.toRadians(bounds.west), Cesium.Math.toRadians(bounds.south), Cesium.Math.toRadians(bounds.east), Cesium.Math.toRadians(bounds.north)) : null;
|
|
202
|
-
if (rect) {
|
|
203
|
-
for (var i = 0; i < features.length; i++) {
|
|
204
|
-
var feature = features[i];
|
|
205
|
-
if (feature) {
|
|
206
|
-
var featureLon = feature.getProperty("cesium#longitude");
|
|
207
|
-
var featureLat = feature.getProperty("cesium#latitude");
|
|
208
|
-
if (featureLon && featureLat) {
|
|
209
|
-
var carto = Cesium.Cartographic.fromDegrees(featureLon, featureLat, 0);
|
|
210
|
-
var isIn = Cesium.Rectangle.contains(rect, carto);
|
|
211
|
-
if (isIn) {
|
|
212
|
-
var isClose = this.getIsVisualWithinRange(feature, MAX_RANGE);
|
|
213
|
-
if (isClose) {
|
|
214
|
-
batch.push(feature);
|
|
215
|
-
if (batch.length >= BATCH_SIZE) {
|
|
216
|
-
return batch;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return batch;
|
|
225
|
-
};
|
|
226
|
-
Manager.prototype.getIsVisualWithinRange = function (visual, range) {
|
|
227
|
-
var featureLon = visual.getProperty("cesium#longitude");
|
|
228
|
-
var featureLat = visual.getProperty("cesium#latitude");
|
|
229
|
-
if (featureLon && featureLat) {
|
|
230
|
-
var pos = Cesium.Cartesian3.fromDegrees(featureLon, featureLat, 0);
|
|
231
|
-
var camPoint = this.monitor.GetTarget();
|
|
232
|
-
var camPos = (camPoint === null || camPoint === void 0 ? void 0 : camPoint.latitude) ? Cesium.Cartesian3.fromDegrees(camPoint.longitude, camPoint.latitude, camPoint.altitude) : null;
|
|
233
|
-
if (camPos && bruce_models_1.Cartes.ValidateCartes3(camPos) && bruce_models_1.Cartes.ValidateCartes3(pos)) {
|
|
234
|
-
var distance = Cesium.Cartesian3.distance(pos, camPos);
|
|
235
|
-
if (distance != null && distance <= range) {
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return false;
|
|
241
|
-
};
|
|
242
|
-
Manager.prototype.mapTileBatch = function (features) {
|
|
243
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
244
|
-
var featureIds, featureMap, _loop_1, this_1, i, api, bIds, i, id, bId, feature, rego;
|
|
245
|
-
return __generator(this, function (_a) {
|
|
246
|
-
switch (_a.label) {
|
|
247
|
-
case 0:
|
|
248
|
-
featureIds = [];
|
|
249
|
-
featureMap = [];
|
|
250
|
-
_loop_1 = function (i) {
|
|
251
|
-
var feature = features[i];
|
|
252
|
-
var featureId = feature.getProperty("elementId");
|
|
253
|
-
if (featureId) {
|
|
254
|
-
featureMap.push(feature);
|
|
255
|
-
featureIds.push(featureId + "");
|
|
256
|
-
}
|
|
257
|
-
var index = this_1.featureQueue.findIndex(function (x) { return x._counter == feature._counter; });
|
|
258
|
-
if (index > -1) {
|
|
259
|
-
this_1.featureQueue.splice(index, 1);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
this_1 = this;
|
|
263
|
-
for (i = 0; i < features.length; i++) {
|
|
264
|
-
_loop_1(i);
|
|
265
|
-
}
|
|
266
|
-
api = this.apiGetter.getApi();
|
|
267
|
-
return [4 /*yield*/, bruce_models_1.EntitySource.GetEntityIdsBySourceKeys(api, this.sourceId, featureIds)];
|
|
268
|
-
case 1:
|
|
269
|
-
bIds = _a.sent();
|
|
270
|
-
for (i = 0; i < featureIds.length; i++) {
|
|
271
|
-
id = featureIds[i];
|
|
272
|
-
bId = bIds[id];
|
|
273
|
-
if (!bId) {
|
|
274
|
-
bId = bruce_models_1.ObjectUtils.UId();
|
|
275
|
-
}
|
|
276
|
-
feature = featureMap[i];
|
|
277
|
-
if (this.item.ghostLoading == true) {
|
|
278
|
-
feature.color = feature._orgColor;
|
|
279
|
-
}
|
|
280
|
-
rego = {
|
|
281
|
-
entityId: bId,
|
|
282
|
-
menuItemId: this.item.id,
|
|
283
|
-
priority: 0,
|
|
284
|
-
visual: feature,
|
|
285
|
-
entityTypeId: this.entityTypeId,
|
|
286
|
-
sourceId: this.sourceId
|
|
287
|
-
};
|
|
288
|
-
this.visualsManager.Add(rego);
|
|
289
|
-
this._loadedCesiumEntities[bId] = rego;
|
|
290
|
-
}
|
|
291
|
-
return [2 /*return*/];
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
Manager.prototype.removeFarAwayBatch = function () {
|
|
297
|
-
var removed = 0;
|
|
298
|
-
var keys = Object.keys(this._loadedCesiumEntities);
|
|
299
|
-
for (var i = 0; i < keys.length; i++) {
|
|
300
|
-
var key = keys[i];
|
|
301
|
-
var rego = this._loadedCesiumEntities[key];
|
|
302
|
-
if (rego) {
|
|
303
|
-
if (!this.getIsVisualWithinRange(rego.visual, MAX_RANGE)) {
|
|
304
|
-
this.visualsManager.Remove(rego.entityId, this.item.id);
|
|
305
|
-
this._loadedCesiumEntities[key] = null;
|
|
306
|
-
delete this._loadedCesiumEntities[key];
|
|
307
|
-
this.totalLoaded -= 1;
|
|
308
|
-
removed += 1;
|
|
309
|
-
if (removed >= BATCH_SIZE) {
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return removed > 0;
|
|
316
|
-
};
|
|
317
|
-
return Manager;
|
|
318
|
-
}());
|
|
319
|
-
TilesetOsmRenderManager.Manager = Manager;
|
|
320
|
-
})(TilesetOsmRenderManager = exports.TilesetOsmRenderManager || (exports.TilesetOsmRenderManager = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.TilesetOsmRenderManager = void 0;
|
|
40
|
+
var bruce_models_1 = require("bruce-models");
|
|
41
|
+
var Cesium = require("cesium");
|
|
42
|
+
var MAX_BATCHES = 2;
|
|
43
|
+
var BATCH_SIZE = 30;
|
|
44
|
+
var BATCH_DELAY = 200;
|
|
45
|
+
var MAX_RANGE = 3000;
|
|
46
|
+
var TilesetOsmRenderManager;
|
|
47
|
+
(function (TilesetOsmRenderManager) {
|
|
48
|
+
var Manager = /** @class */ (function () {
|
|
49
|
+
function Manager(viewer, visualsManager, apiGetter, monitor, item) {
|
|
50
|
+
this.disposed = false;
|
|
51
|
+
this.cTileset = null;
|
|
52
|
+
this.counter = 0;
|
|
53
|
+
this._loadedCesiumEntities = {};
|
|
54
|
+
this.totalLoaded = 0;
|
|
55
|
+
this.featureQueue = [];
|
|
56
|
+
this.sourceId = null;
|
|
57
|
+
this.entityTypeId = null;
|
|
58
|
+
this.queueCheckInterval = null;
|
|
59
|
+
this.processingQueue = 0;
|
|
60
|
+
this.viewer = viewer;
|
|
61
|
+
this.apiGetter = apiGetter;
|
|
62
|
+
this.item = item;
|
|
63
|
+
this.visualsManager = visualsManager;
|
|
64
|
+
this.monitor = monitor;
|
|
65
|
+
}
|
|
66
|
+
Object.defineProperty(Manager.prototype, "Disposed", {
|
|
67
|
+
get: function () {
|
|
68
|
+
return this.disposed;
|
|
69
|
+
},
|
|
70
|
+
enumerable: false,
|
|
71
|
+
configurable: true
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(Manager.prototype, "count", {
|
|
74
|
+
get: function () {
|
|
75
|
+
return ++this.counter;
|
|
76
|
+
},
|
|
77
|
+
enumerable: false,
|
|
78
|
+
configurable: true
|
|
79
|
+
});
|
|
80
|
+
Manager.prototype.Dispose = function () {
|
|
81
|
+
if (this.disposed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
clearInterval(this.queueCheckInterval);
|
|
85
|
+
if (this.cTileset) {
|
|
86
|
+
this.cTileset.show = false;
|
|
87
|
+
}
|
|
88
|
+
this.visualsManager.RemoveByMenuItemId(this.item.id);
|
|
89
|
+
this.featureQueue = [];
|
|
90
|
+
};
|
|
91
|
+
Manager.prototype.Init = function () {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var menuItem;
|
|
95
|
+
var _this = this;
|
|
96
|
+
return __generator(this, function (_c) {
|
|
97
|
+
menuItem = this.item;
|
|
98
|
+
this.sourceId = (_a = menuItem.BruceEntity) === null || _a === void 0 ? void 0 : _a.SourceId;
|
|
99
|
+
this.entityTypeId = (_b = menuItem.BruceEntity) === null || _b === void 0 ? void 0 : _b["EntityType.ID"];
|
|
100
|
+
this.cTileset = Cesium.createOsmBuildings();
|
|
101
|
+
this.cTileset.show = true;
|
|
102
|
+
if (this.sourceId) {
|
|
103
|
+
if (menuItem.ghostLoading == true) {
|
|
104
|
+
this.cTileset.style = new Cesium.Cesium3DTileStyle({
|
|
105
|
+
color: "rgba(255, 255, 250, 0.98)"
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
this.viewer.scene.primitives.add(this.cTileset);
|
|
109
|
+
this.cTileset.tileLoad.addEventListener(function (tile) {
|
|
110
|
+
_this.mapCTile(tile);
|
|
111
|
+
});
|
|
112
|
+
this.queueCheckInterval = setInterval(function () {
|
|
113
|
+
if (_this.featureQueue.length > 0) {
|
|
114
|
+
_this.processQueue();
|
|
115
|
+
}
|
|
116
|
+
}, 5000);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this.viewer.scene.primitives.add(this.cTileset);
|
|
120
|
+
}
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
Manager.prototype.mapCTile = function (tile) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
var content, i, feature;
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
if (this.sourceId) {
|
|
130
|
+
content = tile.content;
|
|
131
|
+
for (i = 0; i < content.featuresLength; i++) {
|
|
132
|
+
feature = content.getFeature(i);
|
|
133
|
+
if (feature._counter == null) {
|
|
134
|
+
feature._counter = this.count;
|
|
135
|
+
}
|
|
136
|
+
if (feature._orgColor == null) {
|
|
137
|
+
feature._orgColor = feature.color;
|
|
138
|
+
}
|
|
139
|
+
this.featureQueue.push(feature);
|
|
140
|
+
}
|
|
141
|
+
this.processQueue();
|
|
142
|
+
}
|
|
143
|
+
return [2 /*return*/];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
Manager.prototype.processQueue = function () {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var batch, rerun, e_1;
|
|
150
|
+
var _this = this;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
if (this.processingQueue >= MAX_BATCHES) {
|
|
155
|
+
return [2 /*return*/];
|
|
156
|
+
}
|
|
157
|
+
else if (this.Disposed) {
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
}
|
|
160
|
+
this.processingQueue += 1;
|
|
161
|
+
batch = [];
|
|
162
|
+
rerun = false;
|
|
163
|
+
_a.label = 1;
|
|
164
|
+
case 1:
|
|
165
|
+
_a.trys.push([1, 4, 5, 6]);
|
|
166
|
+
batch = this.getVisualsForBatch();
|
|
167
|
+
if (!(batch.length > 0)) return [3 /*break*/, 3];
|
|
168
|
+
return [4 /*yield*/, this.mapTileBatch(batch)];
|
|
169
|
+
case 2:
|
|
170
|
+
_a.sent();
|
|
171
|
+
_a.label = 3;
|
|
172
|
+
case 3:
|
|
173
|
+
if (this.totalLoaded > 8000) {
|
|
174
|
+
rerun = this.removeFarAwayBatch();
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
rerun = this.featureQueue.length > 0 && batch.length > 0;
|
|
178
|
+
}
|
|
179
|
+
return [3 /*break*/, 6];
|
|
180
|
+
case 4:
|
|
181
|
+
e_1 = _a.sent();
|
|
182
|
+
console.error(e_1);
|
|
183
|
+
return [3 /*break*/, 6];
|
|
184
|
+
case 5:
|
|
185
|
+
setTimeout(function () {
|
|
186
|
+
_this.processingQueue -= 1;
|
|
187
|
+
if (rerun) {
|
|
188
|
+
_this.processQueue();
|
|
189
|
+
}
|
|
190
|
+
}, BATCH_DELAY);
|
|
191
|
+
return [7 /*endfinally*/];
|
|
192
|
+
case 6: return [2 /*return*/];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
Manager.prototype.getVisualsForBatch = function () {
|
|
198
|
+
var batch = [];
|
|
199
|
+
var features = this.featureQueue;
|
|
200
|
+
var bounds = this.monitor.GetBounds();
|
|
201
|
+
var rect = (bounds === null || bounds === void 0 ? void 0 : bounds.east) ? new Cesium.Rectangle(Cesium.Math.toRadians(bounds.west), Cesium.Math.toRadians(bounds.south), Cesium.Math.toRadians(bounds.east), Cesium.Math.toRadians(bounds.north)) : null;
|
|
202
|
+
if (rect) {
|
|
203
|
+
for (var i = 0; i < features.length; i++) {
|
|
204
|
+
var feature = features[i];
|
|
205
|
+
if (feature) {
|
|
206
|
+
var featureLon = feature.getProperty("cesium#longitude");
|
|
207
|
+
var featureLat = feature.getProperty("cesium#latitude");
|
|
208
|
+
if (featureLon && featureLat) {
|
|
209
|
+
var carto = Cesium.Cartographic.fromDegrees(featureLon, featureLat, 0);
|
|
210
|
+
var isIn = Cesium.Rectangle.contains(rect, carto);
|
|
211
|
+
if (isIn) {
|
|
212
|
+
var isClose = this.getIsVisualWithinRange(feature, MAX_RANGE);
|
|
213
|
+
if (isClose) {
|
|
214
|
+
batch.push(feature);
|
|
215
|
+
if (batch.length >= BATCH_SIZE) {
|
|
216
|
+
return batch;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return batch;
|
|
225
|
+
};
|
|
226
|
+
Manager.prototype.getIsVisualWithinRange = function (visual, range) {
|
|
227
|
+
var featureLon = visual.getProperty("cesium#longitude");
|
|
228
|
+
var featureLat = visual.getProperty("cesium#latitude");
|
|
229
|
+
if (featureLon && featureLat) {
|
|
230
|
+
var pos = Cesium.Cartesian3.fromDegrees(featureLon, featureLat, 0);
|
|
231
|
+
var camPoint = this.monitor.GetTarget();
|
|
232
|
+
var camPos = (camPoint === null || camPoint === void 0 ? void 0 : camPoint.latitude) ? Cesium.Cartesian3.fromDegrees(camPoint.longitude, camPoint.latitude, camPoint.altitude) : null;
|
|
233
|
+
if (camPos && bruce_models_1.Cartes.ValidateCartes3(camPos) && bruce_models_1.Cartes.ValidateCartes3(pos)) {
|
|
234
|
+
var distance = Cesium.Cartesian3.distance(pos, camPos);
|
|
235
|
+
if (distance != null && distance <= range) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
};
|
|
242
|
+
Manager.prototype.mapTileBatch = function (features) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
244
|
+
var featureIds, featureMap, _loop_1, this_1, i, api, bIds, i, id, bId, feature, rego;
|
|
245
|
+
return __generator(this, function (_a) {
|
|
246
|
+
switch (_a.label) {
|
|
247
|
+
case 0:
|
|
248
|
+
featureIds = [];
|
|
249
|
+
featureMap = [];
|
|
250
|
+
_loop_1 = function (i) {
|
|
251
|
+
var feature = features[i];
|
|
252
|
+
var featureId = feature.getProperty("elementId");
|
|
253
|
+
if (featureId) {
|
|
254
|
+
featureMap.push(feature);
|
|
255
|
+
featureIds.push(featureId + "");
|
|
256
|
+
}
|
|
257
|
+
var index = this_1.featureQueue.findIndex(function (x) { return x._counter == feature._counter; });
|
|
258
|
+
if (index > -1) {
|
|
259
|
+
this_1.featureQueue.splice(index, 1);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
this_1 = this;
|
|
263
|
+
for (i = 0; i < features.length; i++) {
|
|
264
|
+
_loop_1(i);
|
|
265
|
+
}
|
|
266
|
+
api = this.apiGetter.getApi();
|
|
267
|
+
return [4 /*yield*/, bruce_models_1.EntitySource.GetEntityIdsBySourceKeys(api, this.sourceId, featureIds)];
|
|
268
|
+
case 1:
|
|
269
|
+
bIds = _a.sent();
|
|
270
|
+
for (i = 0; i < featureIds.length; i++) {
|
|
271
|
+
id = featureIds[i];
|
|
272
|
+
bId = bIds[id];
|
|
273
|
+
if (!bId) {
|
|
274
|
+
bId = bruce_models_1.ObjectUtils.UId();
|
|
275
|
+
}
|
|
276
|
+
feature = featureMap[i];
|
|
277
|
+
if (this.item.ghostLoading == true) {
|
|
278
|
+
feature.color = feature._orgColor;
|
|
279
|
+
}
|
|
280
|
+
rego = {
|
|
281
|
+
entityId: bId,
|
|
282
|
+
menuItemId: this.item.id,
|
|
283
|
+
priority: 0,
|
|
284
|
+
visual: feature,
|
|
285
|
+
entityTypeId: this.entityTypeId,
|
|
286
|
+
sourceId: this.sourceId
|
|
287
|
+
};
|
|
288
|
+
this.visualsManager.Add(rego);
|
|
289
|
+
this._loadedCesiumEntities[bId] = rego;
|
|
290
|
+
}
|
|
291
|
+
return [2 /*return*/];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
Manager.prototype.removeFarAwayBatch = function () {
|
|
297
|
+
var removed = 0;
|
|
298
|
+
var keys = Object.keys(this._loadedCesiumEntities);
|
|
299
|
+
for (var i = 0; i < keys.length; i++) {
|
|
300
|
+
var key = keys[i];
|
|
301
|
+
var rego = this._loadedCesiumEntities[key];
|
|
302
|
+
if (rego) {
|
|
303
|
+
if (!this.getIsVisualWithinRange(rego.visual, MAX_RANGE)) {
|
|
304
|
+
this.visualsManager.Remove(rego.entityId, this.item.id);
|
|
305
|
+
this._loadedCesiumEntities[key] = null;
|
|
306
|
+
delete this._loadedCesiumEntities[key];
|
|
307
|
+
this.totalLoaded -= 1;
|
|
308
|
+
removed += 1;
|
|
309
|
+
if (removed >= BATCH_SIZE) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return removed > 0;
|
|
316
|
+
};
|
|
317
|
+
return Manager;
|
|
318
|
+
}());
|
|
319
|
+
TilesetOsmRenderManager.Manager = Manager;
|
|
320
|
+
})(TilesetOsmRenderManager = exports.TilesetOsmRenderManager || (exports.TilesetOsmRenderManager = {}));
|
|
321
321
|
//# sourceMappingURL=tileset-osm-render-manager.js.map
|