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

geosolutions-it / MapStore2 / 14797665772

02 May 2025 02:55PM UTC coverage: 76.933% (-0.06%) from 76.991%
14797665772

Pull #11067

github

web-flow
Merge 99dcd7f92 into d28bf7035
Pull Request #11067: Fix #10966 basic auth for services

30858 of 48053 branches covered (64.22%)

104 of 172 new or added lines in 24 files covered. (60.47%)

3 existing lines in 3 files now uncovered.

38384 of 49893 relevant lines covered (76.93%)

35.93 hits per line

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

8.0
/web/client/components/map/openlayers/plugins/TileProviderLayer.js
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
import assign from 'object-assign';
9
import Layers from '../../../../utils/openlayers/Layers';
10
import TileProvider from '../../../../utils/TileConfigProvider';
11
import CoordinatesUtils from '../../../../utils/CoordinatesUtils';
12
import { getUrls, template } from '../../../../utils/TileProviderUtils';
13
import XYZ from 'ol/source/XYZ';
14
import TileLayer from 'ol/layer/Tile';
15
import axios from 'axios';
16
import { getCredentials } from '../../../../utils/SecurityUtils';
17
import { isEqual } from 'lodash';
18
function lBoundsToOlExtent(bounds, destPrj) {
19
    var [ [ miny, minx], [ maxy, maxx ] ] = bounds;
×
20
    return CoordinatesUtils.reprojectBbox([minx, miny, maxx, maxy], 'EPSG:4326', CoordinatesUtils.normalizeSRS(destPrj));
×
21
}
22

23
const tileLoadFunction = options => (image, src) => {
1✔
NEW
24
    const storedProtectedService = getCredentials(options.security?.sourceId) || {};
×
NEW
25
    axios.get(src, {
×
26
        headers: {
27
            "Authorization": `Basic ${btoa(storedProtectedService.username + ":" + storedProtectedService.password)}`
28
        },
29
        responseType: 'blob'
30
    }).then(response => {
NEW
31
        image.getImage().src = URL.createObjectURL(response.data);
×
32
    }).catch(e => {
NEW
33
        image.getImage().src = null;
×
NEW
34
        console.error(e);
×
35
    });
36
};
37
function tileXYZToOpenlayersOptions(options) {
38
    let urls = options.url.match(/(\{s\})/) ? getUrls(options) : [template(options.url, options)];
×
39
    let sourceOpt = assign({}, {
×
40
        urls: urls,
41
        attributions: options.attribution ? [options.attribution] : [],
×
42
        maxZoom: options.maxZoom ? options.maxZoom : 18,
×
43
        minZoom: options.minZoom ? options.minZoom : 0 // dosen't affect ol layer rendering UNSUPPORTED
×
44
    });
NEW
45
    if (options.security) {
×
NEW
46
        sourceOpt.tileLoadFunction = tileLoadFunction(options);
×
47
    }
48
    let source = new XYZ(sourceOpt);
×
49
    let olOpt = assign({}, {
×
50
        msId: options.id,
51
        opacity: options.opacity !== undefined ? options.opacity : 1,
×
52
        visible: options.visibility !== false,
53
        zIndex: options.zIndex,
54
        source: source,
55
        minResolution: options.minResolution,
56
        maxResolution: options.maxResolution
57
    }, options.bounds ? {extent: lBoundsToOlExtent(options.bounds, options.srs ? options.srs : 'EPSG:3857')} : {} );
×
58
    return olOpt;
×
59
}
60

61
Layers.registerType('tileprovider', {
1✔
62
    create: (options) => {
63
        let [url, opt] = TileProvider.getLayerConfig(options.provider, options);
×
64
        opt.url = url;
×
65
        return new TileLayer(tileXYZToOpenlayersOptions(opt));
×
66
    },
67
    update: (layer, newOptions, oldOptions) => {
68
        if (oldOptions.minResolution !== newOptions.minResolution) {
×
69
            layer.setMinResolution(newOptions.minResolution === undefined ? 0 : newOptions.minResolution);
×
70
        }
71
        if (oldOptions.maxResolution !== newOptions.maxResolution) {
×
72
            layer.setMaxResolution(newOptions.maxResolution === undefined ? Infinity : newOptions.maxResolution);
×
73
        }
NEW
74
        if (!isEqual(oldOptions.security, newOptions.security)) {
×
NEW
75
            layer.getSource().setTileLoadFunction(tileLoadFunction(newOptions));
×
76
        }
77
    }
78
});
79

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