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

iTowns / itowns / 11161790864

03 Oct 2024 12:16PM UTC coverage: 86.944% (-0.01%) from 86.958%
11161790864

push

github

Desplandis
refacto: split Extent between geographic/tiled

2795 of 3710 branches covered (75.34%)

Branch coverage included in aggregate %.

367 of 392 new or added lines in 15 files covered. (93.62%)

10 existing lines in 2 files now uncovered.

24341 of 27501 relevant lines covered (88.51%)

1022.97 hits per line

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

92.22
/src/Source/WMSSource.js
1
import Source from 'Source/Source';
1✔
2
import URLBuilder from 'Provider/URLBuilder';
1✔
3
import Extent from 'Core/Geographic/Extent';
1✔
4

1✔
5
const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]);
1✔
6

1✔
7
/**
1✔
8
 * An object defining the source of images to get from a
1✔
9
 * [WMS](http://www.opengeospatial.org/standards/wms) server. It inherits
1✔
10
 * from {@link Source}.
1✔
11
 *
1✔
12
 * @extends Source
1✔
13
 *
1✔
14
 * @property {boolean} isWMSSource - Used to checkout whether this source is a
1✔
15
 * WMSSource. Default is true. You should not change this, as it is used
1✔
16
 * internally for optimisation.
1✔
17
 * @property {string} name - The name of the layer, used in the generation of
1✔
18
 * the url.
1✔
19
 * @property {string} version - The version of the WMS server to request on.
1✔
20
 * Default value is '1.3.0'.
1✔
21
 * @property {string} style - The style to query on the WMS server. Default
1✔
22
 * value is 'normal'.
1✔
23
 * @property {number} width - The width of the image to fetch, in pixel.
1✔
24
 * Default value is the height if set or 256.
1✔
25
 * @property {number} height - The height of the image to fetch, in pixel.
1✔
26
 * Default value is the width if set or 256.
1✔
27
 * @property {string} axisOrder - The order of the axis, that helps building the
1✔
28
 * BBOX to put in the url requesting a resource. Default value is 'wsen', other
1✔
29
 * value can be 'swne'.
1✔
30
 * @property {boolean} transparent - Tells if the image to fetch needs
1✔
31
 * transparency support. Default value is false.
1✔
32
 * @property {Object} zoom - Object containing the minimum and maximum values of
1✔
33
 * the level, to zoom in the source.
1✔
34
 * @property {number} zoom.min - The minimum level of the source. Default value
1✔
35
 * is 0.
1✔
36
 * @property {number} zoom.max - The maximum level of the source. Default value
1✔
37
 * is 21.
1✔
38
 * @property {string} bboxDigits - The bbox digits precision used in URL
1✔
39
 * @property {Object} vendorSpecific - An object containing vendor specific
1✔
40
 * parameters. See for example a [list of these parameters for GeoServer](
1✔
41
 * https://docs.geoserver.org/latest/en/user/services/wms/vendor.html). This
1✔
42
 * object is read simply with the `key` being the name of the parameter and
1✔
43
 * `value` being the value of the parameter. If used, this property should be
1✔
44
 * set in the constructor parameters.
1✔
45
 *
1✔
46
 * @example
1✔
47
 * // Create the source
1✔
48
 * const wmsSource = new itowns.WMSSource({
1✔
49
 *     url: 'https://server.geo/wms',
1✔
50
 *     version: '1.3.0',
1✔
51
 *     name: 'REGION.2016',
1✔
52
 *     style: '',
1✔
53
 *     crs: 'EPSG:3857',
1✔
54
 *     extent: {
1✔
55
 *         west: '-6880639.13557728',
1✔
56
 *         east: '6215707.87974825',
1✔
57
 *         south: '-2438399.00148845',
1✔
58
 *         north: '7637050.03850605',
1✔
59
 *     },
1✔
60
 *     transparent: true,
1✔
61
 * });
1✔
62
 *
1✔
63
 * // Create the layer
1✔
64
 * const colorlayer = new itowns.ColorLayer('Region', {
1✔
65
 *     source: wmsSource,
1✔
66
 * });
1✔
67
 *
1✔
68
 * // Add the layer
1✔
69
 * view.addLayer(colorlayer);
1✔
70
 */
1✔
71
class WMSSource extends Source {
1✔
72
    /**
1✔
73
     * @param {Object} source - An object that can contain all properties of
1✔
74
     * WMSSource and {@link Source}. `url`, `name`, `extent` and `crs`
1✔
75
     * are mandatory.
1✔
76
     */
1✔
77
    constructor(source) {
1✔
78
        if (!source.name) {
4!
UNCOV
79
            throw new Error('source.name is required.');
×
80
        }
×
81

4✔
82
        if (!source.extent) {
4!
UNCOV
83
            throw new Error('source.extent is required');
×
84
        }
×
85

4✔
86
        if (!source.crs && !source.projection) {
4!
UNCOV
87
            throw new Error('source.crs is required');
×
UNCOV
88
        }
×
89

4✔
90
        source.format = source.format || 'image/png';
4✔
91

4✔
92
        super(source);
4✔
93

4✔
94
        this.isWMSSource = true;
4✔
95
        this.name = source.name;
4✔
96
        this.zoom = { min: 0, max: Infinity };
4✔
97
        this.style = source.style || '';
4✔
98

4✔
99
        this.width = source.width || source.height || 256;
4✔
100
        this.height = source.height || source.width || 256;
4✔
101
        this.version = source.version || '1.3.0';
4✔
102
        this.transparent = source.transparent || false;
4✔
103
        this.bboxDigits = source.bboxDigits;
4✔
104

4✔
105
        if (!source.axisOrder) {
4✔
106
        // 4326 (lat/long) axis order depends on the WMS version used
4✔
107
            if (this.crs == 'EPSG:4326') {
4✔
108
            // EPSG 4326 x = lat, long = y
2✔
109
            // version 1.1.0 long/lat while version 1.3.0 mandates xy (so lat,long)
2✔
110
                this.axisOrder = (this.version === '1.1.0' ? 'wsen' : 'swne');
2!
111
            } else {
2✔
112
            // xy,xy order
2✔
113
                this.axisOrder = 'wsen';
2✔
114
            }
2✔
115
        }
4✔
116

4✔
117
        const crsPropName = (this.version === '1.3.0') ? 'CRS' : 'SRS';
4!
118

4✔
119
        // Add ? at the end of the url if it is not already in the given URL
4✔
120
        if (!this.url.endsWith('?')) {
4✔
121
            this.url = `${this.url}?`;
4✔
122
        }
4✔
123
        this.url = `${this.url}SERVICE=WMS&REQUEST=GetMap&LAYERS=${
4✔
124
            this.name}&VERSION=${
4✔
125
            this.version}&STYLES=${
4✔
126
            this.style}&FORMAT=${
4✔
127
            this.format}&TRANSPARENT=${
4✔
128
            this.transparent}&BBOX=%bbox&${
4✔
129
            crsPropName}=${
4✔
130
            this.crs}&WIDTH=${this.width}&HEIGHT=${this.height}`;
4✔
131

4✔
132

4✔
133
        this.vendorSpecific = source.vendorSpecific;
4✔
134
        for (const name in this.vendorSpecific) {
4✔
135
            if (Object.prototype.hasOwnProperty.call(this.vendorSpecific, name)) {
3✔
136
                this.url = `${this.url}&${name}=${this.vendorSpecific[name]}`;
3✔
137
            }
3✔
138
        }
3✔
139
    }
1✔
140

1✔
141
    urlFromExtent(extentOrTile) {
1✔
142
        const extent = extentOrTile.isExtent ?
2✔
143
            extentOrTile.as(this.crs, _extent) :
2!
144
            extentOrTile.toExtent(this.crs, _extent);
2✔
145
        return URLBuilder.bbox(extent, this);
2✔
146
    }
2✔
147

1✔
148
    extentInsideLimit(extent) {
1✔
149
        return this.extent.intersectsExtent(extent);
3✔
150
    }
3✔
151
}
1✔
152

1✔
153
export default WMSSource;
1✔
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