Skip to content

Commit 8a8e827

Browse files
authored
fix: find annotation for selected asset for data model source (#4968)
* fixed annotation object fetch for selected asset * updated annotation array to use some method to identify matched identifer
1 parent 0773f27 commit 8a8e827

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

viewer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cognite/reveal",
3-
"version": "4.23.1",
3+
"version": "4.23.2",
44
"description": "WebGL based 3D viewer for CAD and point clouds processed in Cognite Data Fusion.",
55
"homepage": "https://github.com/cognitedata/reveal/tree/master/viewer",
66
"repository": {

viewer/packages/data-providers/src/DataSourceType.ts

+4
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,7 @@ export function isDMIdentifier(identifier: InternalModelIdentifier): identifier
141141
export function isLocalIdentifier(identifier: InternalModelIdentifier): identifier is LocalModelIdentifierType {
142142
return (identifier as LocalModelIdentifierType).localPath !== undefined;
143143
}
144+
145+
export function isSameDMIdentifier(id0: DMInstanceRef, id1: DMInstanceRef): boolean {
146+
return id0.externalId === id1.externalId && id0.space === id1.space;
147+
}

viewer/packages/data-providers/src/image-360-data-providers/CoreDm360ImageAnnotationProvider.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* Copyright 2025 Cognite AS
33
*/
4-
import { ClassicDataSourceType, DataSourceType, DMDataSourceType } from '../DataSourceType';
4+
import { ClassicDataSourceType, DataSourceType, DMDataSourceType, isSameDMIdentifier } from '../DataSourceType';
55
import {
66
Image360AnnotationFilterDelegate,
77
Image360AnnotationProvider,
@@ -18,7 +18,7 @@ import {
1818
import { isSameImage360RevisionId } from './shared';
1919
import { fetchCoreDm360AnnotationsForRevision } from './cdm/fetchCoreDm360AnnotationsForRevision';
2020
import { CogniteClient } from '@cognite/sdk/dist/src';
21-
import { fetchAnnotationsForInstance } from './cdm/fetchAnnotationsForInstance';
21+
import { fetchAnnotationsForInstance, Image360AnnotationsForInstanceResult } from './cdm/fetchAnnotationsForInstance';
2222
import { fetchCoreDm360AnnotationsForCollection } from './cdm/fetchCoreDm360AnnotationsForCollection';
2323
import { DMInstanceKey, dmInstanceRefToKey } from '@reveal/utilities';
2424

@@ -48,21 +48,30 @@ export class CoreDm360ImageAnnotationProvider implements Image360AnnotationProvi
4848
): Promise<Image360AnnotationAssetQueryResult<DMDataSourceType>[]> {
4949
const revisions = entity
5050
.getRevisions()
51-
.filter(
52-
revision =>
53-
relatedRevisionsAndAnnotations.imageRevisionIds.find(foundRevisionId =>
54-
isSameImage360RevisionId(revision.identifier, foundRevisionId)
55-
) !== undefined
51+
.filter(revision =>
52+
relatedRevisionsAndAnnotations.imageRevisionIds.some(foundRevisionId =>
53+
isSameImage360RevisionId(revision.identifier, foundRevisionId)
54+
)
5655
);
57-
return (await Promise.all(revisions.map(revision => getAnnotationInfoForRevision(entity, revision)))).flat();
56+
return (
57+
await Promise.all(
58+
revisions.map(revision => getAnnotationInfoForRevision(entity, revision, relatedRevisionsAndAnnotations))
59+
)
60+
).flat();
5861
}
5962

6063
async function getAnnotationInfoForRevision(
6164
entity: Image360Entity<DMDataSourceType>,
62-
revision: Image360RevisionEntity<DMDataSourceType>
65+
revision: Image360RevisionEntity<DMDataSourceType>,
66+
relatedRevisionsAndAnnotations: Image360AnnotationsForInstanceResult
6367
): Promise<Image360AnnotationAssetQueryResult<DMDataSourceType>[]> {
6468
const annotations = await revision.getAnnotations();
65-
return annotations.map(annotation => ({
69+
const filteredAnnotations = annotations.filter(annotation =>
70+
relatedRevisionsAndAnnotations.annotationIds.some(relatedRevisionAnnotationId =>
71+
isSameDMIdentifier(relatedRevisionAnnotationId, annotation.annotation.annotationIdentifier)
72+
)
73+
);
74+
return filteredAnnotations.map(annotation => ({
6675
image: entity,
6776
revision,
6877
annotation

viewer/packages/data-providers/src/image-360-data-providers/cdm/fetchAnnotationsForInstance.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ function getImage360AnnotationsForInstanceQuery(instance: DMInstanceRef) {
5959
},
6060
object3ds: {
6161
nodes: {
62-
from: 'instance_objects',
62+
from: 'instance_object',
6363
through: { view: COGNITE_VISUALIZABLE_SOURCE, identifier: 'object3D' },
6464
direction: 'outwards'
6565
}
6666
},
67-
annotation_dges: {
67+
annotation_edges: {
6868
edges: {
6969
from: 'object3ds',
7070
direction: 'outwards',

0 commit comments

Comments
 (0)