Changing map viewer map configuration results in empty layer list

I am trying to change the default background maps in the map viewer of GeoNetwork.

What I tried:

  • in GeoNetwork web UI, login as admin, go to Settings / User Interface
  • select ‘Create a default UI configuration’
  • below ‘Choose an option to customize’ select ‘Map application / Viewer Map Configuration’
  • as ‘Path to the context file (XML)’ enter ‘…/…/map/config-viewer-new.xml’
  • Save settings
  • switch to Map tab in GeoNetwork web UI

Expected results:

  • below ‘Manage layers’, the new default background maps should be listed

Actual results:

  • the list of background maps is empty, and no background layer is displayed on the map
  • however, when pressing ‘Default map’, the new viewer config is loaded and background layers are working properly
  • switching to e.g. the search tab and back, the list is empty again

Is there something I am missing here, or is it a bug in GeoNetwork? Has someone else successfully changed the default maps in map viewer?

Tested with GeoNetwork 4.2.8 docker image. The minimal docker compose config to reproduce the issue is:

networks:
  gn-network:
    driver: bridge

volumes:
  geonetwork-catalogue-data:

services:

  my-es-host:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.15
    healthcheck:
      test: ["CMD-SHELL", "curl -s -f http://localhost:9200/_cat/health >/dev/null || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 10
    environment:
      discovery.type: single-node
      ingest.geoip.downloader.enabled: false
    networks:
      gn-network:     

  geonetwork-host:
      image: geonetwork:4.2.8
      ports:
        - 8080:8080
      depends_on:
        my-es-host:
          condition: service_healthy
      volumes:
        - ./config-viewer.xml:/var/lib/jetty/webapps/geonetwork/WEB-INF/data/data/resources/map/config-viewer-new.xml
        - geonetwork-catalogue-data:/catalogue-data
      environment:
        ES_HOST: my-es-host
        ES_PROTOCOL: http
        ES_PORT: 9200 
      networks:
        gn-network:

The content of the ./config-viewer.xml file is:

<ows-context:OWSContext xmlns:ows-context="http://www.opengis.net/ows-context"
      xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ows="http://www.opengis.net/ows"
      version="0.3.1" id="ows-context-ex-1-v3">
      <ows-context:General>
            <ows:BoundingBox crs="EPSG:3857">
                  <ows:LowerCorner>-10961266.408549732 -368509.62979839183</ows:LowerCorner>
                  <ows:UpperCorner>11305393.132677661 8768675.691270513</ows:UpperCorner>
            </ows:BoundingBox>
      </ows-context:General>
      <ows-context:ResourceList>
            <ows-context:Layer name="{type=osm}" group="Background layers" hidden="false"
                  opacity="1">
                  <ows:Title>OpenStreetMap
                  </ows:Title>
            </ows-context:Layer>
            <ows-context:Layer name="{type=tms,name=gm}" group="Background layers" hidden="false"
                  opacity="1">
                  <ows:Title xmlns:ows="http://www.opengis.net/ows">Google Maps
                  </ows:Title>
                  <ows-context:Server service="urn:ogc:serviceType:WMTS">
                        <ows-context:OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink"
                              xlink:href="http://mt2.google.com/vt/lyrs=s@0&amp;hl=en&amp;x={x}&amp;y={y}&amp;z={z}" />
                  </ows-context:Server>
            </ows-context:Layer>
      </ows-context:ResourceList>
</ows-context:OWSContext>

Note that in this setup, the config-viewer.xml is mounted to /var/lib/jetty/webapps/geonetwork/WEB-INF/data/data/resources/map/config-viewer-new.xml in the docker container and gets copied to /catalogue-data/resources/map/config-viewer-new.xml by the GeoNetwork docker image on first startup (i.e. when the geonetwork-catalogue-data volume is empty). GeoNetwork is then configured to read the file from /catalogue-data/resources/map/config-viewer-new.xml as described above.

Following an update to GeoNetwork 4.4.9, this seems to work now.

For 4.4.9, the map viewer default config is copied to /opt/geonetwork/WEB-INF/data/data/resources/map/config-viewer.xml in my custom GeoNetwork docker image, and from there to the $DATA_DIR on first startup (/catalogue-data by default). If $DATA_DIR is not empty, new files may not be copied.

The default owner of config files is jetty, installing files as root might cause issues.

You can check the $DATA_DIR and other paths of your installation in the admin console, e.g.:
http://<your_host>/geonetwork/srv/eng/admin.console#/dashboard/information

There is also some caching of OWS Context in the web browser going on. You might need to view and clear your web browser session storage if changes are not applied immediately (e.g. using Developer Tools / Web Storage tab in Firefox).

The relevant code for resetting the viewer to the default map appears to be in core-geonetwork repo file web-ui/src/main/resources/catalog/components/viewer/baselayerswitcher/BaseLayerSwitcherDirective.js around line 100.

The code appears to load a default context if one exists (presumably from ../../map/config-viewer.xml or whichever file is configured in your settings).
If there is no default context, it tries to load some default layers instead (which according to a code comment might not work?).
If that fails too, it loads the default context from a hard-coded location (../../map/config-viewer.xml).

Default layers here could refer to the layer objects configurable in the Settings / User Interface / Viewer Map Configuration. I did not investigate further so might be wrong. In any case, I could not get the layer objects to have any visible effect on the viewer map.