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

geosolutions-it / MapStore2 / 14534587011

18 Apr 2025 11:41AM UTC coverage: 76.977% (-0.02%) from 76.993%
14534587011

Pull #11037

github

web-flow
Merge f22d700f6 into 48d6a1a15
Pull Request #11037: Remove object assign pollyfills

30792 of 47937 branches covered (64.23%)

446 of 556 new or added lines in 94 files covered. (80.22%)

8 existing lines in 4 files now uncovered.

38277 of 49725 relevant lines covered (76.98%)

36.07 hits per line

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

78.64
/web/client/utils/leaflet/Vector.js
1
/*
2
 * Copyright 2017, 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
const L = require('leaflet');
1✔
10
const Icons = require('./Icons');
1✔
11
const {isMarkerStyle, isSymbolStyle} = require('../VectorStyleUtils');
1✔
12

13
const getIcon = (style, geojson) => {
1✔
14
    if (style && style.iconGlyph) {
×
15
        const iconLibrary = style.iconLibrary || 'extra';
×
16
        if (Icons[iconLibrary]) {
×
17
            return Icons[iconLibrary].getIcon(style);
×
18
        }
19
    }
20
    if (style && style.html && geojson) {
×
21
        return Icons.html.getIcon(style, geojson);
×
22
    }
23
    if (style && style.iconUrl || style.symbolUrlCustomized || style.symbolUrl) {
×
24
        return Icons.standard.getIcon(style);
×
25
    }
26
    return null;
×
27
};
28

29
const coordsToLatLngF = function(coords) {
1✔
30
    return new L.LatLng(coords[1], coords[0], coords[2]);
207✔
31
};
32

33
const coordsToLatLngs = function(coords, levelsDeep, coordsToLatLng) {
1✔
34
    var latlngs = [];
86✔
35
    var len = coords.length;
86✔
36
    for (let i = 0, latlng; i < len; i++) {
86✔
37
        latlng = levelsDeep ?
240✔
38
            coordsToLatLngs(coords[i], levelsDeep - 1, coordsToLatLng) :
39
            (coordsToLatLng || this.coordsToLatLng)(coords[i]);
188!
40

41
        latlngs.push(latlng);
240✔
42
    }
43

44
    return latlngs;
86✔
45
};
46

47
const isMarker = (props) => {
1✔
48
    // TODO FIX THIS, for geom coll that contains marker or normal points
49
    if (props.geometry.type === "GeometryCollection") {
53✔
50
        return false;
4✔
51
    }
52
    const newStructuredStyle = props.style;
49✔
53
    return newStructuredStyle && (isMarkerStyle(newStructuredStyle) || isSymbolStyle(newStructuredStyle) || (newStructuredStyle.iconUrl || newStructuredStyle.iconGlyph));
49✔
54
};
55
// Create a new Leaflet layer with custom icon marker or circleMarker
56

57
const VectorUtils = {
1✔
58
    coordsToLatLngF,
59
    coordsToLatLngs,
60
    isMarker,
61
    getPointLayer: function(pointToLayer, geojson, latlng, options) {
62
        if (pointToLayer) {
19!
63
            return pointToLayer(geojson, latlng);
19✔
64
        }
65
        return VectorUtils.pointToLayer(latlng, geojson, {...options.style, styleName: options.styleName, highlight: options.highlight});
×
66
    },
67
    pointToLayer: (latlng, geojson, style) => {
68
        const newStyle = style.Point || style.MultiPoint || style;
×
69
        const icon = getIcon(newStyle, geojson);
×
70
        if (icon) {
×
71
            return L.marker(
×
72
                latlng,
73
                {
74
                    icon,
75
                    opacity: newStyle && newStyle.opacity || 1
×
76
                });
77
        }
78
        return L.marker(latlng, {
×
79
            opacity: newStyle && newStyle.opacity || 1
×
80
        });
81
    },
82
    /**
83
    * This method creates a valid geoJSON for layer created from GeometryCollection
84
    * The leaflet toGeoJSON transforms the layer created by VectorUtils.geometryToLayer in a
85
    * featureCollection of FeatureCollections in that case because for each L.FeatureGroup it creates a FeatureCollection.
86
    * Thus we need to recreate a GeometryCollection and also multi-geometry instead of FeatureCollections
87
    * @return {object} a valid geoJSON
88
    */
89
    toValidGeoJSON: () => {
90
        // TODO
91
    },
92
    /**
93
     * create point or text layer
94
     */
95
    createTextPointMarkerLayer: ({pointToLayer, geojson, latlng, options, style = {}, highlight = false} = {}) => {
3!
96
        if (geojson.properties && geojson.properties.isText) {
19!
97
            // this is a Text Feature
98
            // TODO: improve management for stroke-width because 5px it was not the same as in ol width:5 for ol.style.Stroke
99
            let myIcon = L.divIcon({html: `<span style="
×
100
                font:${style.font};
101
                color:${style.fillColor};
102
                -webkit-text-stroke-width:${1}px;
103
                -webkit-text-stroke-color:${style.color};">${geojson.properties.valueText}</span>`, className: ''});
104
            return new L.Marker(latlng, {icon: myIcon});
×
105
        }
106
        return VectorUtils.getPointLayer(pointToLayer, geojson, latlng, {...options, style, highlight});
19✔
107
    },
108
    /**
109
    * create Circle or polygon layer
110
    */
111
    createPolygonCircleLayer: ({geojson, style = {}, latlngs = [], coordsToLatLng = () => {}} = {}) => {
×
112
        if (geojson.properties && geojson.properties.isCircle) {
20!
113
            let latlng = coordsToLatLng(geojson.properties.center);
×
114
            return L.circle(latlng, { ...style, radius: geojson.properties.radius});
×
115
        }
116
        return new L.Polygon(latlngs, style);
20✔
117
    },
118
    geometryToLayer: function(geojson, options) {
119
        const geometry = geojson.type === 'Feature' ? geojson.geometry : geojson;
53!
120
        const coords = geometry ? geometry.coordinates : null;
53!
121
        const layers = [];
53✔
122
        const props = {styleName: options.styleName, style: options.style && options.style[0] || options.style, ...geojson};
53✔
123
        const pointToLayer = options && !isMarker(props) ? function(feature, latlng) {
53!
124
            if (props.styleName === "marker") {
19✔
125
                return L.marker(latlng, props.style);
16✔
126
            }
127
            return L.circleMarker(latlng, props.style && props.style[0] || props.style );
3!
128
        } : null;
129

130
        let coordsToLatLng = options && options.coordsToLatLng || VectorUtils.coordsToLatLngF;
53✔
131

132
        if (!coords && !geometry) {
53!
133
            return null;
×
134
        }
135
        let layer;
136
        let style = props.style || Object.assign({}, options.style && options.style[geometry.type] || options.style, {highlight: options.style && options.style.highlight});
53!
137

138
        let latlng;
139
        let latlngs;
140
        let i;
141
        let len;
142
        switch (geometry.type) {
53!
143
        case 'Point':
144
            latlng = coordsToLatLng(coords);
11✔
145
            layer = VectorUtils.createTextPointMarkerLayer({pointToLayer, geojson, latlng, options, style, highlight: style && style.highlight});
11✔
146
            return layer;
11✔
147
        case 'MultiPoint':
148
            for (i = 0, len = coords.length; i < len; i++) {
4✔
149
                latlng = coordsToLatLng(coords[i]);
8✔
150
                layer = VectorUtils.createTextPointMarkerLayer({pointToLayer, geojson, latlng, options, style, highlight: style && style.highlight});
8✔
151
                layer.msId = geojson.id;
8✔
152
                layers.push(layer);
8✔
153
            }
154
            return new L.FeatureGroup(layers);
4✔
155

156
        case 'LineString':
157
            style = VectorUtils.updateHighlightStyle(style);
14✔
158
            latlngs = coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, coordsToLatLng);
14!
159
            layer = new L.Polyline(latlngs, style);
14✔
160
            layer.msId = geojson.id;
14✔
161
            return layer;
14✔
162
        case 'MultiLineString':
163
            style = VectorUtils.updateHighlightStyle(style);
6✔
164
            latlngs = coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, coordsToLatLng);
6!
165
            for (i = 0, len = latlngs.length; i < len; i++) {
6✔
166
                layer = new L.Polyline(latlngs[i], style);
12✔
167
                layer.msId = geojson.id;
12✔
168
                if (layer) {
12!
169
                    layers.push(layer);
12✔
170
                }
171
            }
172
            return new L.FeatureGroup(layers);
6✔
173
        case 'Polygon':
174
            style = VectorUtils.updateHighlightStyle(style);
6✔
175
            latlngs = coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, coordsToLatLng);
6!
176
            layer = VectorUtils.createPolygonCircleLayer({geojson, style, latlngs, coordsToLatLng});
6✔
177
            layer.msId = geojson.id;
6✔
178
            return layer;
6✔
179
        case 'MultiPolygon':
180
            style = VectorUtils.updateHighlightStyle(style);
8✔
181
            latlngs = coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, coordsToLatLng);
8!
182
            for (i = 0, len = latlngs.length; i < len; i++) {
8✔
183
                layer = VectorUtils.createPolygonCircleLayer({geojson, style, latlngs, coordsToLatLng});
14✔
184
                layer.msId = geojson.id;
14✔
185
                if (layer) {
14!
186
                    layers.push(layer);
14✔
187
                }
188
            }
189
            return new L.FeatureGroup(layers);
8✔
190
        case 'GeometryCollection':
191
            for (i = 0, len = geometry.geometries.length; i < len; i++) {
4✔
192
                layer = VectorUtils.geometryToLayer({
8✔
193
                    geometry: geometry.geometries[i],
194
                    type: 'Feature',
195
                    properties: geojson.properties
196
                }, options);
197

198
                if (layer) {
8!
199
                    layers.push(layer);
8✔
200
                }
201
            }
202
            return new L.FeatureGroup(layers);
4✔
203

204
        default:
205
            throw new Error('Invalid GeoJSON object.');
×
206
        }
207
    },
208
    updateHighlightStyle: (style) => {
209
        let {highlight} = style;
34✔
210
        if (highlight) {
34!
NEW
211
            return Object.assign({}, style, {
×
212
                dashArray: highlight ? "10" : null
×
213
            });
214
        }
215
        return style;
34✔
216
    }
217
};
218

219
module.exports = VectorUtils;
1✔
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