bruce-models 0.7.8 → 0.8.0

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.
Files changed (92) hide show
  1. package/dist/bruce-models.es5.js +167 -8
  2. package/dist/bruce-models.es5.js.map +1 -1
  3. package/dist/bruce-models.umd.js +165 -7
  4. package/dist/bruce-models.umd.js.map +1 -1
  5. package/dist/lib/account/account.js +244 -244
  6. package/dist/lib/ann-document/ann-document.js +116 -116
  7. package/dist/lib/api/abstract-api.js +269 -269
  8. package/dist/lib/api/api.js +85 -85
  9. package/dist/lib/api/bruce-api.js +243 -228
  10. package/dist/lib/api/bruce-api.js.map +1 -1
  11. package/dist/lib/api/cam-api.js +132 -132
  12. package/dist/lib/api/global-api.js +131 -131
  13. package/dist/lib/api/idm-api.js +132 -132
  14. package/dist/lib/bruce-models.js +85 -84
  15. package/dist/lib/bruce-models.js.map +1 -1
  16. package/dist/lib/calculator/calculator.js +159 -158
  17. package/dist/lib/calculator/calculator.js.map +1 -1
  18. package/dist/lib/client-file/client-file.js +188 -188
  19. package/dist/lib/common/bounds.js +2 -2
  20. package/dist/lib/common/bruce-event.js +48 -48
  21. package/dist/lib/common/bruce-variable.js +54 -54
  22. package/dist/lib/common/cache.js +86 -86
  23. package/dist/lib/common/camera.js +11 -11
  24. package/dist/lib/common/cartes.js +55 -55
  25. package/dist/lib/common/carto.js +60 -60
  26. package/dist/lib/common/color.js +86 -86
  27. package/dist/lib/common/delay-queue.js +60 -60
  28. package/dist/lib/common/dictionary.js +2 -2
  29. package/dist/lib/common/geometry.js +120 -120
  30. package/dist/lib/common/transform.js +2 -2
  31. package/dist/lib/common/utc.js +39 -39
  32. package/dist/lib/custom-form/custom-form.js +136 -136
  33. package/dist/lib/data-lab/data-lab.js +90 -90
  34. package/dist/lib/entity/entity-attachment-type.js +132 -132
  35. package/dist/lib/entity/entity-attachment.js +208 -208
  36. package/dist/lib/entity/entity-comment.js +132 -132
  37. package/dist/lib/entity/entity-coords.js +181 -181
  38. package/dist/lib/entity/entity-link.js +132 -132
  39. package/dist/lib/entity/entity-lod.js +189 -189
  40. package/dist/lib/entity/entity-relation-type.js +150 -150
  41. package/dist/lib/entity/entity-relation.js +189 -189
  42. package/dist/lib/entity/entity-source.js +176 -176
  43. package/dist/lib/entity/entity-tag.js +229 -229
  44. package/dist/lib/entity/entity-type.js +163 -163
  45. package/dist/lib/entity/entity.js +358 -358
  46. package/dist/lib/entity/getters/batched-data-getter.js +91 -91
  47. package/dist/lib/entity/getters/entity-filter-getter.js +344 -344
  48. package/dist/lib/entity/getters/entity-globe.js +135 -135
  49. package/dist/lib/entity/getters/view-monitor.js +2 -2
  50. package/dist/lib/import/import-cad.js +82 -82
  51. package/dist/lib/import/import-csv.js +51 -51
  52. package/dist/lib/import/import-json.js +51 -51
  53. package/dist/lib/import/import-kml.js +51 -51
  54. package/dist/lib/import/imported-file.js +121 -121
  55. package/dist/lib/import/imported-file.js.map +1 -1
  56. package/dist/lib/markup/markup.js +40 -40
  57. package/dist/lib/program-key/program-key.js +152 -152
  58. package/dist/lib/project/menu-item.js +115 -115
  59. package/dist/lib/project/project-view-bookmark.js +183 -183
  60. package/dist/lib/project/project-view-legacy-tile.js +115 -115
  61. package/dist/lib/project/project-view-tile.js +119 -119
  62. package/dist/lib/project/project-view-tile.js.map +1 -1
  63. package/dist/lib/project/project-view.js +177 -177
  64. package/dist/lib/project/zoom-control.js +17 -17
  65. package/dist/lib/server/message-broker.js +159 -0
  66. package/dist/lib/server/message-broker.js.map +1 -0
  67. package/dist/lib/server/pending-action.js +106 -106
  68. package/dist/lib/server/task.js +113 -113
  69. package/dist/lib/style/style.js +152 -152
  70. package/dist/lib/tileset/tileset-cad.js +2 -2
  71. package/dist/lib/tileset/tileset-entities-map-tiles.js +18 -18
  72. package/dist/lib/tileset/tileset-entities.js +2 -2
  73. package/dist/lib/tileset/tileset-ext-map-tiles.js +17 -17
  74. package/dist/lib/tileset/tileset-ext-terrain-tiles.js +2 -2
  75. package/dist/lib/tileset/tileset-map-tiles.js +2 -2
  76. package/dist/lib/tileset/tileset-pointcloud.js +2 -2
  77. package/dist/lib/tileset/tileset-terrain-tiles.js +2 -2
  78. package/dist/lib/tileset/tileset.js +403 -403
  79. package/dist/lib/user/permission.js +20 -20
  80. package/dist/lib/user/session.js +160 -160
  81. package/dist/lib/user/user-group.js +139 -139
  82. package/dist/lib/user/user.js +451 -451
  83. package/dist/lib/util/encrypt-utils.js +20 -20
  84. package/dist/lib/util/math-utils.js +41 -41
  85. package/dist/lib/util/object-utils.js +17 -17
  86. package/dist/lib/util/path-utils.js +61 -61
  87. package/dist/lib/util/url-utils.js +107 -107
  88. package/dist/types/api/bruce-api.d.ts +9 -1
  89. package/dist/types/bruce-models.d.ts +1 -0
  90. package/dist/types/project/project-view-tile.d.ts +2 -6
  91. package/dist/types/server/message-broker.d.ts +108 -0
  92. package/package.json +1 -1
@@ -1,345 +1,345 @@
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.EntityFilterGetter = void 0;
40
- var api_1 = require("../../api/api");
41
- var bruce_event_1 = require("../../common/bruce-event");
42
- var entity_1 = require("../entity");
43
- var entity_globe_1 = require("./entity-globe");
44
- var MAX_AREA_IN_DEGREES = 90;
45
- var MAX_RETRY_ATTEMPTS = 1;
46
- var RETRY_DELAY_INCREMENT = 500;
47
- var REQUEST_PAGE_DELAY = 50;
48
- var regMenuItemGetter = /** @class */ (function () {
49
- function regMenuItemGetter(tagIds, minHeight, maxHeight) {
50
- this.TagIds = tagIds;
51
- this.MinHeight = minHeight;
52
- this.MaxHeight = maxHeight;
53
- }
54
- return regMenuItemGetter;
55
- }());
56
- function delay(milliseconds) {
57
- return __awaiter(this, void 0, void 0, function () {
58
- return __generator(this, function (_a) {
59
- return [2 /*return*/, new Promise(function (res) {
60
- setTimeout(function () {
61
- res();
62
- }, milliseconds);
63
- })];
64
- });
65
- });
66
- }
67
- /**
68
- * This is a batched entity getter.
69
- * It will scan for entity records in a view-area and emit them in batches.
70
- * It will restart scanning if the camera moves.
71
- */
72
- var EntityFilterGetter;
73
- (function (EntityFilterGetter) {
74
- var EStatus;
75
- (function (EStatus) {
76
- EStatus["Scanning"] = "SCANNING";
77
- EStatus["Loading"] = "LOADING";
78
- })(EStatus = EntityFilterGetter.EStatus || (EntityFilterGetter.EStatus = {}));
79
- var Getter = /** @class */ (function () {
80
- function Getter(api, viewPort, typeId, batchSize, attrFilter) {
81
- this.onUpdate = null;
82
- this.LastStateUpdates = {};
83
- this.onStateUpdate = null;
84
- this.viewPortChangeRemoval = null;
85
- this.cells = null;
86
- this.registeredItems = {};
87
- this.getterLoopId = 0;
88
- this.tagIds = null;
89
- this.minHeight = 0;
90
- this.maxHeight = 100000;
91
- this.viewRect = null;
92
- this.viewCenter = null;
93
- this.api = api;
94
- this.typeId = typeId;
95
- this.batchSize = batchSize;
96
- this.viewPort = viewPort;
97
- this.attrFilter = attrFilter;
98
- this.updateBounds();
99
- }
100
- Object.defineProperty(Getter.prototype, "OnUpdate", {
101
- get: function () {
102
- if (!this.onUpdate) {
103
- this.onUpdate = new bruce_event_1.BruceEvent();
104
- }
105
- return this.onUpdate;
106
- },
107
- enumerable: false,
108
- configurable: true
109
- });
110
- Object.defineProperty(Getter.prototype, "OnStateUpdate", {
111
- get: function () {
112
- if (!this.onStateUpdate) {
113
- this.onStateUpdate = new bruce_event_1.BruceEvent();
114
- }
115
- return this.onStateUpdate;
116
- },
117
- enumerable: false,
118
- configurable: true
119
- });
120
- Getter.prototype.viewAreaSub = function () {
121
- var _this = this;
122
- this.viewAreaDispose();
123
- this.viewPortChangeRemoval = this.viewPort.Updated().Subscribe(function () {
124
- _this.updateBounds();
125
- _this.startGetterLoop();
126
- });
127
- };
128
- Getter.prototype.viewAreaDispose = function () {
129
- var _a;
130
- (_a = this.viewPortChangeRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
131
- };
132
- Getter.prototype.GetMenuItems = function () {
133
- return Object.keys(this.registeredItems);
134
- };
135
- Getter.prototype.IncludeMenuItem = function (menuItemId, layerIds, minHeight, maxHeight) {
136
- this.registeredItems[menuItemId] = new regMenuItemGetter(layerIds, minHeight, maxHeight);
137
- this.updateState();
138
- };
139
- Getter.prototype.ExcludeMenuItem = function (menuItemId) {
140
- this.registeredItems[menuItemId] = null;
141
- delete this.registeredItems[menuItemId];
142
- this.updateState();
143
- };
144
- Getter.prototype.updateBounds = function () {
145
- var viewRect = this.viewPort.GetBounds();
146
- var poi = this.viewPort.GetTarget();
147
- if (viewRect && poi) {
148
- if (Math.abs(viewRect.west - viewRect.east) > MAX_AREA_IN_DEGREES) {
149
- return;
150
- }
151
- if (Math.abs(viewRect.south - viewRect.north) > MAX_AREA_IN_DEGREES) {
152
- return;
153
- }
154
- this.viewRect = viewRect;
155
- this.viewCenter = poi;
156
- }
157
- };
158
- Getter.prototype.updateState = function () {
159
- var tagIds = [];
160
- var menuItemIds = this.GetMenuItems();
161
- var minHeight = null;
162
- var maxHeight = null;
163
- for (var i = 0; i < menuItemIds.length; i++) {
164
- var menuItem = this.registeredItems[menuItemIds[i]];
165
- if (menuItem) {
166
- if (maxHeight == null || maxHeight < menuItem.MaxHeight) {
167
- maxHeight = menuItem.MaxHeight;
168
- }
169
- if (minHeight == null || minHeight > menuItem.MinHeight) {
170
- minHeight = menuItem.MinHeight;
171
- }
172
- var itemLayerIds = menuItem.TagIds;
173
- if (itemLayerIds) {
174
- for (var j = 0; j < itemLayerIds.length; j++) {
175
- var itemLayerId = itemLayerIds[j];
176
- if (!tagIds.includes(itemLayerId)) {
177
- tagIds.push(itemLayerId);
178
- }
179
- }
180
- }
181
- }
182
- }
183
- if (menuItemIds.length > 0) {
184
- // Reset cells so none are marked as fetched.
185
- this.cells = new entity_globe_1.EntityGlobe.Grid();
186
- this.tagIds = tagIds;
187
- this.minHeight = minHeight;
188
- this.maxHeight = maxHeight;
189
- this.updateBounds();
190
- this.startGetterLoop();
191
- this.viewAreaSub();
192
- }
193
- else {
194
- this.getterLoopId = -1;
195
- this.viewAreaDispose();
196
- }
197
- };
198
- Getter.prototype.postStatus = function (status) {
199
- var _a;
200
- this.LastStateUpdates[status.msg] = status;
201
- (_a = this.onStateUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(status);
202
- };
203
- Getter.prototype.startGetterLoop = function () {
204
- var _this = this;
205
- // Increase id so that existing loops stop.
206
- this.getterLoopId += 1;
207
- var loopId = this.getterLoopId;
208
- new Promise(function () { return __awaiter(_this, void 0, void 0, function () {
209
- var MIN_HEIGHT, MAX_HEIGHT, PAGE_SIZE, retryAttempts, retryDelay, prevFirstId, prevLastId, alt, cells, curCellIndex, postedScanning, postedLoading, curCell, page, first, last, e_1;
210
- var _a, _b, _c, _d, _e;
211
- return __generator(this, function (_f) {
212
- switch (_f.label) {
213
- case 0:
214
- // Minor delay to stop 50 menu items enabling doing their first request all together.
215
- // This gives it time to recognize only 1 request is needed.
216
- // Would be better to not use this delay but we're on a clock.
217
- return [4 /*yield*/, delay(100)];
218
- case 1:
219
- // Minor delay to stop 50 menu items enabling doing their first request all together.
220
- // This gives it time to recognize only 1 request is needed.
221
- // Would be better to not use this delay but we're on a clock.
222
- _f.sent();
223
- MIN_HEIGHT = this.minHeight;
224
- MAX_HEIGHT = this.maxHeight;
225
- PAGE_SIZE = this.batchSize;
226
- retryAttempts = MAX_RETRY_ATTEMPTS;
227
- retryDelay = 0;
228
- prevFirstId = "";
229
- prevLastId = "";
230
- _f.label = 2;
231
- case 2:
232
- if (!((!this.viewCenter || !this.viewRect) && this.getterLoopId == loopId)) return [3 /*break*/, 4];
233
- return [4 /*yield*/, delay(RETRY_DELAY_INCREMENT)];
234
- case 3:
235
- _f.sent();
236
- return [3 /*break*/, 2];
237
- case 4:
238
- if (this.getterLoopId != loopId) {
239
- return [2 /*return*/];
240
- }
241
- alt = this.viewRect.alt;
242
- if (alt > MAX_HEIGHT || (alt < MIN_HEIGHT && MIN_HEIGHT > 0)) {
243
- return [2 /*return*/];
244
- }
245
- cells = this.cells.GetCellsForView(this.viewRect);
246
- curCellIndex = cells.length > 0 ? 0 : null;
247
- postedScanning = false;
248
- postedLoading = false;
249
- _f.label = 5;
250
- case 5:
251
- if (!(retryAttempts > 0 && curCellIndex != null)) return [3 /*break*/, 13];
252
- if (this.getterLoopId != loopId) {
253
- return [3 /*break*/, 13];
254
- }
255
- if (!(retryDelay > 0)) return [3 /*break*/, 7];
256
- return [4 /*yield*/, delay(retryDelay)];
257
- case 6:
258
- _f.sent();
259
- _f.label = 7;
260
- case 7:
261
- if (!postedScanning) {
262
- this.postStatus({ msg: EStatus.Scanning, revoking: false });
263
- postedScanning = true;
264
- }
265
- curCell = cells[curCellIndex];
266
- if (curCell.IsFetched()) {
267
- curCellIndex += 1;
268
- if (!cells[curCellIndex]) {
269
- curCellIndex = null;
270
- }
271
- return [3 /*break*/, 5];
272
- }
273
- _f.label = 8;
274
- case 8:
275
- _f.trys.push([8, 10, , 11]);
276
- return [4 /*yield*/, entity_1.Entity.Filter.V1.GetList(this.api, {
277
- pageSize: PAGE_SIZE,
278
- pageIndex: curCell.FetchPageIndex,
279
- entityTypeId: this.typeId,
280
- layerIds: this.tagIds,
281
- bounds: curCell.GetBounds(),
282
- sortOrder: api_1.Api.ESortOrder.Asc,
283
- entityTypeConditions: this.attrFilter
284
- })];
285
- case 9:
286
- page = _f.sent();
287
- if (this.getterLoopId != loopId) {
288
- return [3 /*break*/, 13];
289
- }
290
- if (page) {
291
- (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(page);
292
- }
293
- if (!postedLoading) {
294
- this.postStatus({ msg: EStatus.Loading, revoking: false });
295
- postedLoading = true;
296
- }
297
- if (page.length <= 0) {
298
- curCell.Fetched = true; // Only mark as fetched when ALL pages are done.
299
- return [3 /*break*/, 5];
300
- }
301
- // Checking to make sure it's not just the same batch over and over again.
302
- if (page.length > 0) {
303
- first = (_c = (_b = page[0]) === null || _b === void 0 ? void 0 : _b.Bruce) === null || _c === void 0 ? void 0 : _c.ID;
304
- last = (_e = (_d = page[page.length - 1]) === null || _d === void 0 ? void 0 : _d.Bruce) === null || _e === void 0 ? void 0 : _e.ID;
305
- if (prevFirstId == first && prevLastId == last) {
306
- return [3 /*break*/, 13];
307
- }
308
- else {
309
- prevFirstId = first;
310
- prevLastId = last;
311
- }
312
- }
313
- curCell.FetchPageIndex++;
314
- // Request passed so let's assume it was server hiccup and refresh counts.
315
- retryAttempts = MAX_RETRY_ATTEMPTS;
316
- retryDelay = 0;
317
- return [3 /*break*/, 11];
318
- case 10:
319
- e_1 = _f.sent();
320
- console.log(e_1);
321
- // Request failed so let's add a delay and try again soon.
322
- retryDelay += RETRY_DELAY_INCREMENT;
323
- retryAttempts -= 1;
324
- return [3 /*break*/, 11];
325
- case 11: return [4 /*yield*/, delay(REQUEST_PAGE_DELAY)];
326
- case 12:
327
- _f.sent();
328
- return [3 /*break*/, 5];
329
- case 13:
330
- if (postedLoading) {
331
- this.postStatus({ msg: EStatus.Loading, revoking: true });
332
- }
333
- if (postedScanning) {
334
- this.postStatus({ msg: EStatus.Scanning, revoking: true });
335
- }
336
- return [2 /*return*/];
337
- }
338
- });
339
- }); });
340
- };
341
- return Getter;
342
- }());
343
- EntityFilterGetter.Getter = Getter;
344
- })(EntityFilterGetter = exports.EntityFilterGetter || (exports.EntityFilterGetter = {}));
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.EntityFilterGetter = void 0;
40
+ var api_1 = require("../../api/api");
41
+ var bruce_event_1 = require("../../common/bruce-event");
42
+ var entity_1 = require("../entity");
43
+ var entity_globe_1 = require("./entity-globe");
44
+ var MAX_AREA_IN_DEGREES = 90;
45
+ var MAX_RETRY_ATTEMPTS = 1;
46
+ var RETRY_DELAY_INCREMENT = 500;
47
+ var REQUEST_PAGE_DELAY = 50;
48
+ var regMenuItemGetter = /** @class */ (function () {
49
+ function regMenuItemGetter(tagIds, minHeight, maxHeight) {
50
+ this.TagIds = tagIds;
51
+ this.MinHeight = minHeight;
52
+ this.MaxHeight = maxHeight;
53
+ }
54
+ return regMenuItemGetter;
55
+ }());
56
+ function delay(milliseconds) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ return __generator(this, function (_a) {
59
+ return [2 /*return*/, new Promise(function (res) {
60
+ setTimeout(function () {
61
+ res();
62
+ }, milliseconds);
63
+ })];
64
+ });
65
+ });
66
+ }
67
+ /**
68
+ * This is a batched entity getter.
69
+ * It will scan for entity records in a view-area and emit them in batches.
70
+ * It will restart scanning if the camera moves.
71
+ */
72
+ var EntityFilterGetter;
73
+ (function (EntityFilterGetter) {
74
+ var EStatus;
75
+ (function (EStatus) {
76
+ EStatus["Scanning"] = "SCANNING";
77
+ EStatus["Loading"] = "LOADING";
78
+ })(EStatus = EntityFilterGetter.EStatus || (EntityFilterGetter.EStatus = {}));
79
+ var Getter = /** @class */ (function () {
80
+ function Getter(api, viewPort, typeId, batchSize, attrFilter) {
81
+ this.onUpdate = null;
82
+ this.LastStateUpdates = {};
83
+ this.onStateUpdate = null;
84
+ this.viewPortChangeRemoval = null;
85
+ this.cells = null;
86
+ this.registeredItems = {};
87
+ this.getterLoopId = 0;
88
+ this.tagIds = null;
89
+ this.minHeight = 0;
90
+ this.maxHeight = 100000;
91
+ this.viewRect = null;
92
+ this.viewCenter = null;
93
+ this.api = api;
94
+ this.typeId = typeId;
95
+ this.batchSize = batchSize;
96
+ this.viewPort = viewPort;
97
+ this.attrFilter = attrFilter;
98
+ this.updateBounds();
99
+ }
100
+ Object.defineProperty(Getter.prototype, "OnUpdate", {
101
+ get: function () {
102
+ if (!this.onUpdate) {
103
+ this.onUpdate = new bruce_event_1.BruceEvent();
104
+ }
105
+ return this.onUpdate;
106
+ },
107
+ enumerable: false,
108
+ configurable: true
109
+ });
110
+ Object.defineProperty(Getter.prototype, "OnStateUpdate", {
111
+ get: function () {
112
+ if (!this.onStateUpdate) {
113
+ this.onStateUpdate = new bruce_event_1.BruceEvent();
114
+ }
115
+ return this.onStateUpdate;
116
+ },
117
+ enumerable: false,
118
+ configurable: true
119
+ });
120
+ Getter.prototype.viewAreaSub = function () {
121
+ var _this = this;
122
+ this.viewAreaDispose();
123
+ this.viewPortChangeRemoval = this.viewPort.Updated().Subscribe(function () {
124
+ _this.updateBounds();
125
+ _this.startGetterLoop();
126
+ });
127
+ };
128
+ Getter.prototype.viewAreaDispose = function () {
129
+ var _a;
130
+ (_a = this.viewPortChangeRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
131
+ };
132
+ Getter.prototype.GetMenuItems = function () {
133
+ return Object.keys(this.registeredItems);
134
+ };
135
+ Getter.prototype.IncludeMenuItem = function (menuItemId, layerIds, minHeight, maxHeight) {
136
+ this.registeredItems[menuItemId] = new regMenuItemGetter(layerIds, minHeight, maxHeight);
137
+ this.updateState();
138
+ };
139
+ Getter.prototype.ExcludeMenuItem = function (menuItemId) {
140
+ this.registeredItems[menuItemId] = null;
141
+ delete this.registeredItems[menuItemId];
142
+ this.updateState();
143
+ };
144
+ Getter.prototype.updateBounds = function () {
145
+ var viewRect = this.viewPort.GetBounds();
146
+ var poi = this.viewPort.GetTarget();
147
+ if (viewRect && poi) {
148
+ if (Math.abs(viewRect.west - viewRect.east) > MAX_AREA_IN_DEGREES) {
149
+ return;
150
+ }
151
+ if (Math.abs(viewRect.south - viewRect.north) > MAX_AREA_IN_DEGREES) {
152
+ return;
153
+ }
154
+ this.viewRect = viewRect;
155
+ this.viewCenter = poi;
156
+ }
157
+ };
158
+ Getter.prototype.updateState = function () {
159
+ var tagIds = [];
160
+ var menuItemIds = this.GetMenuItems();
161
+ var minHeight = null;
162
+ var maxHeight = null;
163
+ for (var i = 0; i < menuItemIds.length; i++) {
164
+ var menuItem = this.registeredItems[menuItemIds[i]];
165
+ if (menuItem) {
166
+ if (maxHeight == null || maxHeight < menuItem.MaxHeight) {
167
+ maxHeight = menuItem.MaxHeight;
168
+ }
169
+ if (minHeight == null || minHeight > menuItem.MinHeight) {
170
+ minHeight = menuItem.MinHeight;
171
+ }
172
+ var itemLayerIds = menuItem.TagIds;
173
+ if (itemLayerIds) {
174
+ for (var j = 0; j < itemLayerIds.length; j++) {
175
+ var itemLayerId = itemLayerIds[j];
176
+ if (!tagIds.includes(itemLayerId)) {
177
+ tagIds.push(itemLayerId);
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ if (menuItemIds.length > 0) {
184
+ // Reset cells so none are marked as fetched.
185
+ this.cells = new entity_globe_1.EntityGlobe.Grid();
186
+ this.tagIds = tagIds;
187
+ this.minHeight = minHeight;
188
+ this.maxHeight = maxHeight;
189
+ this.updateBounds();
190
+ this.startGetterLoop();
191
+ this.viewAreaSub();
192
+ }
193
+ else {
194
+ this.getterLoopId = -1;
195
+ this.viewAreaDispose();
196
+ }
197
+ };
198
+ Getter.prototype.postStatus = function (status) {
199
+ var _a;
200
+ this.LastStateUpdates[status.msg] = status;
201
+ (_a = this.onStateUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(status);
202
+ };
203
+ Getter.prototype.startGetterLoop = function () {
204
+ var _this = this;
205
+ // Increase id so that existing loops stop.
206
+ this.getterLoopId += 1;
207
+ var loopId = this.getterLoopId;
208
+ new Promise(function () { return __awaiter(_this, void 0, void 0, function () {
209
+ var MIN_HEIGHT, MAX_HEIGHT, PAGE_SIZE, retryAttempts, retryDelay, prevFirstId, prevLastId, alt, cells, curCellIndex, postedScanning, postedLoading, curCell, page, first, last, e_1;
210
+ var _a, _b, _c, _d, _e;
211
+ return __generator(this, function (_f) {
212
+ switch (_f.label) {
213
+ case 0:
214
+ // Minor delay to stop 50 menu items enabling doing their first request all together.
215
+ // This gives it time to recognize only 1 request is needed.
216
+ // Would be better to not use this delay but we're on a clock.
217
+ return [4 /*yield*/, delay(100)];
218
+ case 1:
219
+ // Minor delay to stop 50 menu items enabling doing their first request all together.
220
+ // This gives it time to recognize only 1 request is needed.
221
+ // Would be better to not use this delay but we're on a clock.
222
+ _f.sent();
223
+ MIN_HEIGHT = this.minHeight;
224
+ MAX_HEIGHT = this.maxHeight;
225
+ PAGE_SIZE = this.batchSize;
226
+ retryAttempts = MAX_RETRY_ATTEMPTS;
227
+ retryDelay = 0;
228
+ prevFirstId = "";
229
+ prevLastId = "";
230
+ _f.label = 2;
231
+ case 2:
232
+ if (!((!this.viewCenter || !this.viewRect) && this.getterLoopId == loopId)) return [3 /*break*/, 4];
233
+ return [4 /*yield*/, delay(RETRY_DELAY_INCREMENT)];
234
+ case 3:
235
+ _f.sent();
236
+ return [3 /*break*/, 2];
237
+ case 4:
238
+ if (this.getterLoopId != loopId) {
239
+ return [2 /*return*/];
240
+ }
241
+ alt = this.viewRect.alt;
242
+ if (alt > MAX_HEIGHT || (alt < MIN_HEIGHT && MIN_HEIGHT > 0)) {
243
+ return [2 /*return*/];
244
+ }
245
+ cells = this.cells.GetCellsForView(this.viewRect);
246
+ curCellIndex = cells.length > 0 ? 0 : null;
247
+ postedScanning = false;
248
+ postedLoading = false;
249
+ _f.label = 5;
250
+ case 5:
251
+ if (!(retryAttempts > 0 && curCellIndex != null)) return [3 /*break*/, 13];
252
+ if (this.getterLoopId != loopId) {
253
+ return [3 /*break*/, 13];
254
+ }
255
+ if (!(retryDelay > 0)) return [3 /*break*/, 7];
256
+ return [4 /*yield*/, delay(retryDelay)];
257
+ case 6:
258
+ _f.sent();
259
+ _f.label = 7;
260
+ case 7:
261
+ if (!postedScanning) {
262
+ this.postStatus({ msg: EStatus.Scanning, revoking: false });
263
+ postedScanning = true;
264
+ }
265
+ curCell = cells[curCellIndex];
266
+ if (curCell.IsFetched()) {
267
+ curCellIndex += 1;
268
+ if (!cells[curCellIndex]) {
269
+ curCellIndex = null;
270
+ }
271
+ return [3 /*break*/, 5];
272
+ }
273
+ _f.label = 8;
274
+ case 8:
275
+ _f.trys.push([8, 10, , 11]);
276
+ return [4 /*yield*/, entity_1.Entity.Filter.V1.GetList(this.api, {
277
+ pageSize: PAGE_SIZE,
278
+ pageIndex: curCell.FetchPageIndex,
279
+ entityTypeId: this.typeId,
280
+ layerIds: this.tagIds,
281
+ bounds: curCell.GetBounds(),
282
+ sortOrder: api_1.Api.ESortOrder.Asc,
283
+ entityTypeConditions: this.attrFilter
284
+ })];
285
+ case 9:
286
+ page = _f.sent();
287
+ if (this.getterLoopId != loopId) {
288
+ return [3 /*break*/, 13];
289
+ }
290
+ if (page) {
291
+ (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(page);
292
+ }
293
+ if (!postedLoading) {
294
+ this.postStatus({ msg: EStatus.Loading, revoking: false });
295
+ postedLoading = true;
296
+ }
297
+ if (page.length <= 0) {
298
+ curCell.Fetched = true; // Only mark as fetched when ALL pages are done.
299
+ return [3 /*break*/, 5];
300
+ }
301
+ // Checking to make sure it's not just the same batch over and over again.
302
+ if (page.length > 0) {
303
+ first = (_c = (_b = page[0]) === null || _b === void 0 ? void 0 : _b.Bruce) === null || _c === void 0 ? void 0 : _c.ID;
304
+ last = (_e = (_d = page[page.length - 1]) === null || _d === void 0 ? void 0 : _d.Bruce) === null || _e === void 0 ? void 0 : _e.ID;
305
+ if (prevFirstId == first && prevLastId == last) {
306
+ return [3 /*break*/, 13];
307
+ }
308
+ else {
309
+ prevFirstId = first;
310
+ prevLastId = last;
311
+ }
312
+ }
313
+ curCell.FetchPageIndex++;
314
+ // Request passed so let's assume it was server hiccup and refresh counts.
315
+ retryAttempts = MAX_RETRY_ATTEMPTS;
316
+ retryDelay = 0;
317
+ return [3 /*break*/, 11];
318
+ case 10:
319
+ e_1 = _f.sent();
320
+ console.log(e_1);
321
+ // Request failed so let's add a delay and try again soon.
322
+ retryDelay += RETRY_DELAY_INCREMENT;
323
+ retryAttempts -= 1;
324
+ return [3 /*break*/, 11];
325
+ case 11: return [4 /*yield*/, delay(REQUEST_PAGE_DELAY)];
326
+ case 12:
327
+ _f.sent();
328
+ return [3 /*break*/, 5];
329
+ case 13:
330
+ if (postedLoading) {
331
+ this.postStatus({ msg: EStatus.Loading, revoking: true });
332
+ }
333
+ if (postedScanning) {
334
+ this.postStatus({ msg: EStatus.Scanning, revoking: true });
335
+ }
336
+ return [2 /*return*/];
337
+ }
338
+ });
339
+ }); });
340
+ };
341
+ return Getter;
342
+ }());
343
+ EntityFilterGetter.Getter = Getter;
344
+ })(EntityFilterGetter = exports.EntityFilterGetter || (exports.EntityFilterGetter = {}));
345
345
  //# sourceMappingURL=entity-filter-getter.js.map