Skip to content

Commit 1c8fe72

Browse files
committed
Merge branch 'main' of https://github.com/CesiumGS/cesium into workspaces
2 parents dec53a3 + 9255f0d commit 1c8fe72

11 files changed

+298
-143
lines changed

Apps/Sandcastle/gallery/I3S 3D Object Layer.html

+22-37
Original file line numberDiff line numberDiff line change
@@ -102,55 +102,40 @@ <h1>Loading...</h1>
102102
Cesium.defined(pickedFeature.content.tile.i3sNode)
103103
) {
104104
const i3sNode = pickedFeature.content.tile.i3sNode;
105-
i3sNode.loadFields().then(function () {
106-
const geometry = i3sNode.geometryData[0];
107-
if (pickedPosition) {
108-
const location = geometry.getClosestPointIndexOnTriangle(
109-
pickedPosition.x,
110-
pickedPosition.y,
111-
pickedPosition.z
112-
);
105+
if (pickedPosition) {
106+
i3sNode.loadFields().then(function () {
113107
let description = "No attributes";
114108
let name;
115-
if (
116-
location.index !== -1 &&
117-
geometry.customAttributes.featureIndex
118-
) {
119-
console.log(
120-
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
121-
);
122-
const featureIndex =
123-
geometry.customAttributes.featureIndex[location.index];
124-
if (Object.keys(i3sNode.fields).length > 0) {
125-
description =
126-
'<table class="cesium-infoBox-defaultTable"><tbody>';
127-
for (const fieldName in i3sNode.fields) {
128-
if (i3sNode.fields.hasOwnProperty(fieldName)) {
129-
const field = i3sNode.fields[fieldName];
130-
description += `<tr><th>${field.name}</th><td>`;
131-
description += `${field.values[featureIndex]}</td></tr>`;
132-
console.log(
133-
`${field.name}: ${field.values[featureIndex]}`
134-
);
135-
if (
136-
!Cesium.defined(name) &&
137-
isNameProperty(field.name)
138-
) {
139-
name = field.values[featureIndex];
140-
}
109+
console.log(
110+
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
111+
);
112+
113+
const fields = i3sNode.getFieldsForPickedPosition(
114+
pickedPosition
115+
);
116+
if (Object.keys(fields).length > 0) {
117+
description =
118+
'<table class="cesium-infoBox-defaultTable"><tbody>';
119+
for (const fieldName in fields) {
120+
if (i3sNode.fields.hasOwnProperty(fieldName)) {
121+
description += `<tr><th>${fieldName}</th><td>`;
122+
description += `${fields[fieldName]}</td></tr>`;
123+
console.log(`${fieldName}: ${fields[fieldName]}`);
124+
if (!Cesium.defined(name) && isNameProperty(fieldName)) {
125+
name = fields[fieldName];
141126
}
142127
}
143-
description += `</tbody></table>`;
144128
}
129+
description += `</tbody></table>`;
145130
}
146131
if (!Cesium.defined(name)) {
147132
name = "unknown";
148133
}
149134
selectedEntity.name = name;
150135
selectedEntity.description = description;
151136
viewer.selectedEntity = selectedEntity;
152-
}
153-
});
137+
});
138+
}
154139
}
155140
},
156141
Cesium.ScreenSpaceEventType.LEFT_CLICK);

Apps/Sandcastle/gallery/I3S Feature Picking.html

+22-37
Original file line numberDiff line numberDiff line change
@@ -102,55 +102,40 @@ <h1>Loading...</h1>
102102
Cesium.defined(pickedFeature.content.tile.i3sNode)
103103
) {
104104
const i3sNode = pickedFeature.content.tile.i3sNode;
105-
i3sNode.loadFields().then(function () {
106-
const geometry = i3sNode.geometryData[0];
107-
if (pickedPosition) {
108-
const location = geometry.getClosestPointIndexOnTriangle(
109-
pickedPosition.x,
110-
pickedPosition.y,
111-
pickedPosition.z
112-
);
105+
if (pickedPosition) {
106+
i3sNode.loadFields().then(function () {
113107
let description = "No attributes";
114108
let name;
115-
if (
116-
location.index !== -1 &&
117-
geometry.customAttributes.featureIndex
118-
) {
119-
console.log(
120-
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
121-
);
122-
const featureIndex =
123-
geometry.customAttributes.featureIndex[location.index];
124-
if (Object.keys(i3sNode.fields).length > 0) {
125-
description =
126-
'<table class="cesium-infoBox-defaultTable"><tbody>';
127-
for (const fieldName in i3sNode.fields) {
128-
if (i3sNode.fields.hasOwnProperty(fieldName)) {
129-
const field = i3sNode.fields[fieldName];
130-
description += `<tr><th>${field.name}</th><td>`;
131-
description += `${field.values[featureIndex]}</td></tr>`;
132-
console.log(
133-
`${field.name}: ${field.values[featureIndex]}`
134-
);
135-
if (
136-
!Cesium.defined(name) &&
137-
isNameProperty(field.name)
138-
) {
139-
name = field.values[featureIndex];
140-
}
109+
console.log(
110+
`pickedPosition(x,y,z) : ${pickedPosition.x}, ${pickedPosition.y}, ${pickedPosition.z}`
111+
);
112+
113+
const fields = i3sNode.getFieldsForPickedPosition(
114+
pickedPosition
115+
);
116+
if (Object.keys(fields).length > 0) {
117+
description =
118+
'<table class="cesium-infoBox-defaultTable"><tbody>';
119+
for (const fieldName in fields) {
120+
if (i3sNode.fields.hasOwnProperty(fieldName)) {
121+
description += `<tr><th>${fieldName}</th><td>`;
122+
description += `${fields[fieldName]}</td></tr>`;
123+
console.log(`${fieldName}: ${fields[fieldName]}`);
124+
if (!Cesium.defined(name) && isNameProperty(fieldName)) {
125+
name = fields[fieldName];
141126
}
142127
}
143-
description += `</tbody></table>`;
144128
}
129+
description += `</tbody></table>`;
145130
}
146131
if (!Cesium.defined(name)) {
147132
name = "unknown";
148133
}
149134
selectedEntity.name = name;
150135
selectedEntity.description = description;
151136
viewer.selectedEntity = selectedEntity;
152-
}
153-
});
137+
});
138+
}
154139
}
155140
},
156141
Cesium.ScreenSpaceEventType.LEFT_CLICK);

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
337337
- [Ilya Shevelev](https://github.com/ilyaly)
338338
- [Gabriel Aldous](https://github.com/Sn00pyW00dst0ck)
339339
- [金俊](https://github.com/jinjun1994)
340+
- [Oussama Bonnor](https://github.com/oussamabonnor1)

packages/engine/Source/Scene/I3SDataProvider.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ I3SDataProvider.prototype._loadGeoidData = function () {
626626
console.log(
627627
"No Geoid Terrain service provided - no geoid conversion will be performed."
628628
);
629-
return Promise.resolve();
629+
this._geoidDataIsReadyPromise = Promise.resolve();
630+
return this._geoidDataIsReadyPromise;
630631
}
631632

632633
this._geoidDataIsReadyPromise = geoidTerrainProvider.readyPromise.then(

packages/engine/Source/Scene/I3SFeature.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Object.defineProperties(I3SFeature.prototype, {
4949

5050
/**
5151
* Loads the content.
52-
* @returns {Promise.<Object>} A promise that is resolved when the data of the I3S feature is loaded
52+
* @returns {Promise} A promise that is resolved when the data of the I3S feature is loaded
5353
* @private
5454
*/
5555
I3SFeature.prototype.load = function () {

packages/engine/Source/Scene/I3SLayer.js

+64-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ function I3SLayer(dataProvider, layerData, index) {
3535
.concat(`${layerData.href}`);
3636
}
3737

38+
this._version = layerData.store.version;
39+
const splitVersion = this._version.split(".");
40+
this._majorVersion = parseInt(splitVersion[0]);
41+
this._minorVersion = splitVersion.length > 1 ? parseInt(splitVersion[1]) : 0;
42+
3843
this._resource = new Resource({ url: tilesetUrl });
3944
this._resource.setQueryParameters(
4045
this._dataProvider.resource.queryParameters
@@ -98,11 +103,68 @@ Object.defineProperties(I3SLayer.prototype, {
98103
return this._data;
99104
},
100105
},
106+
107+
/**
108+
* The version string of the loaded I3S dataset
109+
* @memberof I3SLayer.prototype
110+
* @type {String}
111+
* @readonly
112+
*/
113+
version: {
114+
get: function () {
115+
return this._version;
116+
},
117+
},
118+
119+
/**
120+
* The major version number of the loaded I3S dataset
121+
* @memberof I3SLayer.prototype
122+
* @type {Number}
123+
* @readonly
124+
*/
125+
majorVersion: {
126+
get: function () {
127+
return this._majorVersion;
128+
},
129+
},
130+
131+
/**
132+
* The minor version number of the loaded I3S dataset
133+
* @memberof I3SLayer.prototype
134+
* @type {Number}
135+
* @readonly
136+
*/
137+
minorVersion: {
138+
get: function () {
139+
return this._minorVersion;
140+
},
141+
},
142+
143+
/**
144+
* When <code>true</code>, when the loaded I3S version is 1.6 or older
145+
* @memberof I3SLayer.prototype
146+
* @type {Boolean}
147+
* @readonly
148+
*/
149+
legacyVersion16: {
150+
get: function () {
151+
if (!defined(this.version)) {
152+
return undefined;
153+
}
154+
if (
155+
this.majorVersion < 1 ||
156+
(this.majorVersion === 1 && this.minorVersion <= 6)
157+
) {
158+
return true;
159+
}
160+
return false;
161+
},
162+
},
101163
});
102164

103165
/**
104166
* Loads the content, including the root node definition and its children
105-
* @returns {Promise.<void>} A promise that is resolved when the layer data is loaded
167+
* @returns {Promise} A promise that is resolved when the layer data is loaded
106168
* @private
107169
*/
108170
I3SLayer.prototype.load = function () {
@@ -121,7 +183,7 @@ I3SLayer.prototype.load = function () {
121183
return that._tileset.readyPromise.then(function () {
122184
that._rootNode._tile = that._tileset._root;
123185
that._tileset._root._i3sNode = that._rootNode;
124-
if (that._data.store.version === "1.6") {
186+
if (that.legacyVersion16) {
125187
return that._rootNode._loadChildren();
126188
}
127189
});

packages/engine/Source/Scene/I3SNode.js

+50-6
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,52 @@ I3SNode.prototype.loadFields = function () {
240240
return Promise.all(promises);
241241
};
242242

243+
/**
244+
* Returns the fields for a given picked position
245+
* @param {Cartesian3} pickedPosition The picked position
246+
* @returns {Object} Object containing field names and their values
247+
*/
248+
I3SNode.prototype.getFieldsForPickedPosition = function (pickedPosition) {
249+
const geometry = this.geometryData[0];
250+
if (!defined(geometry.customAttributes.featureIndex)) {
251+
return {};
252+
}
253+
254+
const location = geometry.getClosestPointIndexOnTriangle(
255+
pickedPosition.x,
256+
pickedPosition.y,
257+
pickedPosition.z
258+
);
259+
260+
if (
261+
location.index === -1 ||
262+
location.index > geometry.customAttributes.featureIndex.length
263+
) {
264+
return {};
265+
}
266+
267+
const featureIndex = geometry.customAttributes.featureIndex[location.index];
268+
return this.getFieldsForFeature(featureIndex);
269+
};
270+
271+
/**
272+
* Returns the fields for a given feature
273+
* @param {Number} featureIndex Index of the feature whose attributes we want to get
274+
* @returns {Object} Object containing field names and their values
275+
*/
276+
I3SNode.prototype.getFieldsForFeature = function (featureIndex) {
277+
const featureFields = {};
278+
for (const fieldName in this.fields) {
279+
if (this.fields.hasOwnProperty(fieldName)) {
280+
const field = this.fields[fieldName];
281+
if (featureIndex >= 0 && featureIndex < field.values.length) {
282+
featureFields[field.name] = field.values[featureIndex];
283+
}
284+
}
285+
}
286+
return featureFields;
287+
};
288+
243289
/**
244290
* @private
245291
*/
@@ -336,11 +382,6 @@ I3SNode.prototype._loadFeatureData = function () {
336382
this._featureData.push(newFeatureData);
337383
featurePromises.push(newFeatureData.load());
338384
}
339-
} else if (defined(this._data.mesh) && defined(this._data.mesh.attribute)) {
340-
const featureURI = `./features/0`;
341-
const newFeatureData = new I3SFeature(this, featureURI);
342-
this._featureData.push(newFeatureData);
343-
featurePromises.push(newFeatureData.load());
344385
}
345386

346387
return Promise.all(featurePromises);
@@ -661,7 +702,10 @@ I3SNode.prototype._createContentURL = function () {
661702
};
662703

663704
// Load the geometry data
664-
const dataPromises = [this._loadFeatureData(), this._loadGeometryData()];
705+
const dataPromises = [this._loadGeometryData()];
706+
if (this._dataProvider.legacyVersion16) {
707+
dataPromises.push(this._loadFeatureData());
708+
}
665709

666710
const that = this;
667711
return Promise.all(dataPromises).then(function () {

0 commit comments

Comments
 (0)