bruce-cesium 4.0.9 → 4.1.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 (38) hide show
  1. package/dist/bruce-cesium.es5.js +626 -4
  2. package/dist/bruce-cesium.es5.js.map +1 -1
  3. package/dist/bruce-cesium.umd.js +623 -2
  4. package/dist/bruce-cesium.umd.js.map +1 -1
  5. package/dist/lib/bruce-cesium.js +2 -1
  6. package/dist/lib/bruce-cesium.js.map +1 -1
  7. package/dist/lib/rendering/menu-item-manager.js +10 -0
  8. package/dist/lib/rendering/menu-item-manager.js.map +1 -1
  9. package/dist/lib/rendering/render-managers/data-source/data-source-static-csv-manager.js +2 -0
  10. package/dist/lib/rendering/render-managers/data-source/data-source-static-csv-manager.js.map +1 -1
  11. package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js +2 -0
  12. package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js.map +1 -1
  13. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js +2 -0
  14. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js.map +1 -1
  15. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js +2 -0
  16. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js.map +1 -1
  17. package/dist/lib/rendering/render-managers/entities/entity-render-manager.js +1 -0
  18. package/dist/lib/rendering/render-managers/entities/entity-render-manager.js.map +1 -1
  19. package/dist/lib/rendering/render-managers/other/google-search-render-manager.js +642 -0
  20. package/dist/lib/rendering/render-managers/other/google-search-render-manager.js.map +1 -0
  21. package/dist/lib/rendering/render-managers/other/legacy-relations-render-manager.js +1 -0
  22. package/dist/lib/rendering/render-managers/other/legacy-relations-render-manager.js.map +1 -1
  23. package/dist/lib/rendering/render-managers/other/relations-render-manager.js +1 -0
  24. package/dist/lib/rendering/render-managers/other/relations-render-manager.js.map +1 -1
  25. package/dist/lib/rendering/render-managers/tilesets/tileset-arb-render-manager.js +1 -0
  26. package/dist/lib/rendering/render-managers/tilesets/tileset-arb-render-manager.js.map +1 -1
  27. package/dist/lib/rendering/render-managers/tilesets/tileset-cad-render-manager.js +1 -0
  28. package/dist/lib/rendering/render-managers/tilesets/tileset-cad-render-manager.js.map +1 -1
  29. package/dist/lib/rendering/render-managers/tilesets/tileset-entities-render-manager.js +1 -0
  30. package/dist/lib/rendering/render-managers/tilesets/tileset-entities-render-manager.js.map +1 -1
  31. package/dist/lib/rendering/render-managers/tilesets/tileset-osm-render-manager.js +1 -0
  32. package/dist/lib/rendering/render-managers/tilesets/tileset-osm-render-manager.js.map +1 -1
  33. package/dist/lib/rendering/visuals-register.js +1 -1
  34. package/dist/lib/rendering/visuals-register.js.map +1 -1
  35. package/dist/types/bruce-cesium.d.ts +2 -1
  36. package/dist/types/rendering/render-managers/other/google-search-render-manager.d.ts +46 -0
  37. package/dist/types/rendering/visuals-register.d.ts +2 -1
  38. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  import { BruceEvent, Cartes, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, ProjectViewTile, DelayQueue, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, Api, EntityRelationType, ENVIRONMENT, EntityHistoricData, EntityCoords, EntitySource, MenuItem, EntityRelation, ProgramKey, AbstractApi, ProjectViewBookmark, EntityAttachment, EntityAttachmentType, EntityAttribute, ProjectView, ProjectViewLegacyTile, Camera } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, Entity, Primitive, Cesium3DTileFeature, SceneMode, GeoJsonDataSource, ColorMaterialProperty, ConstantProperty, DistanceDisplayCondition, NearFarScalar, Model, HorizontalOrigin, VerticalOrigin, ConstantPositionProperty, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, ColorBlendMode, HeadingPitchRoll, Transforms, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, Cesium3DTileset, Matrix4, Matrix3, IonResource, EllipsoidTerrainProvider, CesiumInspector, defined, ClockRange, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, IonImageryProvider, CesiumTerrainProvider, PolygonPipeline, BoundingSphere, GeometryInstance, EllipsoidGeodesic, sampleTerrainMostDetailed, ScreenSpaceEventHandler, ScreenSpaceEventType, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, CzmlDataSource, Quaternion, Intersect } from 'cesium';
3
+ import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, SceneMode, DistanceDisplayCondition, NearFarScalar, Model, ColorMaterialProperty, Entity, HorizontalOrigin, VerticalOrigin, ConstantProperty, ConstantPositionProperty, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, ColorBlendMode, HeadingPitchRoll, Transforms, Primitive, Cesium3DTileFeature, GeoJsonDataSource, Cesium3DTileColorBlendMode, HeadingPitchRange, Ion, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, IonImageryProvider, CesiumTerrainProvider, Cesium3DTileset, Matrix4, Matrix3, IonResource, CesiumInspector, defined, ClockRange, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, BoundingSphere, GeometryInstance, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, ScreenSpaceEventHandler, ScreenSpaceEventType, CzmlDataSource, Quaternion, Intersect } from 'cesium';
4
4
 
5
5
  /*! *****************************************************************************
6
6
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -9372,7 +9372,7 @@ var VisualsRegister;
9372
9372
  else {
9373
9373
  var entityRegos = this.rego[entityId];
9374
9374
  if (!entityRegos) {
9375
- return [];
9375
+ return null;
9376
9376
  }
9377
9377
  if (menuItemId) {
9378
9378
  return entityRegos.find(function (r) { return r.menuItemId === menuItemId; });
@@ -11241,6 +11241,7 @@ var EntitiesRenderManager;
11241
11241
  var rego = {
11242
11242
  entityId: entityId,
11243
11243
  menuItemId: _this.item.id,
11244
+ menuItemType: _this.item.Type,
11244
11245
  visual: thing,
11245
11246
  priority: 0,
11246
11247
  entityTypeId: group.entityTypeId,
@@ -11377,6 +11378,7 @@ var EntitiesRenderManager;
11377
11378
  entityId: id,
11378
11379
  schemaId: (_d = entity.Bruce) === null || _d === void 0 ? void 0 : _d.SchemaID,
11379
11380
  menuItemId: this.item.id,
11381
+ menuItemType: this.item.Type,
11380
11382
  visual: cEntity,
11381
11383
  priority: 0,
11382
11384
  entityTypeId: entity.Bruce["EntityType.ID"],
@@ -12115,6 +12117,7 @@ var EntitiesLoadedRenderManager;
12115
12117
  var rego = {
12116
12118
  entityId: entityId,
12117
12119
  menuItemId: _this.item.id,
12120
+ menuItemType: _this.item.Type,
12118
12121
  visual: thing,
12119
12122
  priority: 0,
12120
12123
  entityTypeId: group.entityTypeId,
@@ -12219,6 +12222,7 @@ var EntitiesLoadedRenderManager;
12219
12222
  rego: {
12220
12223
  entityId: id,
12221
12224
  menuItemId: this.item.id,
12225
+ menuItemType: this.item.Type,
12222
12226
  visual: cEntity,
12223
12227
  priority: 0,
12224
12228
  entityTypeId: entity.Bruce["EntityType.ID"],
@@ -12736,6 +12740,7 @@ var EntitiesIdsRenderManager;
12736
12740
  var rego = {
12737
12741
  entityId: entityId,
12738
12742
  menuItemId: _this.item.id,
12743
+ menuItemType: _this.item.Type,
12739
12744
  visual: thing,
12740
12745
  priority: 0,
12741
12746
  entityTypeId: group.entityTypeId,
@@ -12831,6 +12836,7 @@ var EntitiesIdsRenderManager;
12831
12836
  rego: {
12832
12837
  entityId: id,
12833
12838
  menuItemId: this.item.id,
12839
+ menuItemType: this.item.Type,
12834
12840
  visual: cEntity,
12835
12841
  priority: 0,
12836
12842
  entityTypeId: entity.Bruce["EntityType.ID"],
@@ -13050,6 +13056,7 @@ var EntityRenderManager;
13050
13056
  rego: {
13051
13057
  entityId: entity.Bruce.ID,
13052
13058
  menuItemId: this.item.id,
13059
+ menuItemType: this.item.Type,
13053
13060
  visual: cEntity,
13054
13061
  priority: 0,
13055
13062
  entityTypeId: entity.Bruce["EntityType.ID"],
@@ -14376,6 +14383,7 @@ var TilesetCadRenderManager;
14376
14383
  entityId: null,
14377
14384
  entityTypeId: null,
14378
14385
  menuItemId: this.item.id,
14386
+ menuItemType: this.item.Type,
14379
14387
  priority: 0,
14380
14388
  visual: feature,
14381
14389
  accountId: (_b = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.ClientAccountID) !== null && _b !== void 0 ? _b : this.getters.GetAccountId(),
@@ -15585,6 +15593,7 @@ var TilesetOsmRenderManager;
15585
15593
  rego = {
15586
15594
  entityId: bruceId,
15587
15595
  menuItemId: this.item.id,
15596
+ menuItemType: this.item.Type,
15588
15597
  priority: 0,
15589
15598
  visual: feature,
15590
15599
  entityTypeId: this.entityTypeId,
@@ -15877,6 +15886,7 @@ var TilesetEntitiesRenderManager;
15877
15886
  entityId: id,
15878
15887
  entityTypeId: this.typeId,
15879
15888
  menuItemId: this.item.id,
15889
+ menuItemType: this.item.Type,
15880
15890
  priority: 0,
15881
15891
  visual: feature,
15882
15892
  tilesetId: (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.TilesetID,
@@ -16517,6 +16527,7 @@ var TilesetArbRenderManager;
16517
16527
  entityId: null,
16518
16528
  entityTypeId: null,
16519
16529
  menuItemId: this.item.id,
16530
+ menuItemType: this.item.Type,
16520
16531
  priority: 0,
16521
16532
  visual: feature,
16522
16533
  accountId: (_b = (_a = this.item.tileset) === null || _a === void 0 ? void 0 : _a.ClientAccountID) !== null && _b !== void 0 ? _b : this.getters.GetAccountId(),
@@ -16964,6 +16975,7 @@ var RelationsRenderManager;
16964
16975
  rego: {
16965
16976
  entityId: (_b = relation["Data.Entity.ID"]) !== null && _b !== void 0 ? _b : ObjectUtils.UId(),
16966
16977
  menuItemId: this.item.id,
16978
+ menuItemType: this.item.Type,
16967
16979
  relation: relation,
16968
16980
  visual: cEntity,
16969
16981
  priority: 0,
@@ -17395,6 +17407,7 @@ var LegacyRelationsRenderManager;
17395
17407
  rego: {
17396
17408
  entityId: (_b = relation["Data.Entity.ID"]) !== null && _b !== void 0 ? _b : ObjectUtils.UId(),
17397
17409
  menuItemId: this.item.id,
17410
+ menuItemType: this.item.Type,
17398
17411
  relation: relation,
17399
17412
  visual: cEntity,
17400
17413
  priority: 0,
@@ -17732,6 +17745,7 @@ var DataSourceStaticCsvManager;
17732
17745
  rego: {
17733
17746
  entityId: vehicleEntityId,
17734
17747
  menuItemId: this.item.id,
17748
+ menuItemType: this.item.Type,
17735
17749
  priority: 0,
17736
17750
  visual: vehicleEntity,
17737
17751
  accountId: this.apiGetter.accountId,
@@ -17753,6 +17767,7 @@ var DataSourceStaticCsvManager;
17753
17767
  rego: {
17754
17768
  entityId: nextspaceEntityId,
17755
17769
  menuItemId: this.item.id,
17770
+ menuItemType: this.item.Type,
17756
17771
  priority: 0,
17757
17772
  visual: entity,
17758
17773
  accountId: this.apiGetter.accountId,
@@ -18157,6 +18172,604 @@ var TilesetI3sRenderManager;
18157
18172
  TilesetI3sRenderManager.Manager = Manager;
18158
18173
  })(TilesetI3sRenderManager || (TilesetI3sRenderManager = {}));
18159
18174
 
18175
+ var GoogleSearchRenderManager;
18176
+ (function (GoogleSearchRenderManager$$1) {
18177
+ var Manager = /** @class */ (function () {
18178
+ function Manager(params) {
18179
+ // If true, this menu item is disposed and should not be used.
18180
+ // Any rendering will be ignored.
18181
+ this.disposed = false;
18182
+ this.grid = new EntityGlobe.Grid();
18183
+ this.getterLoopId = 0;
18184
+ var item = params.item, register = params.register, monitor = params.monitor, viewer = params.viewer, getters = params.getters;
18185
+ this.item = item;
18186
+ this.register = register;
18187
+ this.monitor = monitor;
18188
+ this.viewer = viewer;
18189
+ this.getters = getters;
18190
+ }
18191
+ Object.defineProperty(Manager.prototype, "Disposed", {
18192
+ get: function () {
18193
+ return this.disposed;
18194
+ },
18195
+ enumerable: false,
18196
+ configurable: true
18197
+ });
18198
+ Manager.prototype.Init = function () {
18199
+ var _this = this;
18200
+ (function () { return __awaiter(_this, void 0, void 0, function () {
18201
+ var key, valid, programKey, valid, e_1;
18202
+ var _this = this;
18203
+ var _a, _b, _c, _d;
18204
+ return __generator(this, function (_e) {
18205
+ switch (_e.label) {
18206
+ case 0:
18207
+ _e.trys.push([0, 7, , 8]);
18208
+ if (!!((_c = (_b = (_a = getGoogle()) === null || _a === void 0 ? void 0 : _a.maps) === null || _b === void 0 ? void 0 : _b.places) === null || _c === void 0 ? void 0 : _c.PlacesService)) return [3 /*break*/, 6];
18209
+ key = this.item.accessToken;
18210
+ if (!key) return [3 /*break*/, 2];
18211
+ return [4 /*yield*/, validateKey(key)];
18212
+ case 1:
18213
+ valid = _e.sent();
18214
+ if (!valid) {
18215
+ console.warn("Menu Item key not valid for Google Places API. Will try use the account default.");
18216
+ key = null;
18217
+ }
18218
+ _e.label = 2;
18219
+ case 2:
18220
+ if (!!key) return [3 /*break*/, 5];
18221
+ return [4 /*yield*/, ProgramKey.Get({
18222
+ programId: ProgramKey.EProgramId.Google,
18223
+ api: this.getters.GetBruceApi()
18224
+ })];
18225
+ case 3:
18226
+ programKey = (_e.sent()).programKey;
18227
+ if (programKey === null || programKey === void 0 ? void 0 : programKey.Key) {
18228
+ key = programKey.Key;
18229
+ }
18230
+ if (!key) return [3 /*break*/, 5];
18231
+ return [4 /*yield*/, validateKey(key)];
18232
+ case 4:
18233
+ valid = _e.sent();
18234
+ if (!valid) {
18235
+ throw new Error("Account default key not valid for Google Places API.");
18236
+ }
18237
+ _e.label = 5;
18238
+ case 5:
18239
+ if (!key) {
18240
+ throw new Error("No valid key found for Google Places API.");
18241
+ }
18242
+ this.accessToken = key;
18243
+ _e.label = 6;
18244
+ case 6:
18245
+ if (this.Disposed) {
18246
+ return [2 /*return*/];
18247
+ }
18248
+ (_d = this.monitorRemoval) === null || _d === void 0 ? void 0 : _d.call(this);
18249
+ this.monitorRemoval = this.monitor.Updated().Subscribe(function () {
18250
+ _this.startGetterLoop();
18251
+ });
18252
+ this.startGetterLoop();
18253
+ return [3 /*break*/, 8];
18254
+ case 7:
18255
+ e_1 = _e.sent();
18256
+ console.error(e_1);
18257
+ return [3 /*break*/, 8];
18258
+ case 8: return [2 /*return*/];
18259
+ }
18260
+ });
18261
+ }); })();
18262
+ };
18263
+ Manager.prototype.Dispose = function () {
18264
+ var _a;
18265
+ if (this.disposed) {
18266
+ return;
18267
+ }
18268
+ this.disposed = true;
18269
+ (_a = this.monitorRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
18270
+ this.register.RemoveRegos({
18271
+ menuItemId: this.item.id
18272
+ });
18273
+ };
18274
+ Manager.prototype.ReRender = function (params) {
18275
+ // Ignore. Not relevant for this render manager.
18276
+ return;
18277
+ };
18278
+ /**
18279
+ * Starts gathering data around the view-port in blocks.
18280
+ * If a block was previously fetched in a different iteration, it is ignored.
18281
+ * This can be re-called once the camera is moved to restart the process.
18282
+ */
18283
+ Manager.prototype.startGetterLoop = function () {
18284
+ var _this = this;
18285
+ this.getterLoopId += 1;
18286
+ var loopId = this.getterLoopId;
18287
+ return new Promise(function () { return __awaiter(_this, void 0, void 0, function () {
18288
+ var MAX_HEIGHT, MIN_HEIGHT, target, bounds, alt, cells, curCellIndex, curCell, bounds_1, location_1, result, e_2;
18289
+ return __generator(this, function (_a) {
18290
+ switch (_a.label) {
18291
+ case 0:
18292
+ MAX_HEIGHT = 100000;
18293
+ MIN_HEIGHT = 1000;
18294
+ _a.label = 1;
18295
+ case 1:
18296
+ if (!((!this.monitor.GetTarget() || !this.monitor.GetBounds()) && this.getterLoopId == loopId || this.Disposed)) return [3 /*break*/, 3];
18297
+ return [4 /*yield*/, delay$1(500)];
18298
+ case 2:
18299
+ _a.sent();
18300
+ return [3 /*break*/, 1];
18301
+ case 3:
18302
+ target = this.monitor.GetTarget();
18303
+ bounds = this.monitor.GetBounds();
18304
+ if (!target || !bounds) {
18305
+ return [2 /*return*/];
18306
+ }
18307
+ alt = bounds.alt;
18308
+ if (alt == null || alt > MAX_HEIGHT || (alt < MIN_HEIGHT && MIN_HEIGHT > 0)) {
18309
+ return [2 /*return*/];
18310
+ }
18311
+ cells = this.grid.GetCellsForView(target, bounds);
18312
+ curCellIndex = cells.length > 0 ? 0 : null;
18313
+ _a.label = 4;
18314
+ case 4:
18315
+ if (!(curCellIndex != null)) return [3 /*break*/, 11];
18316
+ return [4 /*yield*/, delay$1(500)];
18317
+ case 5:
18318
+ _a.sent();
18319
+ // New loop started, break the old one.
18320
+ if (this.getterLoopId != loopId || this.Disposed) {
18321
+ return [3 /*break*/, 11];
18322
+ }
18323
+ curCell = cells[curCellIndex];
18324
+ if (curCell.IsFetched()) {
18325
+ curCell.Fetching = false;
18326
+ curCellIndex += 1;
18327
+ if (cells[curCellIndex]) {
18328
+ cells[curCellIndex].Fetching = true;
18329
+ }
18330
+ else {
18331
+ curCellIndex = null;
18332
+ }
18333
+ return [3 /*break*/, 4];
18334
+ }
18335
+ _a.label = 6;
18336
+ case 6:
18337
+ _a.trys.push([6, 9, , 10]);
18338
+ // New loop started, break the old one.
18339
+ if (this.getterLoopId != loopId) {
18340
+ return [3 /*break*/, 11];
18341
+ }
18342
+ bounds_1 = curCell.GetBounds();
18343
+ location_1 = {
18344
+ altitude: bounds_1.alt,
18345
+ latitude: bounds_1.south + ((bounds_1.north - bounds_1.south) / 2),
18346
+ longitude: bounds_1.west + ((bounds_1.east - bounds_1.west) / 2)
18347
+ };
18348
+ return [4 /*yield*/, getPlaces({
18349
+ location: location_1,
18350
+ bounds: bounds_1,
18351
+ keyword: this.item.keyword,
18352
+ accessToken: this.accessToken
18353
+ })];
18354
+ case 7:
18355
+ result = _a.sent();
18356
+ return [4 /*yield*/, this.renderPlaces(result)];
18357
+ case 8:
18358
+ _a.sent();
18359
+ if (this.getterLoopId != loopId || this.Disposed) {
18360
+ return [3 /*break*/, 11];
18361
+ }
18362
+ curCell.Fetched = true;
18363
+ curCell.Fetching = false;
18364
+ return [3 /*break*/, 10];
18365
+ case 9:
18366
+ e_2 = _a.sent();
18367
+ console.error(e_2);
18368
+ return [3 /*break*/, 11];
18369
+ case 10: return [3 /*break*/, 4];
18370
+ case 11: return [2 /*return*/];
18371
+ }
18372
+ });
18373
+ }); });
18374
+ };
18375
+ /**
18376
+ * Renders Google places on the map and registers them into the common register.
18377
+ * @param places
18378
+ * @returns
18379
+ */
18380
+ Manager.prototype.renderPlaces = function (places) {
18381
+ var _a, _b;
18382
+ return __awaiter(this, void 0, void 0, function () {
18383
+ var i, item, itemId, lat, lon, bgColor, size, canvas, pos, billboard;
18384
+ return __generator(this, function (_c) {
18385
+ switch (_c.label) {
18386
+ case 0:
18387
+ i = 0;
18388
+ _c.label = 1;
18389
+ case 1:
18390
+ if (!(i < places.length)) return [3 /*break*/, 4];
18391
+ item = places[i];
18392
+ itemId = item.place_id;
18393
+ // No ID, no item :)
18394
+ if (!itemId) {
18395
+ return [3 /*break*/, 3];
18396
+ }
18397
+ // Check if we already have this item.
18398
+ if (this.register.GetRego({
18399
+ entityId: itemId,
18400
+ menuItemId: this.item.id
18401
+ })) {
18402
+ return [3 /*break*/, 3];
18403
+ }
18404
+ lat = void 0;
18405
+ lon = void 0;
18406
+ if (item.geometry) {
18407
+ if ((_b = (_a = item.geometry.location) === null || _a === void 0 ? void 0 : _a.lat) === null || _b === void 0 ? void 0 : _b.call(_a)) {
18408
+ lat = item.geometry.location.lat();
18409
+ lon = item.geometry.location.lng();
18410
+ }
18411
+ else if (item.geometry.viewport) {
18412
+ lat = (item.geometry.viewport.Xh.lo + item.geometry.viewport.Xh.hi) / 2;
18413
+ lon = (item.geometry.viewport.Hh.lo + item.geometry.viewport.Hh.hi) / 2;
18414
+ }
18415
+ }
18416
+ if (!lat || !lon || typeof lat !== "number" || typeof lon !== "number") {
18417
+ return [3 /*break*/, 3];
18418
+ }
18419
+ bgColor = item.icon_background_color || "white";
18420
+ size = 38;
18421
+ return [4 /*yield*/, createBillboardImage(item.icon, bgColor, size)];
18422
+ case 2:
18423
+ canvas = _c.sent();
18424
+ pos = Cartesian3.fromDegrees(lon, lat);
18425
+ billboard = this.viewer.entities.add({
18426
+ position: pos,
18427
+ billboard: {
18428
+ image: canvas,
18429
+ scale: 1,
18430
+ verticalOrigin: VerticalOrigin.BOTTOM,
18431
+ heightReference: HeightReference.CLAMP_TO_GROUND
18432
+ }
18433
+ });
18434
+ CesiumEntityStyler.BakeDefaultColor({
18435
+ entity: billboard,
18436
+ viewer: this.viewer,
18437
+ colors: {
18438
+ "billboard": Color.WHITE.clone()
18439
+ },
18440
+ refresh: false
18441
+ });
18442
+ this.register.AddRego({
18443
+ rego: {
18444
+ // If we ever want the user to be able to create a Nextspace record-
18445
+ //we must match this logic with the OSM logic.
18446
+ entityId: itemId,
18447
+ sourceId: itemId,
18448
+ menuItemId: this.item.id,
18449
+ menuItemType: this.item.Type,
18450
+ priority: 0,
18451
+ visual: billboard,
18452
+ name: item.name
18453
+ },
18454
+ requestRender: false
18455
+ });
18456
+ if (this.Disposed) {
18457
+ return [3 /*break*/, 4];
18458
+ }
18459
+ _c.label = 3;
18460
+ case 3:
18461
+ i++;
18462
+ return [3 /*break*/, 1];
18463
+ case 4:
18464
+ if (this.Disposed) {
18465
+ this.register.RemoveRegos({
18466
+ menuItemId: this.item.id,
18467
+ requestRender: true
18468
+ });
18469
+ return [2 /*return*/];
18470
+ }
18471
+ this.viewer.scene.requestRender();
18472
+ return [2 /*return*/];
18473
+ }
18474
+ });
18475
+ });
18476
+ };
18477
+ return Manager;
18478
+ }());
18479
+ GoogleSearchRenderManager$$1.Manager = Manager;
18480
+ })(GoogleSearchRenderManager || (GoogleSearchRenderManager = {}));
18481
+ function delay$1(milliseconds) {
18482
+ return __awaiter(this, void 0, void 0, function () {
18483
+ return __generator(this, function (_a) {
18484
+ return [2 /*return*/, new Promise(function (res) {
18485
+ setTimeout(function () {
18486
+ res();
18487
+ }, milliseconds);
18488
+ })];
18489
+ });
18490
+ });
18491
+ }
18492
+ /**
18493
+ * Gets places of a certain type, eg: restaurant, schools, etc.
18494
+ * We can then display this on the map.
18495
+ * @param params
18496
+ */
18497
+ function getPlaces(params) {
18498
+ var _a, _b, _c;
18499
+ return __awaiter(this, void 0, void 0, function () {
18500
+ return __generator(this, function (_d) {
18501
+ // Works better with CORS.
18502
+ // Does not allow a token to be passed in.
18503
+ if ((_c = (_b = (_a = getGoogle()) === null || _a === void 0 ? void 0 : _a.maps) === null || _b === void 0 ? void 0 : _b.places) === null || _c === void 0 ? void 0 : _c.PlacesService) {
18504
+ return [2 /*return*/, getPlacesThroughLib(params)];
18505
+ }
18506
+ // Dies in localhost with CORS errors.
18507
+ return [2 /*return*/, getPlacesThroughHTTP(params)];
18508
+ });
18509
+ });
18510
+ }
18511
+ function getPlacesThroughHTTP(params) {
18512
+ return __awaiter(this, void 0, void 0, function () {
18513
+ var location, bounds, keyword, accessToken, isKeyValid, url, baseUrl, boundsStr, locationStr, baseUrl, locationStr, response, data;
18514
+ return __generator(this, function (_a) {
18515
+ switch (_a.label) {
18516
+ case 0:
18517
+ location = params.location, bounds = params.bounds, keyword = params.keyword, accessToken = params.accessToken;
18518
+ if (!accessToken) {
18519
+ throw new Error("No access token provided");
18520
+ }
18521
+ return [4 /*yield*/, validateKeyForSearches(accessToken)];
18522
+ case 1:
18523
+ isKeyValid = _a.sent();
18524
+ if (!isKeyValid) {
18525
+ throw new Error("Invalid Google API Key");
18526
+ }
18527
+ if (bounds) {
18528
+ baseUrl = "https://maps.googleapis.com/maps/api/place/textsearch/json";
18529
+ url = new URL(baseUrl);
18530
+ url.searchParams.append("key", accessToken);
18531
+ url.searchParams.append("query", keyword);
18532
+ boundsStr = "".concat(MathUtils.Round(bounds.south, 4), ",").concat(MathUtils.Round(bounds.west, 4), "|").concat(MathUtils.Round(bounds.north, 4), ",").concat(MathUtils.Round(bounds.east, 4));
18533
+ url.searchParams.append("bounds", boundsStr);
18534
+ locationStr = "".concat(MathUtils.Round(location.latitude, 4), ",").concat(MathUtils.Round(location.longitude, 4));
18535
+ url.searchParams.append("location", locationStr);
18536
+ }
18537
+ else {
18538
+ baseUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json";
18539
+ url = new URL(baseUrl);
18540
+ url.searchParams.append("key", accessToken);
18541
+ url.searchParams.append("keyword", keyword);
18542
+ locationStr = "".concat(MathUtils.Round(location.latitude, 4), ",").concat(MathUtils.Round(location.longitude, 4));
18543
+ url.searchParams.append("location", locationStr);
18544
+ url.searchParams.append("radius", "1000");
18545
+ }
18546
+ return [4 /*yield*/, fetch(url.toString())];
18547
+ case 2:
18548
+ response = _a.sent();
18549
+ if (!response.ok) {
18550
+ throw new Error("HTTP error! status: ".concat(response.status));
18551
+ }
18552
+ return [4 /*yield*/, response.json()];
18553
+ case 3:
18554
+ data = _a.sent();
18555
+ if (data.status !== "OK") {
18556
+ throw new Error("API error! status: ".concat(data.status));
18557
+ }
18558
+ return [2 /*return*/, data.results];
18559
+ }
18560
+ });
18561
+ });
18562
+ }
18563
+ function getPlacesThroughLib(params) {
18564
+ var _a, _b, _c;
18565
+ return __awaiter(this, void 0, void 0, function () {
18566
+ var location, bounds, keyword;
18567
+ return __generator(this, function (_d) {
18568
+ location = params.location, bounds = params.bounds, keyword = params.keyword;
18569
+ if (!getGoogle()) {
18570
+ throw new Error("Google is not defined");
18571
+ }
18572
+ if (!_detailsService && ((_c = (_b = (_a = getGoogle()) === null || _a === void 0 ? void 0 : _a.maps) === null || _b === void 0 ? void 0 : _b.places) === null || _c === void 0 ? void 0 : _c.PlacesService)) {
18573
+ _detailsService = new (getGoogle().maps.places.PlacesService)(document.createElement("div"));
18574
+ }
18575
+ return [2 /*return*/, new Promise(function (res, rej) {
18576
+ if (!(_detailsService === null || _detailsService === void 0 ? void 0 : _detailsService.nearbySearch)) {
18577
+ rej("Google is not defined");
18578
+ }
18579
+ var searchParams = {
18580
+ location: new (getGoogle().maps.LatLng)(location.latitude, location.longitude),
18581
+ radius: 1000,
18582
+ keyword: keyword
18583
+ };
18584
+ if (bounds) {
18585
+ searchParams["bounds"] = new (getGoogle().maps.LatLngBounds)(new (getGoogle().maps.LatLng)(bounds.south, bounds.west), new (getGoogle().maps.LatLng)(bounds.north, bounds.east));
18586
+ }
18587
+ _detailsService.nearbySearch(searchParams, function (results, status) {
18588
+ try {
18589
+ if (status === (getGoogle().maps.places.PlacesServiceStatus).OK) {
18590
+ res(results);
18591
+ }
18592
+ else {
18593
+ rej(status);
18594
+ }
18595
+ }
18596
+ catch (e) {
18597
+ rej(e);
18598
+ }
18599
+ });
18600
+ })];
18601
+ });
18602
+ });
18603
+ }
18604
+ /**
18605
+ * Returns if a google api token is valid or not for the geocoding service.
18606
+ * @param apiKey
18607
+ * @returns
18608
+ */
18609
+ function validateKey(apiKey) {
18610
+ return __awaiter(this, void 0, void 0, function () {
18611
+ return __generator(this, function (_a) {
18612
+ return [2 /*return*/, validateKeyForSearches(apiKey)];
18613
+ });
18614
+ });
18615
+ }
18616
+ var _validateKeyCache = new Map();
18617
+ /**
18618
+ * Returns if a google api token is valid or not for the geocoding service.
18619
+ * @param apiKey
18620
+ * @returns
18621
+ */
18622
+ function validateKeyForSearches(apiKey) {
18623
+ return __awaiter(this, void 0, void 0, function () {
18624
+ var prom;
18625
+ var _this = this;
18626
+ return __generator(this, function (_a) {
18627
+ if (!apiKey) {
18628
+ return [2 /*return*/, false];
18629
+ }
18630
+ if (_validateKeyCache.has(apiKey)) {
18631
+ return [2 /*return*/, _validateKeyCache.get(apiKey)];
18632
+ }
18633
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
18634
+ var url, response, data, e_3;
18635
+ return __generator(this, function (_a) {
18636
+ switch (_a.label) {
18637
+ case 0:
18638
+ url = "https://maps.googleapis.com/maps/api/geocode/json?address=invalid&key=".concat(apiKey);
18639
+ _a.label = 1;
18640
+ case 1:
18641
+ _a.trys.push([1, 4, , 5]);
18642
+ return [4 /*yield*/, fetch(url)];
18643
+ case 2:
18644
+ response = _a.sent();
18645
+ if (!response.ok) {
18646
+ console.error(response);
18647
+ res(false);
18648
+ }
18649
+ return [4 /*yield*/, response.json()];
18650
+ case 3:
18651
+ data = _a.sent();
18652
+ if (data.status === "REQUEST_DENIED") {
18653
+ console.error(data);
18654
+ res(false);
18655
+ }
18656
+ res(true);
18657
+ return [2 /*return*/];
18658
+ case 4:
18659
+ e_3 = _a.sent();
18660
+ console.error(e_3);
18661
+ return [3 /*break*/, 5];
18662
+ case 5:
18663
+ res(false);
18664
+ return [2 /*return*/];
18665
+ }
18666
+ });
18667
+ }); });
18668
+ _validateKeyCache.set(apiKey, prom);
18669
+ return [2 /*return*/, prom];
18670
+ });
18671
+ });
18672
+ }
18673
+ var _billboardCache$1 = new LRUCache(150);
18674
+ /**
18675
+ * Calculates the resized dimensions while maintaining aspect ratio.
18676
+ * @param originalWidth
18677
+ * @param originalHeight
18678
+ * @param targetWidth
18679
+ * @param targetHeight
18680
+ */
18681
+ function calculateBillboardSpace(originalWidth, originalHeight, targetWidth, targetHeight) {
18682
+ var aspectRatio = originalWidth / originalHeight;
18683
+ var newWidth = targetWidth;
18684
+ var newHeight = targetHeight;
18685
+ if (newWidth / newHeight > aspectRatio) {
18686
+ newWidth = newHeight * aspectRatio;
18687
+ }
18688
+ else {
18689
+ newHeight = newWidth / aspectRatio;
18690
+ }
18691
+ return { newWidth: newWidth, newHeight: newHeight };
18692
+ }
18693
+ /**
18694
+ * Returns a billboard image with a circle of the given size and color.
18695
+ * The image URL will be loaded and drawn on the center of the circle.
18696
+ * The promise is cached so that the same image is not loaded multiple times.
18697
+ * @param url
18698
+ * @param bgColor
18699
+ * @param width
18700
+ * @param height
18701
+ */
18702
+ function createBillboardImage(url, bgColor, size) {
18703
+ return __awaiter(this, void 0, void 0, function () {
18704
+ var key, cacheData, IMAGE_PADDING, prom;
18705
+ var _this = this;
18706
+ return __generator(this, function (_a) {
18707
+ key = "".concat(url, "-").concat(bgColor, "-").concat(size);
18708
+ cacheData = _billboardCache$1.Get(key);
18709
+ if (cacheData) {
18710
+ return [2 /*return*/, cacheData];
18711
+ }
18712
+ IMAGE_PADDING = 8;
18713
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
18714
+ var response, blob, image_1, e_4;
18715
+ return __generator(this, function (_a) {
18716
+ switch (_a.label) {
18717
+ case 0:
18718
+ _a.trys.push([0, 3, , 4]);
18719
+ return [4 /*yield*/, fetch(url)];
18720
+ case 1:
18721
+ response = _a.sent();
18722
+ return [4 /*yield*/, response.blob()];
18723
+ case 2:
18724
+ blob = _a.sent();
18725
+ image_1 = new Image();
18726
+ image_1.onload = function () {
18727
+ var canvas = document.createElement("canvas");
18728
+ canvas.width = size;
18729
+ canvas.height = size;
18730
+ var context = canvas.getContext("2d");
18731
+ // Calculate padding and available space.
18732
+ var availableSize = size - 2 * IMAGE_PADDING;
18733
+ // Calculate resized dimensions preserving aspect ratio.
18734
+ var _a = calculateBillboardSpace(image_1.width, image_1.height, availableSize, availableSize), newWidth = _a.newWidth, newHeight = _a.newHeight;
18735
+ // Draw the circular background.
18736
+ context.beginPath();
18737
+ context.arc(size / 2, size / 2, size / 2, 0, 2 * Math.PI, false);
18738
+ context.fillStyle = bgColor;
18739
+ context.fill();
18740
+ // Draw the image centered within the circle.
18741
+ var offsetX = (size - newWidth) / 2;
18742
+ var offsetY = (size - newHeight) / 2;
18743
+ context.drawImage(image_1, offsetX, offsetY, newWidth, newHeight);
18744
+ // Draw a 2px darkened border around the circle.
18745
+ context.beginPath();
18746
+ context.arc(size / 2, size / 2, size / 2 - 1, 0, 2 * Math.PI, false);
18747
+ context.lineWidth = 1;
18748
+ context.strokeStyle = "rgba(0, 0, 0, 0.3)";
18749
+ context.stroke();
18750
+ res(canvas);
18751
+ };
18752
+ image_1.onerror = function (e) { return rej(e); };
18753
+ image_1.src = URL.createObjectURL(blob);
18754
+ return [3 /*break*/, 4];
18755
+ case 3:
18756
+ e_4 = _a.sent();
18757
+ rej(e_4);
18758
+ return [3 /*break*/, 4];
18759
+ case 4: return [2 /*return*/];
18760
+ }
18761
+ });
18762
+ }); });
18763
+ _billboardCache$1.Set(key, prom);
18764
+ return [2 /*return*/, prom];
18765
+ });
18766
+ });
18767
+ }
18768
+ var _detailsService = null;
18769
+ function getGoogle() {
18770
+ return window["google"];
18771
+ }
18772
+
18160
18773
  /**
18161
18774
  * Utility to keep track of enabled menu items within a Cesium viewer.
18162
18775
  */
@@ -18444,6 +19057,15 @@ var MenuItemManager;
18444
19057
  viewer: this.viewer,
18445
19058
  });
18446
19059
  break;
19060
+ case MenuItem.EType.GoogleSearch:
19061
+ rItem.renderManager = new GoogleSearchRenderManager.Manager({
19062
+ item: params.item,
19063
+ monitor: this.sharedMonitor,
19064
+ register: this.visualsRegister,
19065
+ viewer: this.viewer,
19066
+ getters: params.getters
19067
+ });
19068
+ break;
18447
19069
  // Any "none" type can be ignored. These are just containers for other items.
18448
19070
  case MenuItem.EType.None:
18449
19071
  break;
@@ -24673,7 +25295,7 @@ var ViewRenderEngine;
24673
25295
  ViewRenderEngine.Render = Render;
24674
25296
  })(ViewRenderEngine || (ViewRenderEngine = {}));
24675
25297
 
24676
- var VERSION = "4.0.9";
25298
+ var VERSION = "4.1.0";
24677
25299
 
24678
- export { VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, CesiumEntityStyler, CesiumAnimatedProperty, CesiumAnimatedInOut, Draw3dPolygon, Draw3dPolyline };
25300
+ export { VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, GoogleSearchRenderManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, CesiumEntityStyler, CesiumAnimatedProperty, CesiumAnimatedInOut, Draw3dPolygon, Draw3dPolyline };
24679
25301
  //# sourceMappingURL=bruce-cesium.es5.js.map