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

iTowns / itowns / 10902507646

17 Sep 2024 11:56AM UTC coverage: 86.931% (-0.03%) from 86.964%
10902507646

push

github

Desplandis
release v2.44.2

2791 of 3694 branches covered (75.55%)

Branch coverage included in aggregate %.

24241 of 27402 relevant lines covered (88.46%)

1027.5 hits per line

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

92.5
/src/Source/WMSSource.js
1
import Source from 'Source/Source';
1✔
2
import URLBuilder from 'Provider/URLBuilder';
1✔
3

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

4✔
79
        if (!source.extent) {
4!
80
            throw new Error('source.extent is required');
×
81
        }
×
82

4✔
83
        if (!source.crs && !source.projection) {
4!
84
            throw new Error('source.crs is required');
×
85
        }
×
86

4✔
87
        source.format = source.format || 'image/png';
4✔
88

4✔
89
        super(source);
4✔
90

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

4✔
96
        this.width = source.width || source.height || 256;
4✔
97
        this.height = source.height || source.width || 256;
4✔
98
        this.version = source.version || '1.3.0';
4✔
99
        this.transparent = source.transparent || false;
4✔
100
        this.bboxDigits = source.bboxDigits;
4✔
101

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

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

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

4✔
129

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

1✔
138
    urlFromExtent(extent) {
1✔
139
        return URLBuilder.bbox(extent, this);
2✔
140
    }
2✔
141

1✔
142
    extentInsideLimit(extent) {
1✔
143
        return this.extent.intersectsExtent(extent);
3✔
144
    }
3✔
145
}
1✔
146

1✔
147
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