File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import bboxPolygon from "@turf/bbox-polygon";
33import type { FeatureCollection } from "geojson" ;
44import type {
55 SpatialExtent ,
6- StacAsset ,
76 StacCollection ,
87 StacItem ,
98 StacLink ,
@@ -62,7 +61,13 @@ export function getSelfHref(value: StacValue) {
6261
6362export function getThumbnailAsset ( value : StacValue ) {
6463 if ( "assets" in value ) {
65- const asset = ( value . assets as { [ key : string ] : StacAsset } ) [ "thumbnail" ] ;
64+ const assets = value . assets as StacAssets ;
65+ const asset =
66+ assets [ "thumbnail" ] ||
67+ Object . values ( assets ) . find ( ( asset ) =>
68+ asset . roles ?. includes ( "thumbnail" )
69+ ) ||
70+ assets [ "thumbnails" ] ;
6671 return asset ?. href . startsWith ( "http" ) && asset ;
6772 }
6873}
Original file line number Diff line number Diff line change @@ -168,6 +168,30 @@ describe("getThumbnailAsset", () => {
168168 item . assets = { data : { href : "http://example.com/data.tiff" } } ;
169169 expect ( getThumbnailAsset ( item ) ) . toBeUndefined ( ) ;
170170 } ) ;
171+
172+ test ( "returns thumbnail asset if it has thumbnail role" , ( ) => {
173+ const item = makeItem ( "test" ) ;
174+ item . assets = {
175+ foo : { href : "http://example.com/thumb.png" , roles : [ "thumbnail" ] } ,
176+ } ;
177+ expect ( getThumbnailAsset ( item ) ) . toEqual ( {
178+ href : "http://example.com/thumb.png" ,
179+ roles : [ "thumbnail" ] ,
180+ } ) ;
181+ } ) ;
182+
183+ test ( "returns thumbnail asset if it has thumbnails key" , ( ) => {
184+ // https://github.com/englacial/xopr/issues/64
185+ const item = makeItem ( "test" ) ;
186+ item . assets = {
187+ thumbnails : {
188+ href : "http://example.com/thumb.png" ,
189+ } ,
190+ } ;
191+ expect ( getThumbnailAsset ( item ) ) . toEqual ( {
192+ href : "http://example.com/thumb.png" ,
193+ } ) ;
194+ } ) ;
171195} ) ;
172196
173197describe ( "makeHrefsAbsolute" , ( ) => {
You can’t perform that action at this time.
0 commit comments