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

geosolutions-it / MapStore2 / 19935919825

04 Dec 2025 04:19PM UTC coverage: 76.703% (+0.04%) from 76.661%
19935919825

Pull #11648

github

web-flow
Merge f9ef0e5ca into a0da62e93
Pull Request #11648: #11644: Implement dynamic request configurations

32405 of 50408 branches covered (64.29%)

220 of 244 new or added lines in 42 files covered. (90.16%)

3 existing lines in 3 files now uncovered.

40299 of 52539 relevant lines covered (76.7%)

40.18 hits per line

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

6.45
/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 { hasRequestConfigurationByUrl } from '../../../../utils/SecurityUtils';
16
const tileLoadFunction = options => (image, src) => {
1✔
17
    axios.get(src, {
×
18
        _msAuthSourceId: options.security?.sourceId,
19
        responseType: 'blob'
20
    }).then(response => {
21
        image.getImage().src = URL.createObjectURL(response.data);
×
22
    }).catch(e => {
23
        image.getImage().src = null;
×
24
        console.error(e);
×
25
    });
26
};
27

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

39
    let source = new XYZ(sourceOpt);
×
40
    const defaultTileGrid = source.getTileGrid();
×
41

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

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

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