Skip to content

Commit 71552f2

Browse files
committed
Migrate to stac-js
1 parent 6b77a1c commit 71552f2

26 files changed

+346
-597
lines changed

basemaps.config.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import STAC from './src/models/stac';
1+
import { Collection, Item } from './src/models/stac';
22
import Utils from './src/utils';
33

44
const USGS_ATTRIBUTION = 'USGS Astrogeology';
@@ -68,17 +68,15 @@ const BASEMAPS = {
6868
* @returns {Array.<BasemapOptions>}
6969
*/
7070
export default function configureBasemap(stac, i18n) {
71-
let targets = ['earth'];
72-
if (stac instanceof STAC) {
73-
if (stac.isCollection() && Utils.isObject(stac.summaries) && Array.isArray(stac.summaries['ssys:targets'])) {
74-
targets = stac.summaries['ssys:targets'];
75-
}
76-
else if (stac.isCollection() && Array.isArray(stac['ssys:targets'])) {
77-
targets = stac['ssys:targets'];
78-
}
79-
else if (stac.isItem() && Array.isArray(stac.properties['ssys:targets'])) {
80-
targets = stac.properties['ssys:targets'];
81-
}
71+
let targets;
72+
if (stac instanceof Collection) {
73+
targets = stac.getSummary('ssys:targets');
74+
}
75+
if (!targets) {
76+
targets = stac.getMetadata('ssys:targets');
77+
}
78+
if (!targets) {
79+
targets = ['earth'];
8280
}
8381

8482
let layers = [];

src/StacBrowser.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ import "bootstrap-vue/dist/bootstrap-vue.css";
3838
import ErrorAlert from './components/ErrorAlert.vue';
3939
import StacHeader from './components/StacHeader.vue';
4040
41-
import STAC from './models/stac';
41+
import { STAC } from 'stac-js';
4242
import Utils from './utils';
4343
import URI from 'urijs';
4444
4545
import { API_LANGUAGE_CONFORMANCE } from './i18n';
46-
import { getBest, prepareSupported } from './locale-id';
46+
import { getBest, prepareSupported } from 'stac-js/src/locales';
4747
import BrowserStorage from "./browser-store";
4848
import Authentication from "./components/Authentication.vue";
4949

src/components/Catalog.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
<script>
2323
import { mapState, mapGetters } from 'vuex';
24+
import FileFormatsMixin from './FileFormatsMixin';
2425
import StacFieldsMixin from './StacFieldsMixin';
2526
import ThumbnailCardMixin from './ThumbnailCardMixin';
2627
import StacLink from './StacLink.vue';
27-
import STAC from '../models/stac';
28+
import { STAC } from 'stac-js';
2829
import { formatMediaType, formatTemporalExtent } from '@radiantearth/stac-fields/formatters';
2930
import Utils from '../utils';
3031
@@ -39,6 +40,7 @@ export default {
3940
formatMediaType: value => formatMediaType(value, null, {shorten: true})
4041
},
4142
mixins: [
43+
FileFormatsMixin,
4244
ThumbnailCardMixin,
4345
StacFieldsMixin({ formatTemporalExtent })
4446
],
@@ -79,12 +81,6 @@ export default {
7981
}
8082
return null;
8183
},
82-
fileFormats() {
83-
if (this.data) {
84-
return this.data.getFileFormats();
85-
}
86-
return [];
87-
},
8884
keywords() {
8985
if (this.data) {
9086
return this.data.getMetadata('keywords') || [];

src/components/Catalogs.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
import { mapGetters, mapState } from 'vuex';
3939
import Catalog from './Catalog.vue';
4040
import Loading from './Loading.vue';
41-
import STAC from '../models/stac';
41+
import { getDisplayTitle } from '../models/stac';
42+
import { STAC } from 'stac-js';
4243
import ViewMixin from './ViewMixin';
4344
import Utils from '../utils';
4445
@@ -160,7 +161,7 @@ export default {
160161
// Sort
161162
if (!this.hasMore && this.sort !== 0) {
162163
const collator = new Intl.Collator(this.uiLanguage);
163-
catalogs = catalogs.slice(0).sort((a,b) => collator.compare(STAC.getDisplayTitle(a), STAC.getDisplayTitle(b)));
164+
catalogs = catalogs.slice(0).sort((a,b) => collator.compare(getDisplayTitle(a), getDisplayTitle(b)));
164165
if (this.sort === -1) {
165166
catalogs = catalogs.reverse();
166167
}

src/components/FileFormatsMixin.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Utils from '../utils';
2+
3+
export default {
4+
computed: {
5+
fileFormats() {
6+
if (!this.data) {
7+
return [];
8+
}
9+
let assets = [];
10+
if ((this.data.isItem() || this.data.isCollection()) && Utils.isObject(this.data.assets)) {
11+
assets = assets.concat(Object.values(this.data.assets));
12+
}
13+
if (this.data.isCollection() && Utils.isObject(this.data.item_assets)) {
14+
assets = assets.concat(Object.values(this.data.item_assets));
15+
}
16+
return assets
17+
.filter(asset => Array.isArray(asset.roles) && asset.roles.includes('data') && typeof asset.type === 'string') // Look for data files
18+
.map(asset => asset.type) // Array shall only contain media types
19+
.filter((v, i, a) => a.indexOf(v) === i); // Unique values
20+
}
21+
}
22+
};

src/components/Item.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424

2525
<script>
2626
import { mapState, mapGetters } from 'vuex';
27+
import FileFormatsMixin from './FileFormatsMixin';
2728
import ThumbnailCardMixin from './ThumbnailCardMixin';
2829
import StacLink from './StacLink.vue';
29-
import STAC from '../models/stac';
30+
import { STAC } from 'stac-js';
3031
import { formatTemporalExtent, formatTimestamp, formatMediaType } from '@radiantearth/stac-fields/formatters';
3132
import Registry from '@radiantearth/stac-fields/registry';
3233
import Utils from '../utils';
@@ -46,6 +47,7 @@ export default {
4647
formatTimestamp
4748
},
4849
mixins: [
50+
FileFormatsMixin,
4951
ThumbnailCardMixin
5052
],
5153
props: {
@@ -66,12 +68,6 @@ export default {
6668
}
6769
return null;
6870
},
69-
fileFormats() {
70-
if (this.data) {
71-
return this.data.getFileFormats();
72-
}
73-
return [];
74-
},
7571
keywords() {
7672
if (this.data) {
7773
return this.data.getMetadata('keywords') || [];

src/components/Items.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import Loading from './Loading.vue';
4747
import Pagination from './Pagination.vue';
4848
import { BCollapse, BIconSearch } from "bootstrap-vue";
4949
import Utils from '../utils';
50-
import STAC from '../models/stac';
50+
import { getDisplayTitle } from '../models/stac';
5151
import { mapState } from 'vuex';
5252
5353
export default {
@@ -134,7 +134,7 @@ export default {
134134
let items = this.items;
135135
if (!this.apiFilters.sortby && this.sort !== 0) {
136136
const collator = new Intl.Collator(this.uiLanguage);
137-
items = items.slice(0).sort((a,b) => collator.compare(STAC.getDisplayTitle(a), STAC.getDisplayTitle(b)));
137+
items = items.slice(0).sort((a,b) => collator.compare(getDisplayTitle(a), getDisplayTitle(b)));
138138
if (this.sort === -1) {
139139
items = items.reverse();
140140
}

src/components/SearchFilter.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ import ApiCapabilitiesMixin, { TYPES } from './ApiCapabilitiesMixin';
128128
import DatePickerMixin from './DatePickerMixin';
129129
import Loading from './Loading.vue';
130130
131-
import STAC from '../models/stac';
131+
import { CatalogLike, STAC } from 'stac-js';
132+
import { createSTAC } from '../models/stac';
132133
import Cql from '../models/cql2/cql';
133134
import Queryable from '../models/cql2/queryable';
134135
import CqlValue from '../models/cql2/value';
@@ -240,7 +241,7 @@ export default {
240241
};
241242
},
242243
collectionSearchLink() {
243-
return this.parent instanceof STAC && this.parent.getApiCollectionsLink();
244+
return this.parent instanceof CatalogLike && this.parent.getApiCollectionsLink();
244245
},
245246
canSearchCollectionsFreeText() {
246247
return this.canSearchCollections && this.supportsConformance(TYPES.Collections.FreeText);
@@ -426,9 +427,10 @@ export default {
426427
data.queryableLink = this.findQueryableLink(links) || null;
427428
}
428429
430+
// todo: use ItemCollection / CollectionCollection
429431
if (!hasMore && Array.isArray(response.data.collections)) {
430432
let collections = response.data.collections
431-
.map(collection => new STAC(collection));
433+
.map(collection => createSTAC(collection));
432434
data.collections = this.prepareCollections(collections);
433435
}
434436
}

src/components/ShowAssetLinkMixin.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Utils from '../utils';
22
import { mapGetters, mapState } from 'vuex';
33
import { stacBrowserSpecialHandling } from "../rels";
4-
import create from 'stac-js';
54

65
export default {
76
data() {
@@ -13,22 +12,15 @@ export default {
1312
computed: {
1413
...mapState(['showThumbnailsAsAssets']),
1514
...mapGetters(['data']),
16-
// hasAsset also checks whether the assets have a href and thus are not item asset definitions
17-
data2() {
18-
// todo: remove once stac-js is implemented fully
19-
if (!this.data) {
20-
return null;
21-
}
22-
return create(this.data, false);
23-
},
15+
// hasAssets in stac-js also checks whether the assets have a href and thus are not item asset definitions
2416
hasAssets() {
2517
return this.assets.length > 0;
2618
},
2719
assets() {
28-
if (!this.data2) {
20+
if (!this.data) {
2921
return [];
3022
}
31-
let assets = this.data2.getAssets();
23+
let assets = this.data.getAssets();
3224
if (!this.showThumbnailsAsAssets) {
3325
assets = assets.filter(asset => !asset.isPreview());
3426
}
@@ -38,10 +30,10 @@ export default {
3830
return this.thumbnails.length > 0;
3931
},
4032
thumbnails() {
41-
if (!this.data2) {
33+
if (!this.data) {
4234
return [];
4335
}
44-
return this.data2.getThumbnails();
36+
return this.data.getThumbnails();
4537
},
4638
additionalLinks() {
4739
if (!this.data) {

src/components/Source.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import { mapActions, mapGetters, mapState } from 'vuex';
8282
import Url from './Url.vue';
8383
8484
import Utils from '../utils';
85-
import { getBest, prepareSupported } from '../locale-id';
85+
import { getBest, prepareSupported } from '../../../stac-js/src/locales';
8686
import CopyButton from './CopyButton.vue';
8787
import SocialSharing from './SocialSharing.vue';
8888

0 commit comments

Comments
 (0)