• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geosolutions-it / MapStore2 / 20129435362

10 Dec 2025 05:00PM UTC coverage: 76.664% (-0.07%) from 76.732%
20129435362

Pull #11796

github

web-flow
Fix #11792 Search plugin show null or undefined in displayName (#11791)
Pull Request #11796: [github-action] 2025.02.xx - Dependencies versions update

32325 of 50296 branches covered (64.27%)

40222 of 52465 relevant lines covered (76.66%)

37.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.5
/web/client/components/widgets/widget/MapWidget.jsx
1
/*
2
 * Copyright 2018, GeoSolutions Sas.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under the BSD-style license found in the
6
 * LICENSE file in the root directory of this source tree.
7
 */
8

9
import { omit, isEqual } from 'lodash';
10
import React from 'react';
11
import { compose, withHandlers, withProps } from 'recompose';
12

13
import BorderLayout from '../../layout/BorderLayout';
14
import LoadingSpinner from '../../misc/LoadingSpinner';
15
import MapViewComp from './MapView';
16
import WidgetContainer from './WidgetContainer';
17
import MapSwitcher from "../builder/wizard/map/MapSwitcher";
18
import BackgroundSelector from '../../background/BackgroundSelector';
19
import LegendViewComponent from './LegendView';
20
import { getDerivedLayersVisibility } from "../../../utils/LayersUtils";
21

22
const MapView = withHandlers({
1✔
23
    onMapViewChanges: ({ onUpdateMapProperty = () => { }}) => ({layers, ...map}) => onUpdateMapProperty(map)
13!
24
})(MapViewComp);
25

26
const LegendView = withHandlers({
1✔
27
    updateProperty: ({ onUpdateMapProperty = () => { }, map }) => (_, value) => {
×
28
        const newLayers = map.layers?.map(layer => {
×
29
            const updateLayer = value?.layers.find(l => l.id === layer.id);
×
30
            if (updateLayer) {
×
31
                return {
×
32
                    ...layer,
33
                    visibility: updateLayer.visibility,
34
                    opacity: updateLayer.opacity,
35
                    expanded: updateLayer.expanded,
36
                    layerFilter: updateLayer.layerFilter
37
                };
38
            }
39
            return layer;
×
40
        });
41
        const groups = map.groups?.map(group => {
×
42
            const updateGroup = value?.groups.find(g => g.id === group.id);
×
43
            if (updateGroup) {
×
44
                return {
×
45
                    ...group,
46
                    visibility: updateGroup.visibility,
47
                    expanded: updateGroup.expanded
48
                };
49
            }
50
            return group;
×
51
        });
52
        if (!isEqual(map.layers, newLayers) || !isEqual(map.groups, groups)) {
×
53
            onUpdateMapProperty({ ...map, layers: newLayers, groups });
×
54
        }
55
    }
56
})(LegendViewComponent);
57

58
const BackgroundSelectorWithHandlers = withHandlers({
1✔
59
    onPropertiesChange: ({ onUpdateMapProperty, map }) => (layerId, properties) => {
1✔
60
        if (!layerId) {
1!
61
            return;
1✔
62
        }
63
        const newLayers = map.layers?.map(layer => {
×
64
            if (layer.group === 'background') {
×
65
                const updatedLayer = { ...layer, visibility: false };
×
66
                // set the selected background layer to visible
67
                if (layer.id === layerId) {
×
68
                    return { ...updatedLayer, visibility: true, ...properties };
×
69
                }
70
                return updatedLayer;
×
71
            }
72
            return layer;
×
73
        });
74
        if (!isEqual(map.layers, newLayers)) {
×
75
            onUpdateMapProperty({ ...map, layers: newLayers });
×
76
        }
77
    }
78
})(BackgroundSelector);
79

80
const MapWidgetComponent = ({
1✔
81
    updateProperty = () => { },
13✔
82
    onUpdateMapProperty = () => { },
×
83
    toggleDeleteConfirm = () => { },
×
84
    id, title,
85
    map = {},
×
86
    maps = [],
11✔
87
    selectedMapId,
88
    icons,
89
    hookRegister,
90
    mapStateSource,
91
    topRightItems = [],
×
92
    options = {},
13✔
93
    confirmDelete = false,
×
94
    loading = false,
11✔
95
    dataGrid = {},
13✔
96
    onDelete = () => {},
13✔
97
    headerStyle,
98
    env,
99
    selectionActive,
100
    currentZoomLvl,
101
    scales,
102
    language,
103
    currentLocale
104
}) => {
105
    const { size: {height: mapHeight, width: mapWidth} = {}, mapInfoControl } = map;
13!
106
    const backgroundLayers = (map.layers || []).filter(layer => layer.group === 'background');
13!
107
    const enableViewerTools = mapHeight > 400 && mapWidth > 400 && mapInfoControl;
13✔
108

109
    return (<WidgetContainer className={"map-widget-view"} id={`widget-text-${id}`} title={title} confirmDelete={confirmDelete} onDelete={onDelete} toggleDeleteConfirm={toggleDeleteConfirm} headerStyle={headerStyle}
13✔
110
        icons={icons}
111
        topRightItems={[
112
            <MapSwitcher
113
                key="map-switcher"
114
                className={'map-switcher'}
115
                maps={maps}
116
                onChange={(...args) => updateProperty(id, ...args)}
×
117
                value={selectedMapId}
118
                disabled={selectionActive}
119
            />,
120
            ...topRightItems]
121
        }
122
        isDraggable={dataGrid.isDraggable}
123
        options={options}
124
    >
125
        <BorderLayout
126
            footer={loading
13✔
127
                ? <div className={"widget-footer"}>
128
                    <span style={{ "float": "right"}}><LoadingSpinner /></span>
129
                </div>
130
                : null
131
            }>
132
            <div className="map-widget-view-content">
133
                <MapView
134
                    tools={enableViewerTools ? ['popup'] : []}
13✔
135
                    onUpdateMapProperty={onUpdateMapProperty}
136
                    id={id}
137
                    map={{
138
                        ...omit(map, 'mapStateSource')
139
                    }}
140
                    mapStateSource={mapStateSource}
141
                    hookRegister={hookRegister}
142
                    layers={getDerivedLayersVisibility(map.layers, map.groups)}
143
                    options={{ style: { margin: '0 10px 10px 10px', height: 'calc(100% - 10px)' }}}
144
                    env={env}
145
                />
146
                {enableViewerTools && <>
18✔
147
                    {map.showBackgroundSelector && backgroundLayers?.length > 0 && (
7✔
148
                        <BackgroundSelectorWithHandlers
149
                            id={id}
150
                            map={map}
151
                            onUpdateMapProperty={onUpdateMapProperty}
152
                            backgrounds={backgroundLayers}
153
                            projection={map.projection}
154
                            style={{
155
                                position: 'absolute',
156
                                bottom: 8,
157
                                left: 8,
158
                                zIndex: 100,
159
                                marginBottom: 0
160
                            }}
161
                            alwaysVisible={false}
162
                            canEdit={false}
163
                            allowDeletion={false}
164
                            backgroundToolbarItems={[]}
165
                        />
166
                    )}
167
                    {map.showLegend && (
6✔
168
                        <div className="legend-in-mapview">
169
                            <LegendView
170
                                id={id}
171
                                map={map}
172
                                onUpdateMapProperty={onUpdateMapProperty}
173
                                currentZoomLvl={currentZoomLvl}
174
                                scales={scales}
175
                                language={language}
176
                                currentLocale={currentLocale}
177
                            />
178
                        </div>
179
                    )}
180
                </>}
181
            </div>
182
        </BorderLayout>
183
    </WidgetContainer>);
184
};
185

186
const MapWidget = compose(
1✔
187
    withProps(({ selectedMapId }) => ({ selectedMapId })),
13✔
188
    withHandlers({
189
        onUpdateMapProperty: ({updateProperty = () => {}, id, selectedMapId}) => (value) => {
13✔
190
            // Include mapId in the value so the reducer knows which map to update
191
            const valueWithMapId = selectedMapId ? { ...value, mapId: selectedMapId } : value;
13✔
192
            updateProperty(id, "maps", valueWithMapId, "merge");
13✔
193
        }
194
    })
195
)(MapWidgetComponent);
196

197
export default MapWidget;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc