Skip to content

Commit 864268a

Browse files
valentinMachadojailln
authored andcommitted
feat(3DTiles): add style API + C3DTFeature
1 parent f13a060 commit 864268a

11 files changed

+541
-60
lines changed

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The following people have contributed to iTowns.
3131
* [Marie Lamure](https://github.com/mlamure)
3232
* [Vincent Jaillot](https://github.com/jailln)
3333
* [Valentin Rigolle](https://github.com/Crejak)
34+
* [Valentin Machado](https://github.com/valentinMachado)
3435

3536
* [virtualcitySYSTEMS](https://www.virtualcitysystems.de/)
3637
* [Ben Kuster](https://github.com/bkuster)

docs/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
"C3DTBatchTable",
119119
"C3DTBoundingVolume",
120120
"C3DTExtensions",
121-
"C3DTBatchTableHierarchyExtension"
121+
"C3DTBatchTableHierarchyExtension",
122+
"C3DTFeature"
122123
],
123124

124125
"Plugins": [

examples/js/3dTilesHelper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ function fillHTMLWithPickingInfo(event, pickingArg) {
2323

2424
// Get information from intersected objects (from the batch table and
2525
// eventually the 3D Tiles extensions
26-
var featureDisplayableInfo = pickingArg.layer.getInfoFromIntersectObject(intersects);
26+
var closestC3DTileFeature = pickingArg.layer.getC3DTileFeatureFromIntersectsArray(intersects);
2727

28-
if (featureDisplayableInfo) {
28+
if (closestC3DTileFeature) {
2929
// eslint-disable-next-line
30-
pickingArg.htmlDiv.appendChild(createHTMLListFromObject(featureDisplayableInfo));
30+
pickingArg.htmlDiv.appendChild(createHTMLListFromObject(closestC3DTileFeature.getInfo()));
3131
}
3232
}

src/Core/3DTiles/C3DTBatchTable.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import C3DTilesTypes from './C3DTilesTypes';
1818
*/
1919
class C3DTBatchTable {
2020
/**
21-
* @param {ArrayBuffer} buffer - batch table buffer to parse
22-
* @param {number} jsonLength - batch table json part length
23-
* @param {number} binaryLength - batch table binary part length
24-
* @param {number} batchLength - the length of the batch.
25-
* @param {Object} registeredExtensions - extensions registered to the layer
21+
* @param {ArrayBuffer} [buffer=new ArrayBuffer()] - batch table buffer to parse
22+
* @param {number} [jsonLength=0] - batch table json part length
23+
* @param {number} [binaryLength=0] - batch table binary part length
24+
* @param {number} [batchLength=0] - the length of the batch.
25+
* @param {Object} [registeredExtensions] - extensions registered to the layer
2626
*/
27-
constructor(buffer, jsonLength, binaryLength, batchLength, registeredExtensions) {
27+
constructor(buffer = new ArrayBuffer(), jsonLength = 0, binaryLength = 0, batchLength = 0, registeredExtensions) {
2828
if (arguments.length === 4 &&
2929
typeof batchLength === 'object' &&
3030
!Array.isArray(batchLength) &&
@@ -40,7 +40,8 @@ class C3DTBatchTable {
4040
this.batchLength = batchLength;
4141

4242
const jsonBuffer = buffer.slice(0, jsonLength);
43-
const jsonContent = JSON.parse(utf8Decoder.decode(new Uint8Array(jsonBuffer)));
43+
const decodedJsonBuffer = utf8Decoder.decode(new Uint8Array(jsonBuffer));
44+
const jsonContent = decodedJsonBuffer === '' ? null : JSON.parse(decodedJsonBuffer);
4445

4546
if (binaryLength > 0) {
4647
const binaryBuffer = buffer.slice(jsonLength, jsonLength + binaryLength);
@@ -71,7 +72,7 @@ class C3DTBatchTable {
7172
// returned object to batchTable.extensions
7273
// Extensions must be registered in the layer (see an example of this in
7374
// 3dtiles_hierarchy.html)
74-
if (jsonContent.extensions) {
75+
if (jsonContent && jsonContent.extensions) {
7576
this.extensions =
7677
registeredExtensions.parseExtensions(jsonContent.extensions, this.type);
7778
delete jsonContent.extensions;

src/Core/3DTiles/C3DTFeature.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* C3DTFeature is a feature of a 3DTiles
3+
*
4+
* @class C3DTFeature
5+
* @param {number} tileId - tile id
6+
* @param {number} batchId - batch id
7+
* @param {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
8+
* @param {object} info - info in the batchTable
9+
* @param {object} [userData={}] - some userData
10+
* @property {number} tileId - tile id
11+
* @property {number} batchId - batch id
12+
* @property {Array<{start:number,count:number}>} groups - groups in geometry.attributes matching batchId
13+
* @property {object} info - info in the batchTable
14+
* @property {object} [userData={}] - some userData
15+
*/
16+
class C3DTFeature {
17+
#info;
18+
constructor(tileId, batchId, groups, info, userData = {}) {
19+
/** @type {number} */
20+
this.tileId = tileId;
21+
22+
/** @type {number} */
23+
this.batchId = batchId;
24+
25+
/** @type {Array<{start:number,count:number}>} */
26+
this.groups = groups;
27+
28+
/** @type {object} */
29+
this.userData = userData;
30+
31+
/** @type {object} */
32+
this.#info = info;
33+
}
34+
35+
/**
36+
*
37+
* @returns {object} - batchTable info
38+
*/
39+
getInfo() {
40+
return this.#info;
41+
}
42+
}
43+
44+
export default C3DTFeature;

0 commit comments

Comments
 (0)