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

geosolutions-it / MapStore2 / 19060241474

04 Nov 2025 06:46AM UTC coverage: 76.943% (+0.02%) from 76.92%
19060241474

Pull #11648

github

web-flow
Merge 763e0cf1e into 19e678788
Pull Request #11648: #11644: Implement dynamic request configurations

32057 of 49801 branches covered (64.37%)

201 of 222 new or added lines in 39 files covered. (90.54%)

4 existing lines in 3 files now uncovered.

39801 of 51728 relevant lines covered (76.94%)

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

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

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

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

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

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