qgis / qwc2-demo-app

QWC2 demo application
Other
243 stars 155 forks source link

blank map window after login/logout #519

Closed rsrg-zwiama closed 10 months ago

rsrg-zwiama commented 10 months ago

With the latest version of qwc2, the map window shows blank page after login and log out and the background switcher button disappears. I can reproduce this with the qwc demo app (docker) and the latest image for the demo app. With login and logout the theme parameter disappears from the url. login call: http://127.0.0.1:8088/auth/login?url=http%3A%2F%2F127.0.0.1%3A8088%2F%3Ft%3Dqwc_demo%26l%3Dedit_points%252Cedit_lines%252Cedit_polygons%252Cgeographic_lines%252Ccountry_names%252Cstates_provinces%252Ccountries%26bl%3Dmapnik%26c%3D1000000%252C6000000%26s%3D25000000 url after login: http://127.0.0.1:8088/?c=1000000%2C6000000&s=25000000 I get following error in the browser:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at l (LayerUtils.js:64:31)
    at Object.restoreOrderedLayerParams (LayerUtils.js:55:9)
    at To (ServiceLayerUtils.js:328:97)
    at ThemeUtils.js:39:36
    at redux-thunk.mjs:3:25
    at n.<computed> [as setCurrentTheme] (XMLText.js:61:51)
    at ThemeUtils.js:225:1
    at b (PermaLinkUtils.js:106:10)
    at ThemeUtils.js:200:46

I have tracked the problem to this commit: https://github.com/qgis/qwc2/commit/9faa1bf451e9140b574349ba85c9bd1e3c8ec16e

The map loads as expected, when I disable the if statement:

                    if (!entry.sublayer.style) {
                        entry.sublayer.style = Object.keys(entry.sublayer.styles)[0];
                    }

In restoreOrderedLayerParams https://github.com/qgis/qwc2/blob/3244e1ae20500517d98f9310830fabea2028f393/utils/LayerUtils.js#L51

    restoreOrderedLayerParams(themeLayer, layerConfigs, permalinkLayers, externalLayers) {
        const exploded = LayerUtils.explodeLayers([themeLayer]);
        let reordered = [];
        // Iterate over layer configs and reorder items accordingly, create external layer placeholders as neccessary
        for (const layerConfig of layerConfigs) {
            if (layerConfig.type === 'theme') {
                const entry = exploded.find(e => e.sublayer.name === layerConfig.name);
                if (entry) {
                    entry.sublayer.opacity = layerConfig.opacity;
                    entry.sublayer.visibility = layerConfig.visibility || layerConfig.tristate;
                    entry.sublayer.tristate = layerConfig.tristate;
                    entry.sublayer.style = layerConfig.style;
                    if (!entry.sublayer.style) {
                        entry.sublayer.style = Object.keys(entry.sublayer.styles)[0];
                    }
                    reordered.push(entry);
                }
            } else if (layerConfig.type === 'separator') {
                reordered = reordered.concat(LayerUtils.createSeparatorLayer(layerConfig.name));
            } else {
                reordered = reordered.concat(LayerUtils.createExternalLayerPlaceholder(layerConfig, externalLayers, layerConfig.id));
            }

Same code is also used in restoreLayerParams https://github.com/qgis/qwc2/blob/3244e1ae20500517d98f9310830fabea2028f393/utils/LayerUtils.js#L29

manisandro commented 10 months ago

Thanks, fixed in [1]

[1] https://github.com/qgis/qwc2/commit/d01f505dbf90a325270ceacbbe88612a0902821f

rsrg-zwiama commented 10 months ago

Thanks @manisandro But I think my problem is in restoreOrderedLayerParams Line 64 https://github.com/qgis/qwc2/blob/3244e1ae20500517d98f9310830fabea2028f393/utils/LayerUtils.js#L64 where the same code is used

manisandro commented 10 months ago

Right, fixed as well. Thanks

rsrg-zwiama commented 10 months ago

Great thank you!