diff --git a/libs/feature/dataviz/src/lib/service/data.service.ts b/libs/feature/dataviz/src/lib/service/data.service.ts index a260d5e482..e1a2211059 100644 --- a/libs/feature/dataviz/src/lib/service/data.service.ts +++ b/libs/feature/dataviz/src/lib/service/data.service.ts @@ -1,6 +1,11 @@ import { Injectable } from '@angular/core' import { marker } from '@biesbjerg/ngx-translate-extract-marker' -import { WfsEndpoint, WfsVersion } from '@camptocamp/ogc-client' +import { + OgcApiCollectionInfo, + OgcApiEndpoint, + WfsEndpoint, + WfsVersion, +} from '@camptocamp/ogc-client' import { BaseReader, FetchError, @@ -12,6 +17,7 @@ import { getFileFormat, getFileFormatFromServiceOutput, getMimeTypeForFormat, + mimeTypeToFormat, ProxyService, } from '@geonetwork-ui/util/shared' import type { FeatureCollection } from 'geojson' @@ -148,6 +154,34 @@ export class DataService { ) } + async getDownloadLinksFromOgcApiFeatures( + ogcApiLink: DatasetServiceDistribution + ): Promise { + const apiUrl = + ogcApiLink.url.href.slice(-1) === '?' + ? ogcApiLink.url.href.slice(0, -1) + : ogcApiLink.url.href + + const collectionInfo = await this.getDownloadUrlsFromOgcApi(apiUrl) + + return Object.keys(collectionInfo.bulkDownloadLinks).map((downloadLink) => { + return { + ...ogcApiLink, + type: 'download', + url: new URL(collectionInfo.bulkDownloadLinks[downloadLink]), + mimeType: getMimeTypeForFormat( + getFileFormatFromServiceOutput(downloadLink) + ), + } + }) + } + + async getDownloadUrlsFromOgcApi(url: string): Promise { + const endpoint = new OgcApiEndpoint(url) + const collection = (await endpoint.featureCollections)[0] + return endpoint.getCollectionInfo(collection) + } + getDownloadLinksFromEsriRest( esriRestLink: DatasetServiceDistribution ): DatasetDistribution[] { @@ -205,6 +239,23 @@ export class DataService { 'geojson' ) return from(openDataset(url, 'geojson')).pipe() + } else if ( + link.type === 'service' && + link.accessServiceProtocol === 'ogcFeatures' + ) { + return from(this.getDownloadLinksFromOgcApiFeatures(link)).pipe( + switchMap((urls) => { + const geojsonUrl = urls.find( + (url) => mimeTypeToFormat(url['mimeType']) === 'geojson' + ) + return openDataset(geojsonUrl.url.toString(), 'geojson') + }), + tap((url) => { + if (url === null) { + throw new Error('wfs.geojsongml.notsupported') + } + }) + ) } return throwError(() => 'protocol not supported') } diff --git a/libs/util/shared/src/lib/links/link-classifier.service.ts b/libs/util/shared/src/lib/links/link-classifier.service.ts index a900e0400e..f34ec79ce2 100644 --- a/libs/util/shared/src/lib/links/link-classifier.service.ts +++ b/libs/util/shared/src/lib/links/link-classifier.service.ts @@ -26,7 +26,7 @@ export class LinkClassifierService { case 'wmts': return [LinkUsage.API, LinkUsage.MAP_API] case 'ogcFeatures': - return [LinkUsage.API] + return [LinkUsage.API, LinkUsage.DOWNLOAD, LinkUsage.GEODATA] default: return [LinkUsage.UNKNOWN] }