bruce-models 0.7.2 → 0.7.3

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.
@@ -93,7 +93,7 @@ var Api;
93
93
  ECacheKey["PendingAction"] = "pendingaction";
94
94
  ECacheKey["EntitySource"] = "entitysource";
95
95
  ECacheKey["ProgramKey"] = "programkey";
96
- ECacheKey["Ucs"] = "ucs";
96
+ ECacheKey["EntityCoords"] = "entitycoords";
97
97
  ECacheKey["Tag"] = "tag";
98
98
  ECacheKey["Attachment"] = "attachment";
99
99
  ECacheKey["Comment"] = "comment";
@@ -4073,6 +4073,186 @@ var BatchedDataGetter;
4073
4073
  BatchedDataGetter.Getter = Getter;
4074
4074
  })(BatchedDataGetter || (BatchedDataGetter = {}));
4075
4075
 
4076
+ var MathUtils;
4077
+ (function (MathUtils) {
4078
+ /**
4079
+ * Rounds a number to a given number of decimal places.
4080
+ * @param num
4081
+ * @param decimals
4082
+ * @returns
4083
+ */
4084
+ function Round(num, decimals) {
4085
+ if (decimals === void 0) { decimals = 0; }
4086
+ if (decimals <= 0) {
4087
+ return Math.round(num);
4088
+ }
4089
+ var tmp = "1";
4090
+ for (var i = 0; i < decimals; i++) {
4091
+ tmp += "0";
4092
+ }
4093
+ var d = parseFloat(tmp);
4094
+ return Math.round((num + Number.EPSILON) * d) / d;
4095
+ }
4096
+ MathUtils.Round = Round;
4097
+ /**
4098
+ * Returns a random integer between min (inclusive) and max (inclusive).
4099
+ * @param min
4100
+ * @param max
4101
+ * @returns
4102
+ */
4103
+ function RandInt(min, max) {
4104
+ if (min == max) {
4105
+ return min;
4106
+ }
4107
+ else if (min > max) {
4108
+ throw ("Min is greater than max.");
4109
+ }
4110
+ return Math.floor(Math.random() * (max - min + 1)) + min;
4111
+ }
4112
+ MathUtils.RandInt = RandInt;
4113
+ })(MathUtils || (MathUtils = {}));
4114
+
4115
+ var EntityCoords;
4116
+ (function (EntityCoords) {
4117
+ EntityCoords.UCS_ENTITY_TYPE_ID = "Bruce_UCS_Type";
4118
+ function GetCacheKey(entityId) {
4119
+ return Api.ECacheKey.EntityCoords + Api.ECacheKey.Entity + Api.ECacheKey.Id + entityId;
4120
+ }
4121
+ EntityCoords.GetCacheKey = GetCacheKey;
4122
+ function GetEntityCoords(api, entityId) {
4123
+ return __awaiter(this, void 0, void 0, function () {
4124
+ var cacheData, req;
4125
+ return __generator(this, function (_a) {
4126
+ cacheData = api.Cache.Get(GetCacheKey(entityId));
4127
+ if (cacheData) {
4128
+ return [2 /*return*/, cacheData];
4129
+ }
4130
+ req = api.GET("entity/" + entityId + "/ucs");
4131
+ api.Cache.Set(GetCacheKey(entityId), req, Api.DEFAULT_CACHE_DURATION);
4132
+ return [2 /*return*/, req];
4133
+ });
4134
+ });
4135
+ }
4136
+ EntityCoords.GetEntityCoords = GetEntityCoords;
4137
+ function EntityRelativeToPoint(api, entityId, params) {
4138
+ return __awaiter(this, void 0, void 0, function () {
4139
+ var point, name, res;
4140
+ return __generator(this, function (_a) {
4141
+ switch (_a.label) {
4142
+ case 0:
4143
+ if (!!params.test) return [3 /*break*/, 2];
4144
+ return [4 /*yield*/, UnlinkCoords(api, entityId)];
4145
+ case 1:
4146
+ _a.sent();
4147
+ _a.label = 2;
4148
+ case 2:
4149
+ point = params.point;
4150
+ name = params.name || MathUtils.Round(point.latitude, 4) + ", " + MathUtils.Round(point.longitude, 4);
4151
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/ucs", {
4152
+ "ucs": {
4153
+ "Entity.ID": null,
4154
+ "name": name,
4155
+ "location": {
4156
+ "latitude": point.latitude,
4157
+ "longitude": point.longitude,
4158
+ "altitude": point.altitude,
4159
+ "coordinates": {
4160
+ "Entity.ID": entityId
4161
+ }
4162
+ }
4163
+ },
4164
+ "test": params.test
4165
+ })];
4166
+ case 3:
4167
+ res = _a.sent();
4168
+ if (!params.test) {
4169
+ api.Cache.Remove(GetCacheKey(entityId));
4170
+ }
4171
+ return [2 /*return*/, res];
4172
+ }
4173
+ });
4174
+ });
4175
+ }
4176
+ EntityCoords.EntityRelativeToPoint = EntityRelativeToPoint;
4177
+ function EntityRelativeToEpsg(api, entityId, params) {
4178
+ var _a;
4179
+ return __awaiter(this, void 0, void 0, function () {
4180
+ var epsg, name, res;
4181
+ return __generator(this, function (_b) {
4182
+ switch (_b.label) {
4183
+ case 0:
4184
+ if (!!params.test) return [3 /*break*/, 2];
4185
+ return [4 /*yield*/, UnlinkCoords(api, entityId)];
4186
+ case 1:
4187
+ _b.sent();
4188
+ _b.label = 2;
4189
+ case 2:
4190
+ epsg = params.epsg;
4191
+ name = (_a = params.name) !== null && _a !== void 0 ? _a : "EPSG: " + epsg;
4192
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/ucs", {
4193
+ "ucs": {
4194
+ "Entity.ID": null,
4195
+ "name": name,
4196
+ "location": {
4197
+ "coordinates": {
4198
+ "SRID": "EPSG:" + epsg,
4199
+ "Entity.ID": entityId
4200
+ }
4201
+ }
4202
+ },
4203
+ "test": params.test
4204
+ })];
4205
+ case 3:
4206
+ res = _b.sent();
4207
+ if (!params.test) {
4208
+ api.Cache.Remove(GetCacheKey(entityId));
4209
+ }
4210
+ return [2 /*return*/, res];
4211
+ }
4212
+ });
4213
+ });
4214
+ }
4215
+ EntityCoords.EntityRelativeToEpsg = EntityRelativeToEpsg;
4216
+ function EntityRelativeToUcs(api, entityId, params) {
4217
+ return __awaiter(this, void 0, void 0, function () {
4218
+ var ucsId, res;
4219
+ return __generator(this, function (_a) {
4220
+ switch (_a.label) {
4221
+ case 0:
4222
+ if (!!params.test) return [3 /*break*/, 2];
4223
+ return [4 /*yield*/, UnlinkCoords(api, entityId)];
4224
+ case 1:
4225
+ _a.sent();
4226
+ _a.label = 2;
4227
+ case 2:
4228
+ ucsId = params.ucsId;
4229
+ return [4 /*yield*/, api.POST("entity/" + entityId + "/ucs", {
4230
+ "ucs": {
4231
+ "Entity.ID": ucsId
4232
+ },
4233
+ "test": params.test
4234
+ })];
4235
+ case 3:
4236
+ res = _a.sent();
4237
+ if (!params.test) {
4238
+ api.Cache.Remove(GetCacheKey(entityId));
4239
+ }
4240
+ return [2 /*return*/, res];
4241
+ }
4242
+ });
4243
+ });
4244
+ }
4245
+ EntityCoords.EntityRelativeToUcs = EntityRelativeToUcs;
4246
+ function UnlinkCoords(api, entityId) {
4247
+ return __awaiter(this, void 0, void 0, function () {
4248
+ return __generator(this, function (_a) {
4249
+ return [2 /*return*/, api.DELETE("entity/" + entityId + "/ucs")];
4250
+ });
4251
+ });
4252
+ }
4253
+ EntityCoords.UnlinkCoords = UnlinkCoords;
4254
+ })(EntityCoords || (EntityCoords = {}));
4255
+
4076
4256
  /**
4077
4257
  * Describes the "Client File" concept within Bruce.
4078
4258
  * A client file is a record of a file uploaded to Bruce.
@@ -5357,102 +5537,6 @@ var TilesetExtMapTiles;
5357
5537
  })(EType = TilesetExtMapTiles.EType || (TilesetExtMapTiles.EType = {}));
5358
5538
  })(TilesetExtMapTiles || (TilesetExtMapTiles = {}));
5359
5539
 
5360
- /**
5361
- * Describes the "UCS" concept within Bruce.
5362
- * A UCS is a user-coordinate-system.
5363
- * It is a description of an offset to apply to tilesets so that they can all align with each other.
5364
- */
5365
- var Ucs;
5366
- (function (Ucs) {
5367
- function GetCacheKey(id, expandUsage) {
5368
- return Api.ECacheKey.Ucs + Api.ECacheKey.Id + id + Api.ECacheKey + expandUsage;
5369
- }
5370
- Ucs.GetCacheKey = GetCacheKey;
5371
- function GetListCacheKey() {
5372
- return Api.ECacheKey.Ucs;
5373
- }
5374
- Ucs.GetListCacheKey = GetListCacheKey;
5375
- var EState;
5376
- (function (EState) {
5377
- EState["Undefined"] = "undef";
5378
- EState["Prepared"] = "ready";
5379
- })(EState = Ucs.EState || (Ucs.EState = {}));
5380
- function Get(api, ucsId, expandUsage) {
5381
- return __awaiter(this, void 0, void 0, function () {
5382
- var cacheData, req;
5383
- return __generator(this, function (_a) {
5384
- if (!ucsId) {
5385
- throw ("UCS ID is required.");
5386
- }
5387
- if (!expandUsage) {
5388
- expandUsage = false;
5389
- }
5390
- cacheData = api.Cache.Get(GetCacheKey(ucsId, expandUsage));
5391
- if (cacheData) {
5392
- return [2 /*return*/, cacheData];
5393
- }
5394
- req = api.GET("ucs/" + ucsId);
5395
- api.Cache.Set(GetCacheKey(ucsId, expandUsage), req, Api.DEFAULT_CACHE_DURATION);
5396
- return [2 /*return*/, req];
5397
- });
5398
- });
5399
- }
5400
- Ucs.Get = Get;
5401
- function Delete(api, ucsId) {
5402
- return __awaiter(this, void 0, void 0, function () {
5403
- return __generator(this, function (_a) {
5404
- switch (_a.label) {
5405
- case 0:
5406
- if (!ucsId) {
5407
- throw ("UCS ID is required.");
5408
- }
5409
- return [4 /*yield*/, api.DELETE("ucs/" + ucsId)];
5410
- case 1:
5411
- _a.sent();
5412
- api.Cache.RemoveByStartsWith(Api.ECacheKey.Ucs + Api.ECacheKey.Id + ucsId);
5413
- api.Cache.Remove(GetListCacheKey());
5414
- return [2 /*return*/];
5415
- }
5416
- });
5417
- });
5418
- }
5419
- Ucs.Delete = Delete;
5420
- function GetList(api) {
5421
- return __awaiter(this, void 0, void 0, function () {
5422
- var cacheData, req;
5423
- return __generator(this, function (_a) {
5424
- cacheData = api.Cache.Get(GetListCacheKey());
5425
- if (cacheData) {
5426
- return [2 /*return*/, cacheData];
5427
- }
5428
- req = api.GET("ucs");
5429
- api.Cache.Set(GetListCacheKey(), req, Api.DEFAULT_CACHE_DURATION);
5430
- return [2 /*return*/, req];
5431
- });
5432
- });
5433
- }
5434
- Ucs.GetList = GetList;
5435
- function Update(api, data) {
5436
- return __awaiter(this, void 0, void 0, function () {
5437
- return __generator(this, function (_a) {
5438
- switch (_a.label) {
5439
- case 0:
5440
- if (!(data === null || data === void 0 ? void 0 : data.name)) {
5441
- throw ("UCS name is required.");
5442
- }
5443
- return [4 /*yield*/, api.POST("ucs" + (!data.id ? "" : "/" + data.id), data)];
5444
- case 1:
5445
- data = _a.sent();
5446
- api.Cache.RemoveByStartsWith(Api.ECacheKey.Ucs + Api.ECacheKey.Id + data.id);
5447
- api.Cache.Remove(GetListCacheKey());
5448
- return [2 /*return*/, data];
5449
- }
5450
- });
5451
- });
5452
- }
5453
- Ucs.Update = Update;
5454
- })(Ucs || (Ucs = {}));
5455
-
5456
5540
  var Permission;
5457
5541
  (function (Permission) {
5458
5542
  var EPerm;
@@ -6122,45 +6206,6 @@ var EncryptUtils;
6122
6206
  EncryptUtils.Cyrb53Hash = Cyrb53Hash;
6123
6207
  })(EncryptUtils || (EncryptUtils = {}));
6124
6208
 
6125
- var MathUtils;
6126
- (function (MathUtils) {
6127
- /**
6128
- * Rounds a number to a given number of decimal places.
6129
- * @param num
6130
- * @param decimals
6131
- * @returns
6132
- */
6133
- function Round(num, decimals) {
6134
- if (decimals === void 0) { decimals = 0; }
6135
- if (decimals <= 0) {
6136
- return Math.round(num);
6137
- }
6138
- var tmp = "1";
6139
- for (var i = 0; i < decimals; i++) {
6140
- tmp += "0";
6141
- }
6142
- var d = parseFloat(tmp);
6143
- return Math.round((num + Number.EPSILON) * d) / d;
6144
- }
6145
- MathUtils.Round = Round;
6146
- /**
6147
- * Returns a random integer between min (inclusive) and max (inclusive).
6148
- * @param min
6149
- * @param max
6150
- * @returns
6151
- */
6152
- function RandInt(min, max) {
6153
- if (min == max) {
6154
- return min;
6155
- }
6156
- else if (min > max) {
6157
- throw ("Min is greater than max.");
6158
- }
6159
- return Math.floor(Math.random() * (max - min + 1)) + min;
6160
- }
6161
- MathUtils.RandInt = RandInt;
6162
- })(MathUtils || (MathUtils = {}));
6163
-
6164
6209
  /**
6165
6210
  * Utility to help with url manipulation.
6166
6211
  */
@@ -6478,5 +6523,5 @@ var ImportedFile;
6478
6523
  ImportedFile.Get = Get;
6479
6524
  })(ImportedFile || (ImportedFile = {}));
6480
6525
 
6481
- export { AnnDocument, CustomForm, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, Calculator, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewTileSource, PendingAction, Style, TilesetEntitiesMapTiles, TilesetExtMapTiles, Tileset, Ucs, Permission, Session, UserGroup, User, Account, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile };
6526
+ export { AnnDocument, CustomForm, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, Calculator, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, EntityCoords, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewTileSource, PendingAction, Style, TilesetEntitiesMapTiles, TilesetExtMapTiles, Tileset, Permission, Session, UserGroup, User, Account, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile };
6482
6527
  //# sourceMappingURL=bruce-models.es5.js.map