当前位置:网站首页>Cesium learning notes (II) uploading data using rest API
Cesium learning notes (II) uploading data using rest API
2022-06-30 08:04:00 【Lafiteeee】
Step1. Provide ion information about your data
Use the data files provided on the official website :Reichstag.zip
To create a new asset, we POST information about our data and what we want to do with it to the /v1/assets endpoint. The POST body looks like this:
const postBody = {
name: 'Reichstag',
description: 'See [Wikipedia](https://en.wikipedia.org/?curid=217577).',
type: '3DTILES',
options: {
sourceType: 'CITYGML',
clampToTerrain: true,
baseTerrainId: 1
}
}
name
Is a non empty stringdescription
It's a Markdown Compatible stringtype
Is one of three types :3DTILES
、IMAGERY
、TERRAIN
, Now uploading CityGML, It can only be used to generate 3DTILESoptions
yes the ion tilling pipeline The option to , And specific to the type of data being uploaded . In this example, specify :sourceType
Indicates that we are uploading CityGML dataclampToTerrain
tell pipeline, We want it to adjust the height of the buildings in the file so that they are placed on the groundbaseTerrainID
To specify a terrain asset id As the ground . In the code above ,“1” representative CesiumWorldTerrain. If not defined andclamoToTerrain = true
, Then the building will be put into WGS84 Ellipsoid .
To actually create assets , We use the following code to publish the above objects :
const response = await request({
url: 'https://api.cesium.com/v1/assets',
method: 'POST',
headers: {
Authorization: `Bearer ${
accessToken}` },
json: true,
body: postBody
});
This service returns response
It has three properties :
response.uploadLocation
Provide temporary vouchers and location information , Used to upload source data to ion, The credentials last about 1 Hours .response.onComplete
It contains the information that we will use to send back to the server after uploading the data .response.assetMetadata
Include this asset All the information about it, including its id、 state , And the name and description we just released .
This response as follows :
{
"assetMetadata": {
"id": 21111,
"type": "3DTILES",
"name": "Reichstag",
"description": "See [Wikipedia](https://en.wikipedia.org/?curid=217577).",
"attribution": "",
"bytes": 0,
"dateAdded": "2019-04-19T00:30:54.111Z",
"status": "AWAITING_FILES",
"percentComplete": 0
},
"uploadLocation": {
"bucket": "assets.cesium.com",
"prefix": "sources/21111/",
"accessKey": "ASIATXRQLSFCKKLAIVXW",
"secretAccessKey": "Qa6YC2yq78hoCR4KYF4atHEnytfgLJMNV0KPdpw8",
"sessionToken": "FQoGZXIvYXdzEIr//wEaDIEDvhx6N7x4..."
},
"onComplete": {
"method": "POST",
"url": "https://api.cesium.com/v1/assets/21111/uploadComplete",
"fields": {
}
}
}
Step 2.Upload your data to the provided Amazon S3 bucket
We can use anything with S3 Compatible libraries to perform Uploads , However, we recommend using official services that are widely available in multiple languages AWS Development kit . Everything we need is response.uploadLocation
In the object .
Every asset Of S3 API Initialization is the same :
const AWS = require('aws-sdk');
const uploadLocation = response.uploadLocation;
const s3 = new AWS.S3({
apiVersion: '2006-03-01',
region: 'us-east-1',
signatureVersion: 'v4',
endpoint: uploadLocation.endpoint,
credentials: new AWS.Credentials(
uploadLocation.accessKey,
uploadLocation.secretAccessKey,
uploadLocation.sessionToken)
});
thus , We can use s3 The instance uploads the required number of files . In this example , Everything is contained in a single zip In file , So we can use a single upload call . If you have multiple files , Just use different “Body” and “Key” Property to perform multiple s3.upload call . Make sure to use Reichstag.zip Position replacement of path_to_file.
const input = 'path_to_file/Reichstag.zip';
const fs = require('fs');
await s3.upload({
Body: fs.createReadStream(input),
Bucket: uploadLocation.bucket,
Key: `${
uploadLocation.prefix}Reichstag.zip`
}).promise();
Step 3: Notify ion that you are finished uploading
After the data is uploaded , We will use response.onComplete
The message in the object emits a second POST request . This tells the server that all source data has been uploaded , And you can start tiling The process .
const onComplete = response.onComplete;
await request({
url: onComplete.url,
method: onComplete.method,
headers: {
Authorization: `Bearer ${
accessToken}` },
json: true,
body: onComplete.fields
});
Step 4: Monitor the tiling status
Now? asset Has been tiled into 3D Tiles And there are no steps to do . You can go to Asset Dashboard see tile speed of progress , You can also use REST API To monitor progress , So that you can take some action when you finish .
This can be used GET / v1 / assets / {assetId}
Endpoint to achieve , among {assetId}
It's the beginning POST In response response.assetMetadata.id
.
async function waitUntilReady() {
const assetId = response.assetMetadata.id;
// Issue a GET request for the metadata
const assetMetadata = await request({
url: `https://api.cesium.com/v1/assets/${
assetId}`,
headers: {
Authorization: `Bearer ${
accessToken}` },
json: true
});
const status = assetMetadata.status;
if (status === 'COMPLETE') {
console.log('Asset tiled successfully');
console.log(`View in ion: https://cesium.com/ion/assets/${
assetMetadata.id}`);
} else if (status === 'DATA_ERROR') {
console.log('ion detected a problem with the uploaded data.');
} else if (status === 'ERROR') {
console.log('An unknown tiling error occurred, please contact [email protected]');
} else {
if (status === 'NOT_STARTED') {
console.log('Tiling pipeline initializing.');
} else {
// IN_PROGRESS
console.log(`Asset is ${
assetMetadata.percentComplete}% complete.`);
}
// Not done yet, check again in 10 seconds
setTimeout(waitUntilReady, 10000);
}
}
waitUntilReady();
边栏推荐
- MySQL quotation sentence is unlocked: algorithm=insert, lock=none
- Efga design open source framework fabulous series (I) establishment of development environment
- Want to ask, how to choose securities companies for stock speculation? Is it safe to open an account online?
- 想转行,却又不知道干什么?此文写给正在迷茫的你
- Introduction to opencv (II): image color space conversion and image saving
- 想问问,炒股怎么选择证券公司?网上开户安全么?
- 期末复习-PHP学习笔记2-PHP语言基础
- 深度学习——BRNN和DRNN
- CRM&PM如何帮助企业创造最优销售绩效
- 2021.11.20 [reading notes] | differential variable splicing events and DTU analysis
猜你喜欢
深度学习——使用词嵌入and词嵌入特征
Final review -php learning notes 2-php language foundation
Deep learning - goal orientation
Opencv4.2.0+vs2015 configuration
鲸探NFT数字臧品系统开发技术分享
February 14, 2022 [reading notes] - life science based on deep learning Chapter 2 Introduction to deep learning (Part 1)
How CRM & PM helps enterprises create optimal sales performance
领域驱动下cloud项目中单个服务的示例
2022.01.20 [bug note] | qiime2: an error was encoded while running dada2 in R (return code 1)
Full stack performance testing theory - Summary
随机推荐
Armv8 (coretex-a53) debugging based on openocd and ft2232h
Experiment 6 examination
JS code case
Pre ++ and post ++ overloads
tp5设置直接下载文件
Go 数据类型篇之字符串及底层字符类型
【Tensorflow-gpu】window11下深度学习环境搭建
期末复习-PHP学习笔记5-PHP数组
Simple application of generating function -- integer splitting 2
December 4, 2021 [metagenome] - sorting out the progress of metagenome process construction
Palindrome substring, palindrome subsequence
Introduction to opencv (I): image reading and display
Deep learning - bounding box prediction
深度学习——残差网络ResNets
Personal blog one article multi post tutorial - basic usage of openwriter management tool
深度学习——Bounding Box预测
亚马逊测评术语有哪些?
[notes] polygon mesh processing learning notes (10)
July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)
[JUC series] overview of fork/join framework