From 6749a3402404e3acbea12e822f3a80a19a22db67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Prunayre?= Date: Tue, 13 Jun 2023 09:28:00 +0200 Subject: [PATCH] Map / Layer manager / Add support for multilingual layer title. (#7121) * Map / Layer manager / Add support for multilingual layer title. Metadata may be multilingual and provide multilingual layer name in the online source description field. GetCapabilities document do not provide multilingual support, so this adds the possibility to translate layer name in maps. A multilingual description in a link: ```xml https://data.apps.fao.org/map/gsrv/gsrv1/geonetwork/ows?SERVICE=WMS& OGC:WMS geonetwork:basins_296 geonetwork:basins_296 Hydrological basins in Africa Hydrological basins in Africa Bassins versants en Afrique ``` The description is retrieved from the metadata on load from the metadata UUID which is attached to the layer (and saved in the OWS context extension of the layer) using the service URL and the layer name. This also allows to override layer name when a group of layer (eg. `a,b,c`) is used in the online source name. * Map / When loading a map, switch to layer tool panel. * Map / Layer manager / Add support for multilingual layer title / Layer search. * Map / Layer manager / Add support for multilingual layer title / Layer filter. * Remove openTool after map load. Configuration done in https://github.com/geonetwork/core-geonetwork/pull/7126 --- .../components/common/map/mapService.js | 40 ++++++++++++++++++- .../index/IndexDataViewDirective.js | 2 +- .../partials/layermanageritem.html | 9 +++-- .../partials/searchlayerformap.html | 4 +- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/web-ui/src/main/resources/catalog/components/common/map/mapService.js b/web-ui/src/main/resources/catalog/components/common/map/mapService.js index 73fc377d8c9..31c8624e7cd 100644 --- a/web-ui/src/main/resources/catalog/components/common/map/mapService.js +++ b/web-ui/src/main/resources/catalog/components/common/map/mapService.js @@ -1538,6 +1538,32 @@ return layer; }, + /** + * @ngdoc method + * @methodOf gn_map.service:gnMap + * @name gnMap#getLinkDescription + * + * @description + * Retrieve description of the link from the metadata + * record using the URL and layer name. The description + * may override GetCapabilities layer name and can also + * be multilingual. + */ + getLinkDescription: function (md, url, name) { + if (md) { + var link = md.getLinksByFilter( + "protocol:OGC:WMS" + + " AND url:" + + url.replace("?", "\\?") + + " AND name:" + + name + ); + if (link.length === 1) { + return link[0].description !== "" ? link[0].description : undefined; + } + } + }, + /** * @ngdoc method * @methodOf gn_map.service:gnMap @@ -1615,6 +1641,12 @@ if (!createOnly) { map.addLayer(olL); } + + olL.set( + "layerTitleFromMetadata", + $this.getLinkDescription(olL.get("md"), url, name) + ); + gnWmsQueue.removeFromQueue( url, name, @@ -1910,6 +1942,12 @@ if (!createOnly) { map.addLayer(olL); } + + olL.set( + "layerTitleFromMetadata", + $this.getLinkDescription(olL.get("md"), url, name) + ); + gnWmsQueue.removeFromQueue(url, name, map); defer.resolve(olL); }; @@ -2393,7 +2431,7 @@ feedLayerWithRelated: function (layer, linkGroup) { var md = layer.get("md"); - if (!linkGroup) { + if (!Number.isInteger(linkGroup)) { console.warn( "The layer has not been found in any group: " + layer.getSource().getParams().LAYERS diff --git a/web-ui/src/main/resources/catalog/components/index/IndexDataViewDirective.js b/web-ui/src/main/resources/catalog/components/index/IndexDataViewDirective.js index 11645a56898..78219cc94bf 100644 --- a/web-ui/src/main/resources/catalog/components/index/IndexDataViewDirective.js +++ b/web-ui/src/main/resources/catalog/components/index/IndexDataViewDirective.js @@ -42,7 +42,7 @@ scope.currentLayer = l; }; scope.getLabel = function (layer) { - return layer.get("label"); + return layer.get("layerTitleFromMetadata") || layer.get("label"); }; scope.set = function () { if (scope.layer) { diff --git a/web-ui/src/main/resources/catalog/components/viewer/layermanager/partials/layermanageritem.html b/web-ui/src/main/resources/catalog/components/viewer/layermanager/partials/layermanageritem.html index 433faab519c..aef31046b32 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/layermanager/partials/layermanageritem.html +++ b/web-ui/src/main/resources/catalog/components/viewer/layermanager/partials/layermanageritem.html @@ -66,15 +66,18 @@ for="layer-{{$index}}" data-ng-class="{'gn-map-layer-selected': layer.showInfo}" > - - {{layer.get('label')}} + + {{layer.get('layerTitleFromMetadata') || layer.get('label')}} {{layer.get('currentStyle') ? '(' + (layer.get('currentStyle').Title || layer.get('currentStyle').Name) + ')' : ''}} - + diff --git a/web-ui/src/main/resources/catalog/components/viewer/searchlayerformap/partials/searchlayerformap.html b/web-ui/src/main/resources/catalog/components/viewer/searchlayerformap/partials/searchlayerformap.html index 8c6041795f4..07a34d98642 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/searchlayerformap/partials/searchlayerformap.html +++ b/web-ui/src/main/resources/catalog/components/viewer/searchlayerformap/partials/searchlayerformap.html @@ -66,11 +66,11 @@

- {{link.desc || link.name}}  + {{link.description || link.name}}