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

geosolutions-it / MapStore2 / 19710972030

26 Nov 2025 03:38PM UTC coverage: 76.665% (-0.3%) from 76.929%
19710972030

Pull #11119

github

web-flow
Fix maven publish (#11739)
Pull Request #11119: Layer Selection Plugin on ArcGIS, WFS & WMS layers

32272 of 50209 branches covered (64.28%)

3 of 3 new or added lines in 2 files covered. (100.0%)

3018 existing lines in 249 files now uncovered.

40157 of 52380 relevant lines covered (76.66%)

37.9 hits per line

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

78.95
/web/client/utils/openlayers/WMSUtils.js
1
/*
2
 * Copyright 2023, 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
import { get } from 'ol/proj';
9
import TileGrid from 'ol/tilegrid/TileGrid';
10

11
import CoordinatesUtils from '../CoordinatesUtils';
12
import { getProjection } from '../ProjectionUtils';
13
import {needProxy, getProxyUrl} from '../ProxyUtils';
14
import {optionsToVendorParams} from '../VendorParamsUtils';
15
import { addAuthenticationToSLD } from '../SecurityUtils';
16
import { creditsToAttribution, getWMSVendorParams } from '../LayersUtils';
17
import { getResolutionsForProjection } from '../MapUtils';
18
import { generateEnvString } from '../LayerLocalizationUtils';
19
import { getTileGridFromLayerOptions } from '../WMSUtils';
20

21

22
function hasHttpProtocol(givenUrl = '') {
×
23
    if (window?.location?.protocol === 'https:') {
59!
UNCOV
24
        if (givenUrl.indexOf('http') === 0) {
×
25
            const givenUrlObject = new URL(givenUrl);
×
26
            return givenUrlObject.protocol === 'http:';
×
27
        }
UNCOV
28
        if (givenUrl.indexOf('/') === 0) {
×
29
            return false;
×
30
        }
UNCOV
31
        return true;
×
32
    }
33
    return false;
59✔
34
}
35

36
/**
37
 * Check source and apply proxy
38
 * when `forceProxy` is set on layer options
39
 * @param {boolean} forceProxy
40
 * @param {string} src
41
 * @returns {string}
42
 */
43
export const proxySource = (forceProxy, src) => {
1✔
44
    const _forceProxy = forceProxy || hasHttpProtocol(src);
59✔
45
    let newSrc = src;
59✔
46
    if (_forceProxy && needProxy(src)) {
59!
UNCOV
47
        let proxyUrl = getProxyUrl();
×
48
        newSrc = proxyUrl + encodeURIComponent(src);
×
49
    }
50
    return newSrc;
59✔
51
};
52

53
export function getWMSURLs( urls ) {
54
    return urls.map((url) => url.split("\?")[0]);
58✔
55
}
56

57
export const toOLAttributions = credits => credits && creditsToAttribution(credits) || undefined;
59✔
58
/**
59
    @param {object} options of the layer
60
    @return the Openlayers options from the layers ones and/or default.
61
    tiled params must be tru if not defined
62
*/
63
export function wmsToOpenlayersOptions(options) {
64
    const params = optionsToVendorParams(options);
79✔
65
    // NOTE: can we use opacity to manage visibility?
66
    const result = Object.assign({}, options.baseParams, {
79✔
67
        LAYERS: options.name,
68
        STYLES: options.style || "",
158✔
69
        FORMAT: options.format || 'image/png',
94✔
70
        TRANSPARENT: options.transparent !== undefined ? options.transparent : true,
79!
71
        SRS: CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS),
108✔
72
        CRS: CoordinatesUtils.normalizeSRS(options.srs || 'EPSG:3857', options.allowedSRS),
108✔
73
        ...getWMSVendorParams(options),
74
        VERSION: options.version || "1.3.0"
158✔
75
    }, Object.assign(
76
        {},
77
        (options._v_ ? {_v_: options._v_} : {}),
79!
78
        (params || {}),
129✔
79
        (options.localizedLayerStyles &&
158!
80
            options.env && options.env.length &&
81
            options.group !== 'background' ? {ENV: generateEnvString(options.env) } : {})
82
    ));
83
    return addAuthenticationToSLD(result, options);
79✔
84
}
85

86
export const generateTileGrid = (options, map) => {
1✔
87
    const mapSrs = map?.getView()?.getProjection()?.getCode() || 'EPSG:3857';
49✔
88
    const normalizedSrs = CoordinatesUtils.normalizeSRS(options.srs || mapSrs, options.allowedSRS);
49✔
89
    const tileSize = options.tileSize ? options.tileSize : 256;
49✔
90
    const extent = get(normalizedSrs).getExtent() || getProjection(normalizedSrs).extent;
49!
91
    const { TILED } = getWMSVendorParams(options);
49✔
92
    const customTileGrid = TILED && options.tileGridStrategy === 'custom' && options.tileGrids
49✔
93
        ? getTileGridFromLayerOptions({ tileSize, projection: normalizedSrs, tileGrids: options.tileGrids })
94
        : null;
95
    if (customTileGrid
49✔
96
        && (customTileGrid.resolutions || customTileGrid.scales)
97
        && (customTileGrid.origins || customTileGrid.origin)
98
        && (customTileGrid.tileSizes || customTileGrid.tileSize)) {
99
        const {
100
            resolutions: customTileGridResolutions,
101
            scales,
102
            origin,
103
            origins,
104
            tileSize: customTileGridTileSize,
105
            tileSizes
106
        } = customTileGrid;
2✔
107
        const projection = get(normalizedSrs);
2✔
108
        const metersPerUnit = projection.getMetersPerUnit();
2✔
109
        const scaleToResolution = s => s * 0.28E-3 / metersPerUnit;
6✔
110
        const resolutions = customTileGridResolutions
2!
111
            ? customTileGridResolutions
112
            : scales.map(scale => scaleToResolution(scale));
6✔
113
        return new TileGrid({
2✔
114
            extent,
115
            resolutions,
116
            tileSizes,
117
            tileSize: customTileGridTileSize,
118
            origin,
119
            origins
120
        });
121
    }
122
    const resolutions = options.resolutions || getResolutionsForProjection(normalizedSrs, {
47✔
123
        tileWidth: tileSize,
124
        tileHeight: tileSize,
125
        extent
126
    });
127
    const origin = options.origin ? options.origin : [extent[0], extent[1]];
47✔
128
    return new TileGrid({
47✔
129
        extent,
130
        resolutions,
131
        tileSize,
132
        origin
133
    });
134
};
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