Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | 1x 1x 1x 1x 1x 1x 1x 25x 1x 24x 2x 22x 1x 1x 9x 8x 1x 8x 1x 7x 7x 7x 7x 1x 7x 7x 3x 4x 4x 1x 1x 3x 1x 1x 2x 1x 1x 1x 1x 9x 8x 7x 1x 6x 6x 6x 1x 5x 5x 1x 1x 4x 1x 1x 3x 1x 2x 1x 1x 1x 1x 11x 10x 9x 8x 1x 7x 7x 7x 2x 2x 2x 2x 5x 5x 1x 1x 4x 1x 1x 3x 1x 2x 1x 1x 1x | import Check from "./Check.js";
import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
import Resource from "./Resource.js";
import RuntimeError from "./RuntimeError.js";
/**
* Default settings for accessing the iTwin platform.
*
* @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
*
* @see ITwinData
* @namespace ITwinPlatform
*/
const ITwinPlatform = {};
/**
* Status states for a mesh-export export.
* Valid values are: <code>NotStarted</code>, <code>InProgress</code>, <code>Complete</code>, <code>Invalid</code>
* @enum {string}
*/
ITwinPlatform.ExportStatus = Object.freeze({
NotStarted: "NotStarted",
InProgress: "InProgress",
Complete: "Complete",
Invalid: "Invalid",
});
/**
* Types of mesh-export exports. CesiumJS only supports loading <code>3DTILES</code> type exports.
* Valid values are: <code>IMODEL</code>, <code>CESIUM</code>, <code>3DTILES</code>
* @enum {string}
*/
ITwinPlatform.ExportType = Object.freeze({
IMODEL: "IMODEL",
CESIUM: "CESIUM",
"3DTILES": "3DTILES",
});
/**
* Types of Reality data. This is a partial list of types we know we can support
*
* @see https://developer.bentley.com/apis/reality-management/rm-rd-details/#types
* @enum {string}
*/
ITwinPlatform.RealityDataType = Object.freeze({
Cesium3DTiles: "Cesium3DTiles",
PNTS: "PNTS",
RealityMesh3DTiles: "RealityMesh3DTiles",
Terrain3DTiles: "Terrain3DTiles",
KML: "KML",
GeoJSON: "GeoJSON",
Unstructured: "Unstructured",
});
/**
* Gets or sets the default iTwin access token. This token should have the <code>itwin-platform</code> scope.
*
* This value will be ignored if {@link ITwinPlatform.defaultShareKey} is defined.
*
* @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
*
* @type {string|undefined}
*/
ITwinPlatform.defaultAccessToken = undefined;
/**
* Gets or sets the default iTwin share key. If this value is provided it will override {@link ITwinPlatform.defaultAccessToken} in all requests.
*
* Share keys can be generated using the iTwin Shares api
* https://developer.bentley.com/apis/access-control-v2/operations/create-itwin-share/
*
* @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
*
* @type {string|undefined}
*/
ITwinPlatform.defaultShareKey = undefined;
/**
* Create the necessary Authorization header based on which key/token is set.
* If the {@link ITwinPlatform.defaultShareKey} is set it takes precedence and
* will be used regardless if the {@link ITwinPlatform.defaultAccessToken} is set
* @private
* @returns {string} full auth header with basic/bearer method
*/
ITwinPlatform._getAuthorizationHeader = function () {
//>>includeStart('debug', pragmas.debug);
if (
!defined(ITwinPlatform.defaultAccessToken) &&
!defined(ITwinPlatform.defaultShareKey)
) {
throw new DeveloperError(
"Must set ITwinPlatform.defaultAccessToken or ITwinPlatform.defaultShareKey first",
);
}
//>>includeEnd('debug');
if (defined(ITwinPlatform.defaultShareKey)) {
return `Basic ${ITwinPlatform.defaultShareKey}`;
}
return `Bearer ${ITwinPlatform.defaultAccessToken}`;
};
/**
* Gets or sets the default iTwin API endpoint.
*
* @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
*
* @type {string|Resource}
* @default "https://api.bentley.com"
*/
ITwinPlatform.apiEndpoint = new Resource({
url: "https://api.bentley.com",
});
/**
* @typedef {object} ExportRequest
* @private
* @property {string} iModelId
* @property {string} changesetId
* @property {ITwinPlatform.ExportType} exportType Type of the export. CesiumJS only supports the 3DTILES type
*/
/**
* @typedef {object} Link
* @private
* @property {string} href
*/
/**
* @typedef {object} ExportRepresentation
* The export objects from get-exports when using return=representation
* @private
* @property {string} id Export id
* @property {string} displayName Name of the iModel
* @property {ITwinPlatform.ExportStatus} status Status of this export
* @property {string} lastModified
* @property {ExportRequest} request Object containing info about the export itself
* @property {{mesh: Link}} _links Object containing relevant links. For Exports this includes the access url for the mesh itself
*/
/**
* @typedef {object} GetExportsResponse
* @private
* @property {ExportRepresentation[]} exports The list of exports for the current page
* @property {{self: Link, next: Link | undefined, prev: Link | undefined}} _links Pagination links
*/
/**
* Get the list of exports for the specified iModel at it's most current version.
* This will only return the top 5 exports with {@link ITwinPlatform.ExportType} of <code>3DTILES</code>.
*
* @private
*
* @param {string} iModelId iModel id
* @param {string} [changesetId] The id of the changeset to filter results by. If not provided, exports from the latest available changesets will be returned.
* @returns {Promise<GetExportsResponse>}
*
* @throws {RuntimeError} If the iTwin API request is not successful
*/
ITwinPlatform.getExports = async function (iModelId, changesetId) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.string("iModelId", iModelId);
if (defined(changesetId)) {
Check.typeOf.string("changesetId", changesetId);
}
if (
!defined(ITwinPlatform.defaultAccessToken) &&
!defined(ITwinPlatform.defaultShareKey)
) {
throw new DeveloperError(
"Must set ITwinPlatform.defaultAccessToken or ITwinPlatform.defaultShareKey first",
);
}
//>>includeEnd('debug');
const resource = new Resource({
url: `${ITwinPlatform.apiEndpoint}mesh-export`,
headers: {
Authorization: ITwinPlatform._getAuthorizationHeader(),
Accept: "application/vnd.bentley.itwin-platform.v1+json",
Prefer: "return=representation",
},
queryParameters: {
iModelId: iModelId,
exportType: ITwinPlatform.ExportType["3DTILES"],
// With the export auto-generation it will auto-delete the 6th export so
// there should never be more than 5 results. Just request them all and parse
// for ones that are COMPLETE
$top: "5",
client: "CesiumJS",
},
});
/* global CESIUM_VERSION */
Eif (typeof CESIUM_VERSION !== "undefined") {
resource.appendQueryParameters({ clientVersion: CESIUM_VERSION });
}
if (defined(changesetId) && changesetId !== "") {
resource.appendQueryParameters({ changesetId: changesetId });
}
try {
const response = await resource.fetchJson();
return response;
} catch (error) {
const result = JSON.parse(error.response);
if (error.statusCode === 401) {
const code = result.error.details?.[0].code ?? "";
throw new RuntimeError(
`Unauthorized, bad token, wrong scopes or headers bad. ${code}`,
);
} else if (error.statusCode === 403) {
console.error(result.error.code, result.error.message);
throw new RuntimeError("Not allowed, forbidden");
} else if (error.statusCode === 422) {
throw new RuntimeError(
`Unprocessable Entity:${result.error.code} ${result.error.message}`,
);
} else Eif (error.statusCode === 429) {
throw new RuntimeError("Too many requests");
}
throw new RuntimeError(`Unknown request failure ${error.statusCode}`);
}
};
/**
* @typedef {object} RealityDataExtent
* @private
* @property {{latitude: number, longitude: number}} southWest
* @property {{latitude: number, longitude: number}} northEast
*/
/**
* @typedef {object} RealityDataRepresentation
* @private
* @property {string} id "95d8dccd-d89e-4287-bb5f-3219acbc71ae",
* @property {string} displayName "Name of reality data",
* @property {string} dataset "Dataset",
* @property {string} group "73d09423-28c3-4fdb-ab4a-03a47a5b04f8",
* @property {string} description "Description of reality data",
* @property {string} rootDocument "Directory/SubDirectory/realityData.3mx",
* @property {number} size 6521212,
* @property {string} classification "Model",
* @property {ITwinPlatform.RealityDataType} type "3MX",
* @property {{startDateTime: string, endDateTime: string, acquirer: string}} acquisition
* @property {RealityDataExtent} extent
* @property {boolean} authoring false,
* @property {string} dataCenterLocation "North Europe",
* @property {string} modifiedDateTime "2021-04-09T19:03:12Z",
* @property {string} lastAccessedDateTime "2021-04-09T00:00:00Z",
* @property {string} createdDateTime "2021-02-22T20:03:40Z",
* @property {string} ownerId "f1d49cc7-f9b3-494f-9c67-563ea5597063",
*/
/**
* Load the full metadata for the given iTwin id and reality data id.
*
* @private
*
* @param {string} iTwinId The id of the iTwin to load data from
* @param {string} realityDataId The id of the reality data to load
* @returns {Promise<RealityDataRepresentation>}
*/
ITwinPlatform.getRealityDataMetadata = async function (iTwinId, realityDataId) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.string("iTwinId", iTwinId);
Check.typeOf.string("realityDataId", realityDataId);
if (
!defined(ITwinPlatform.defaultAccessToken) &&
!defined(ITwinPlatform.defaultShareKey)
) {
throw new DeveloperError(
"Must set ITwinPlatform.defaultAccessToken or ITwinPlatform.defaultShareKey first",
);
}
//>>includeEnd('debug');
const resource = new Resource({
url: `${ITwinPlatform.apiEndpoint}reality-management/reality-data/${realityDataId}`,
headers: {
Authorization: ITwinPlatform._getAuthorizationHeader(),
Accept: "application/vnd.bentley.itwin-platform.v1+json",
},
queryParameters: { iTwinId: iTwinId },
});
try {
const response = await resource.fetchJson();
return response.realityData;
} catch (error) {
const result = JSON.parse(error.response);
if (error.statusCode === 401) {
const code = result.error.details?.[0].code ?? "";
throw new RuntimeError(
`Unauthorized, bad token, wrong scopes or headers bad. ${code}`,
);
} else if (error.statusCode === 403) {
console.error(result.error.code, result.error.message);
throw new RuntimeError("Not allowed, forbidden");
} else if (error.statusCode === 404) {
throw new RuntimeError(
`Reality data not found: ${iTwinId}, ${realityDataId}`,
);
} else if (error.statusCode === 422) {
throw new RuntimeError(
`Unprocessable Entity:${result.error.code} ${result.error.message}`,
);
} else Eif (error.statusCode === 429) {
throw new RuntimeError("Too many requests");
}
throw new RuntimeError(`Unknown request failure ${error.statusCode}`);
}
};
/**
* Request the access url for the given iTwin id, reality data id and root document.
* The root document can be requested from the list using <code>return=representation</code>
* or the metadata route from {@link ITwinPlatform.getRealityDataMetadata}
*
* @private
*
* @param {string} iTwinId The id of the iTwin to load data from
* @param {string} realityDataId The id of the reality data to load
* @param {string} rootDocument The path of the root document for this reality data
* @returns {Promise<string>}
*/
ITwinPlatform.getRealityDataURL = async function (
iTwinId,
realityDataId,
rootDocument,
) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.string("iTwinId", iTwinId);
Check.typeOf.string("realityDataId", realityDataId);
Check.typeOf.string("rootDocument", rootDocument);
if (
!defined(ITwinPlatform.defaultAccessToken) &&
!defined(ITwinPlatform.defaultShareKey)
) {
throw new DeveloperError(
"Must set ITwinPlatform.defaultAccessToken or ITwinPlatform.defaultShareKey first",
);
}
//>>includeEnd('debug');
const resource = new Resource({
url: `${ITwinPlatform.apiEndpoint}reality-management/reality-data/${realityDataId}/readaccess`,
headers: {
Authorization: ITwinPlatform._getAuthorizationHeader(),
Accept: "application/vnd.bentley.itwin-platform.v1+json",
},
queryParameters: { iTwinId: iTwinId },
});
try {
const result = await resource.fetchJson();
const containerUrl = result._links.containerUrl.href;
const tilesetUrl = new URL(containerUrl);
tilesetUrl.pathname = `${tilesetUrl.pathname}/${rootDocument}`;
return tilesetUrl.toString();
} catch (error) {
const result = JSON.parse(error.response);
if (error.statusCode === 401) {
const code = result.error.details?.[0].code ?? "";
throw new RuntimeError(
`Unauthorized, bad token, wrong scopes or headers bad. ${code}`,
);
} else if (error.statusCode === 403) {
console.error(result.error.code, result.error.message);
throw new RuntimeError("Not allowed, forbidden");
} else if (error.statusCode === 404) {
throw new RuntimeError(
`Reality data not found: ${iTwinId}, ${realityDataId}`,
);
} else if (error.statusCode === 422) {
throw new RuntimeError(
`Unprocessable Entity:${result.error.code} ${result.error.message}`,
);
} else Eif (error.statusCode === 429) {
throw new RuntimeError("Too many requests");
}
throw new RuntimeError(`Unknown request failure ${error.statusCode}`);
}
};
export default ITwinPlatform;
|