Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchBackground function button #476

Closed
shapley opened this issue Aug 30, 2023 · 5 comments
Closed

SwitchBackground function button #476

shapley opened this issue Aug 30, 2023 · 5 comments

Comments

@shapley
Copy link

shapley commented Aug 30, 2023

Hi,

Trying to set up the background layers to appear alongside the missing 'SwitchBackground' button in the 'qwc2-demo-app' static website version but cannot see what is wrong. Below is the 'backgroundLayers' part of 'themesConfig.json. Perhaps this is only functional in 'qwc-services'? What other json files require amending/checking if any.

            "backgroundLayers":[
                  {
                      "name":"layer1",
                      "title":"O'S Road Map",
                      "resource": "wmts:https://layer1serviceurl#layername",
                      "thumbnail":"img/mapthumbs/default.jpg",
                      "overview":false
                  },
                  {
                      "name":"layer2",
                      "title":"O'S Leisure Map",
                      "resource": "wmts:https://layer2serviceurl#layername2",
                      "thumbnail":"img/mapthumbs/default.jpg",
                      "overview":true
                  },
                  {
                      "name":"layer3",
                      "title":"APGB 25cm Aerial",
                      "resource": "wms:wmts:https://layer3serviceurl#layername3",
                      "thumbnail":"img/mapthumbs/default.jpg",
                      "overview":false
                  }

],

backgroundswitcherbutton

@manisandro
Copy link
Member

manisandro commented Aug 30, 2023

You also need to assign the desired backgound layers to a theme, see https://qwc-services.github.io/configuration/ThemesConfiguration/

@shapley
Copy link
Author

shapley commented Aug 30, 2023

I took the code above from within a theme.. These layers are already set up in the QGIS project and configured in QGIS Server. I was hoping to use them in the background switcher too. Can you confirm whether this is possible before I close the call.

@manisandro
Copy link
Member

Background layers are configured purely client-side and will appear in the background switcher, separate from the layertree. Background layers are typically added to the QGIS project itself just for printing (see https://qwc-services.github.io/topics/Printing/)

@shapley
Copy link
Author

shapley commented Aug 30, 2023

Ahh...so i need to set up some background layers in the QGIS project which I haven't done then mark them as 'printLayers' under 'backgroundLayers'. Think I've got it.

@shapley shapley closed this as completed Aug 30, 2023
@danceb
Copy link

danceb commented Aug 31, 2023

Let me add a hint:
You don't have to add your background layers to your QGIS projects to use them as print layers!
This could be a mess, if you have a lot of background layers and many themes and changes with the background layers has to be done in each QGIS project.

Just set the parameter printExternalLayers within the print-config in your config.json to true:

      {
        "name": "Print",
        "cfg": {
          "printExternalLayers": true,
          [...]
        },
        "mapClickAction": "identify"
      },

See: https://qwc-services.github.io/references/qwc2_plugins/#print

And respective for including them in the raster export:

      {
        "name": "RasterExport",
        "cfg": {
          "exportExternalLayers": true,
          [...]
        }
      },

See: https://qwc-services.github.io/references/qwc2_plugins/#rasterexport

Then configure the background layer sources within the backgroundLayers block in your themesConfig.json/tenantConfig.json:

      "backgroundLayers": [
        {
          "name": "background_layer_1",
          "title": "Background Layer 1",
          "group": "Group 1",
          "type": "wms",
          "url": "/your/url",
          "srs": "EPSG:25832",
          "tiled": false,
          "params": {
            "LAYERS": "WMS Layer 1",
            "STYLES": "default"
          },
          "thumbnail": "thumbnail_1.jpg",
          [...]
        },
        [...]

And specify them for each theme:

        {
          "url": "your/url",
          "title": "Title",
          "backgroundLayers": [
            {
              "name": "background_layer_1",
              "visibility": true
            },
            {
              "name": "background_layer_2"
            },
           [...]
          ],
          [...]
        }

Reading the documentation at https://qwc-services.github.io/configuration/ThemesConfiguration/#manual-theme-configuration, it should by possible to specify them within the defaultBackgroundLayers block instead of configure them for each theme itself, but I didn't get this to work in my case. But you could have a try.

With this configuration you don't have to add the background layers to each QGIS project to get them printed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants