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

geosolutions-it / MapStore2 / 13125376331

04 Feb 2025 12:06AM UTC coverage: 76.858% (+0.008%) from 76.85%
13125376331

Pull #10798

github

web-flow
Merge edbbfc354 into 490d96d88
Pull Request #10798: #10737: Interactive legend for TOC layers [Vector Layer part]

31107 of 48619 branches covered (63.98%)

18 of 30 new or added lines in 4 files covered. (60.0%)

6 existing lines in 3 files now uncovered.

38654 of 50293 relevant lines covered (76.86%)

34.4 hits per line

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

66.67
/web/client/components/map/leaflet/plugins/VectorLayer.jsx
1
/**
2
 * Copyright 2015, 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 Layers from '../../../../utils/leaflet/Layers';
10
import { isEqual, isNil } from 'lodash';
11
import L from 'leaflet';
12
import {
13
    getStyle
14
} from '../../../../utils/VectorStyleUtils';
15
import { applyDefaultStyleToVectorLayer } from '../../../../utils/StyleUtils';
16
import { filterVectorLayerFeatures } from '../../../../utils/FilterUtils';
17

18
const setOpacity = (layer, opacity) => {
1✔
19
    if (layer.eachLayer) {
333✔
20
        layer.eachLayer(l => {
101✔
21
            if (l.setOpacity) {
302✔
22
                l.setOpacity(opacity);
164✔
23
            }
24
            setOpacity(l, opacity);
302✔
25
        });
26
    }
27
};
28

29
const createVectorLayer = function(options) {
1✔
30
    const { hideLoading } = options;
6✔
31
    const layer = L.geoJson([]/* options.features */, {
6✔
32
        pointToLayer: options.styleName !== "marker" ? function(feature, latlng) {
6✔
33
            return L.circleMarker(latlng, feature.style || options.style);
×
34
        } : null,
35
        hideLoading: hideLoading
36
    });
37
    layer.setOpacity = (opacity) => {
6✔
38
        setOpacity(layer, opacity);
31✔
39
    };
40
    layer.on('layeradd', ({layer: featureLayer}) => {
6✔
41
        layer.setOpacity(!isNil(layer.opacity) ? layer.opacity : options.opacity, featureLayer);
31!
42
    });
43
    return layer;
6✔
44
};
45

46
const isNewStyle = (options) => (options?.style?.body && options?.style?.format);
7✔
47

48
const createLayerLegacy = (options) => {
1✔
49
    const layer = createVectorLayer(options);
6✔
50
    // layer.opacity will store the opacity value
51
    layer.opacity = !isNil(options.opacity) ? options.opacity : 1.0;
6✔
52
    layer._msLegacyGeoJSON = true;
6✔
53
    return layer;
6✔
54
};
55

56
const createLayer = (options) => {
1✔
57
    const { hideLoading } = options;
1✔
58
    const featuresToRender = options.features.filter(filterVectorLayerFeatures(options));        // make filter for features if filter is existing
1✔
59

60
    const layer = L.geoJson(featuresToRender, {
1✔
61
        hideLoading: hideLoading
62
    });
63

64
    getStyle(applyDefaultStyleToVectorLayer(options), 'leaflet')
1✔
65
        .then((styleUtils) => {
66
            styleUtils({ opacity: options.opacity, layer, features: featuresToRender })
1✔
67
                .then(({
×
68
                    style: styleFunc,
69
                    pointToLayer = () => null,
×
70
                    filter: filterFunc = () => true
×
71
                } = {}) => {
72
                    layer.clearLayers();
1✔
73
                    layer.options.pointToLayer = pointToLayer;
1✔
74
                    layer.options.filter = filterFunc;
1✔
75
                    layer.addData(featuresToRender);
1✔
76
                    layer.setStyle(styleFunc);
1✔
77
                });
78
        });
79
    return layer;
1✔
80
};
81

82
const updateLayerLegacy = (layer, newOptions, oldOptions) => {
1✔
83
    if (newOptions.opacity !== oldOptions.opacity) {
1!
84
        layer.opacity = newOptions.opacity;
×
85
    }
86
    if (!isEqual(newOptions.style, oldOptions.style)) {
1!
87
        return isNewStyle(newOptions)
×
88
            ? createLayer(newOptions)
89
            : createLayerLegacy(newOptions);
90
    }
91
    return null;
1✔
92
};
93

94
const updateLayer = (layer, newOptions, oldOptions) => {
1✔
NEW
95
    if (!isEqual(oldOptions.layerFilter, newOptions.layerFilter)) {
×
NEW
96
        layer.remove();
×
NEW
97
        return createLayer(newOptions);
×
98
    }
UNCOV
99
    if (!isEqual(oldOptions.style, newOptions.style)
×
100
    || newOptions.opacity !== oldOptions.opacity) {
101
        getStyle(applyDefaultStyleToVectorLayer(newOptions), 'leaflet')
×
102
            .then((styleUtils) => {
103
                styleUtils({ opacity: newOptions.opacity, layer, features: newOptions.features })
×
104
                    .then(({
×
105
                        style: styleFunc,
106
                        pointToLayer = () => null,
×
107
                        filter: filterFunc = () => true
×
108
                    } = {}) => {
109
                        layer.clearLayers();
×
110
                        layer.options.pointToLayer = pointToLayer;
×
111
                        layer.options.filter = filterFunc;
×
112
                        layer.addData(newOptions.features);
×
113
                        layer.setStyle(styleFunc);
×
114
                    });
115
            });
116
    }
117
    return null;
×
118
};
119

120
Layers.registerType('vector', {
1✔
121
    create: (options) => {
122
        return !isNewStyle(options)
7✔
123
            ? createLayerLegacy(options)
124
            : createLayer(options);
125
    },
126
    update: (layer, newOptions, oldOptions) => layer._msLegacyGeoJSON
1!
127
        ? updateLayerLegacy(layer, newOptions, oldOptions)
128
        : updateLayer(layer, newOptions, oldOptions),
129
    render: () => {
130
        return null;
×
131
    }
132
});
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