Skip to content

Commit

Permalink
add support for geospatial features API
Browse files Browse the repository at this point in the history
  • Loading branch information
jjspace committed Jan 23, 2025
1 parent dc667cd commit be5f5a7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
16 changes: 8 additions & 8 deletions Apps/Sandcastle/gallery/iTwin Feature Service.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@
viewer.scene.camera.flyTo(birdsEyeView);

// Load feature service geojson files
const points = await Cesium.ITwinData.createDataSourceForRealityDataId(
const points = await Cesium.ITwinData.loadGeospatialFeatures(
iTwinId,
"57b975f6-fd92-42ba-8014-79911ed606d1",
"aef2f202-1ac8-4bb7-8a5f-9b75a8665c41",
);
const lines = await Cesium.ITwinData.createDataSourceForRealityDataId(
const lines = await Cesium.ITwinData.loadGeospatialFeatures(
iTwinId,
"1099c53f-c568-48a3-a57c-0230a6f37229",
"613d2310-4d01-43b7-bc92-873a2ca4a4a0",
);
const areas = await Cesium.ITwinData.createDataSourceForRealityDataId(
const areas = await Cesium.ITwinData.loadGeospatialFeatures(
iTwinId,
"21eaf0d0-ab90-400f-97cf-adc455b29a78",
"93e7ef51-5210-49f2-92a3-c7f6685e102f",
);

// Add some styling to the lines and points to differentiate types
Expand All @@ -86,7 +86,7 @@
Arrow_Marking: { color: Cesium.Color.YELLOW, icon: "car" },
Road_Sign: { color: Cesium.Color.ORANGE, icon: "triangle" },
};
const type = entity.properties.Type?.getValue();
const type = entity.properties.type?.getValue();
if (Cesium.defined(type) && Cesium.defined(styleByType[type])) {
const { color, icon } = styleByType[type];
const canvas = await pinBuilder.fromMakiIconId(icon, color, 48);
Expand All @@ -103,7 +103,7 @@
Turning_pocket: Cesium.Color.DEEPPINK,
Yellow_Box: Cesium.Color.GOLD,
};
const type = entity.properties.Type?.getValue();
const type = entity.properties.type?.getValue();
if (Cesium.defined(type) && Cesium.defined(lineColorsByType[type])) {
entity.polyline.material = lineColorsByType[type];
}
Expand Down
36 changes: 35 additions & 1 deletion packages/engine/Source/Scene/ITwinData.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ ITwinData.createTilesetForRealityDataId = async function (
*
* @throws {RuntimeError} if the type of reality data is not supported by this function
*/
ITwinData.createDataSourceForRealityDataId = async function loadRealityData(
ITwinData.createDataSourceForRealityDataId = async function (
iTwinId,
realityDataId,
type,
Expand Down Expand Up @@ -205,4 +205,38 @@ ITwinData.createDataSourceForRealityDataId = async function loadRealityData(
return KmlDataSource.load(tilesetAccessUrl);
};

ITwinData.loadGeospatialFeatures = async function (
iTwinId,
collectionId,
limit,
) {
////>>includeStart('debug', pragmas.debug);
Check.typeOf.string("iTwinId", iTwinId);
Check.typeOf.string("collectionId", collectionId);
if (defined(limit)) {
Check.typeOf.number("limit", limit);
Check.typeOf.number.lessThanOrEquals("limit", limit, 10000);
Check.typeOf.number.greaterThanOrEquals("limit", limit, 1);
}
//>>includeEnd('debug')

const pageLimit = limit ?? 10000;

const tilesetUrl = `${ITwinPlatform.apiEndpoint}/geospatial-features/itwins/${iTwinId}/ogc/collections/${collectionId}/items`;

const resource = new Resource({
url: tilesetUrl,
headers: {
Authorization: `Bearer ${ITwinPlatform.defaultAccessToken}`,
Accept: "application/vnd.bentley.itwin-platform.v1+json",
},
queryParameters: {
limit: pageLimit,
client: "CesiumJS",
},
});

return GeoJsonDataSource.load(resource);
};

export default ITwinData;

0 comments on commit be5f5a7

Please sign in to comment.