• 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

6.25
/web/client/components/map/openlayers/plugins/TMSLayer.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 { get, isEqual } from 'lodash';
9
import axios from 'axios';
10
import XYZ from 'ol/source/XYZ';
11
import TileGrid from 'ol/tilegrid/TileGrid';
12
import TileLayer from 'ol/layer/Tile';
13

14
import Layers from '../../../../utils/openlayers/Layers';
15
import { getCredentials } from '../../../../utils/SecurityUtils';
16

17
const tileLoadFunction = options => (image, src) => {
1✔
NEW
18
    const storedProtectedService = getCredentials(options.security?.sourceId) || {};
×
NEW
19
    axios.get(src, {
×
20
        headers: {
21
            "Authorization": `Basic ${btoa(storedProtectedService.username + ":" + storedProtectedService.password)}`
22
        },
23
        responseType: 'blob'
24
    }).then(response => {
NEW
25
        image.getImage().src = URL.createObjectURL(response.data);
×
26
    }).catch(e => {
NEW
27
        image.getImage().src = null;
×
NEW
28
        console.error(e);
×
29
    });
30
};
31

32
function tileXYZToOpenlayersOptions(options = {}) {
×
33
    const { minx, miny, maxx, maxy } = get(options, "bbox.bounds", {});
×
34
    const sourceOpt = {
×
35
        projection: options.srs,
36
        url: `${options.tileMapUrl}/{z}/{x}/{-y}.${options.extension}`, // TODO use resolutions
37
        attributions: options.attribution ? [options.attribution] : []
×
38
    };
NEW
39
    if (options.security) {
×
NEW
40
        sourceOpt.tileLoadFunction = tileLoadFunction(options);
×
41
    }
42

43
    let source = new XYZ(sourceOpt);
×
44
    const defaultTileGrid = source.getTileGrid();
×
45

46
    if (options.forceDefaultTileGrid) {
×
47
        const defaultExtent = defaultTileGrid.getExtent();
×
48
        const newOrigin = [defaultExtent[0], defaultExtent[1]]; // minx, miny instead of top left corner, origin is bottom left.
×
49
        const newTileGrid = new TileGrid({
×
50
            // origin must be overridden because GeoServer uses the tile-set origin and OL uses by default extent corner.
51
            origin: newOrigin,
52
            extent: options.bbox && [minx, miny, maxx, maxy],
×
53
            resolutions: defaultTileGrid.getResolutions(),
54
            tileSize: options.tileSize
55
        });
56
        source.setTileGridForProjection(options.srs, newTileGrid);
×
57
        if (options.srs === "EPSG:3857") {
×
58
            source.setTileGridForProjection("EPSG:900913", newTileGrid);
×
59
        }
60
    } else if (options.tileSets) {
×
61
        source.setTileGridForProjection(options.srs, new TileGrid({
×
62
            origin: options.origin,
63
            extent: options.bbox && [minx, miny, maxx, maxy],
×
64
            resolutions: options.tileSets.map(({ resolution }) => resolution),
×
65
            tileSize: options.tileSize
66
        }));
67
    }
68
    let olOpt = {
×
69
        msId: options.id,
70
        extent: options.bbox && [minx, miny, maxx, maxy],
×
71
        opacity: options.opacity !== undefined ? options.opacity : 1,
×
72
        visible: options.visibility !== false,
73
        zIndex: options.zIndex,
74
        source: source,
75
        minResolution: options.minResolution,
76
        maxResolution: options.maxResolution
77
    };
78
    return olOpt;
×
79
}
80

81
Layers.registerType('tms', {
1✔
82
    create: (options) => {
83
        return new TileLayer(tileXYZToOpenlayersOptions(options));
×
84
    },
85
    update: (layer, newOptions, oldOptions) => {
86
        if (oldOptions.minResolution !== newOptions.minResolution) {
×
87
            layer.setMinResolution(newOptions.minResolution === undefined ? 0 : newOptions.minResolution);
×
88
        }
89
        if (oldOptions.maxResolution !== newOptions.maxResolution) {
×
90
            layer.setMaxResolution(newOptions.maxResolution === undefined ? Infinity : newOptions.maxResolution);
×
91
        }
NEW
92
        if (!isEqual(oldOptions.security, newOptions.security)) {
×
NEW
93
            layer.getSource().setTileLoadFunction(tileLoadFunction(newOptions));
×
94
        }
95
    }
96
});
97

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