Skip to content

Commit

Permalink
Merge pull request #19 from IIIF-Commons/fix-null-lookat
Browse files Browse the repository at this point in the history
Fix null lookat
  • Loading branch information
JulieWinchester authored Sep 11, 2024
2 parents f46cfcd + 3c61b2d commit b2dd614
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
17 changes: 11 additions & 6 deletions src/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ export class Camera extends AnnotationBody {
* with an id matching the id of an Annotation instance.
**/
getLookAt() : object | PointSelector | null {
let rawObj = this.getPropertyAsObject("lookAt" )
let rawType = (rawObj["type"] || rawObj["@type"])
if (rawType == "Annotation"){
let rawObj = this.getPropertyAsObject("lookAt" ) ?? null;
if ( rawObj == null ) return null;

let rawType = (rawObj["type"] || rawObj["@type"]) ?? null;
if (rawType == null ) return null;

if (rawType == "Annotation")
return rawObj;
}
if (rawType == "PointSelector"){
else if (rawType == "PointSelector")
return new PointSelector(rawObj);
else{
console.error('unidentified value of lookAt ${rawType}');
return null;
}
throw new Error('unidentified value of lookAt ${rawType}');
}
get LookAt() : object | null {return this.getLookAt();}

Expand Down
7 changes: 3 additions & 4 deletions src/JSONLDResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ export class JSONLDResource {
{
let prop = this.getProperty(name);

if ( prop === null)
return prop;
else if ( typeof(prop) === 'string')

if ( typeof(prop) === 'string')
return { "id" : prop ,
"isIRI" : true
};
else if ( prop === Object(prop))
return prop;
else{
throw new Error("cannot resolve prop as object: " + prop );
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe('c_comment_annotation_camera', function() {
expect(camera.isPerspectiveCamera).to.equal(true);
});

it('camera has null LookAt property', function(){
var annotations = scene.getContent();
var body = annotations[3].getBody()[0];
var camera = body.isSpecificResource?body.Source:body;


expect(camera.LookAt).to.equal(null);
});

it('all annotation have a body', function(){
var annotations = scene.getContent();
for (var i = 0; i < annotations.length; ++i){
Expand Down

0 comments on commit b2dd614

Please sign in to comment.