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

geosolutions-it / MapStore2 / 19060241474

04 Nov 2025 06:46AM UTC coverage: 76.943% (+0.02%) from 76.92%
19060241474

Pull #11648

github

web-flow
Merge 763e0cf1e into 19e678788
Pull Request #11648: #11644: Implement dynamic request configurations

32057 of 49801 branches covered (64.37%)

201 of 222 new or added lines in 39 files covered. (90.54%)

4 existing lines in 3 files now uncovered.

39801 of 51728 relevant lines covered (76.94%)

39.94 hits per line

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

67.21
/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 { createVectorFeatureFilter } 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 vectorFeatureFilter = createVectorFeatureFilter(options);
1✔
59
    const featuresToRender = options.features.filter(vectorFeatureFilter);        // make filter for features if filter is existing
1✔
60

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

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

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

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

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

© 2025 Coveralls, Inc