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

iTowns / itowns / 10635241580

30 Aug 2024 03:26PM UTC coverage: 86.966% (-2.8%) from 89.766%
10635241580

push

github

jailln
feat(3dtiles): add new OGC3DTilesLayer using 3d-tiles-renderer-js

Deprecate C3DTilesLayer (replaced by OGC3DTilesLayer).
Add new iGLTFLoader that loads gltf 1.0 and 2.0 files.

2791 of 3694 branches covered (75.55%)

Branch coverage included in aggregate %.

480 of 644 new or added lines in 8 files covered. (74.53%)

2144 existing lines in 111 files now uncovered.

24319 of 27479 relevant lines covered (88.5%)

1024.72 hits per line

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

98.24
/src/Source/TMSSource.js
1
import Source from 'Source/Source';
1✔
2
import URLBuilder from 'Provider/URLBuilder';
1✔
3
import Extent, { globalExtentTMS } from 'Core/Geographic/Extent';
1✔
4
import CRS from 'Core/Geographic/Crs';
1✔
5

1✔
6
const extent = new Extent(CRS.tms_4326, 0, 0, 0);
1✔
7

1✔
8
/**
1✔
9
 * @classdesc
1✔
10
 * An object defining the source of resources to get from a [TMS]{@link
1✔
11
 * https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification} server. It
1✔
12
 * inherits from {@link Source}.
1✔
13
 *
1✔
14
 * @extends Source
1✔
15
 *
1✔
16
 * @property {boolean} isTMSSource - Used to checkout whether this source is a
1✔
17
 * TMSSource. Default is true. You should not change this, as it is used
1✔
18
 * internally for optimisation.
1✔
19
 * @property {boolean} isInverted - The isInverted property is to be set to the
1✔
20
 * correct value, true or false (default being false) if the computation of the
1✔
21
 * coordinates needs to be inverted to match the same scheme as OSM, Google Maps
1✔
22
 * or other system. See [this link]{@link
1✔
23
 * https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/}
1✔
24
 * for more information.
1✔
25
 * @property {Object} tileMatrixSetLimits - it describes the available tile for this layer
1✔
26
 * @property {Object} extentSetlimits - these are the extents of the set of identical zoom tiles.
1✔
27
 * @property {Object} zoom - Object containing the minimum and maximum values of
1✔
28
 * the level, to zoom in the source.
1✔
29
 * @property {number} zoom.min - The minimum level of the source. Default value
1✔
30
 * is 0.
1✔
31
 * @property {number} zoom.max - The maximum level of the source. Default value
1✔
32
 * is 20.
1✔
33
 * @property {function} tileMatrixCallback - a method that create a TileMatrix
1✔
34
 * identifier from the zoom level. For example, if set to `(zoomLevel) => 'EPSG:4326:' + zoomLevel`,
1✔
35
 * the TileMatrix that will be fetched at zoom level 5 will be the one with identifier `EPSG:4326:5`.
1✔
36
 * By default, the method returns the input zoom level.
1✔
37
 *
1✔
38
 * @example <caption><b>Source from OpenStreetMap server :</b></caption>
1✔
39
 * // Create the source
1✔
40
 * const tmsSource = new itowns.TMSSource({
1✔
41
 *     format: 'image/png',
1✔
42
 *     url: 'http://osm.io/styles/${z}/${x}/${y}.png',
1✔
43
 *     attribution: {
1✔
44
 *         name: 'OpenStreetMap',
1✔
45
 *         url: 'http://www.openstreetmap.org/',
1✔
46
 *     },
1✔
47
 *     crs: 'EPSG:3857',
1✔
48
 * });
1✔
49
 *
1✔
50
 * // Create the layer
1✔
51
 * const colorLayer = new itowns.ColorLayer('OPENSM', {
1✔
52
 *     source: tmsSource,
1✔
53
 * });
1✔
54
 *
1✔
55
 * // Add the layer
1✔
56
 * view.addLayer(colorLayer);
1✔
57
 *
1✔
58
 * @example <caption><b>Source from Mapbox server :</b></caption>
1✔
59
 * // Create the source
1✔
60
 * const orthoSource = new itowns.TMSSource({
1✔
61
 *     url: 'https://api.mapbox.com/v4/mapbox.satellite/${z}/${x}/${y}.jpg?access_token=' + accessToken,
1✔
62
 *     crs: 'EPSG:3857',
1✔
63
 * };
1✔
64
 *
1✔
65
 * // Create the layer
1✔
66
 * const imageryLayer = new itowns.ColorLayer("Ortho", {
1✔
67
 *     source: orthoSource,
1✔
68
 * };
1✔
69
 *
1✔
70
 * // Add the layer to the view
1✔
71
 * view.addLayer(imageryLayer);
1✔
72
 */
1✔
73
class TMSSource extends Source {
1✔
74
    /**
1✔
75
     * @param {Object} source - An object that can contain all properties of a
1✔
76
     * TMSSource and {@link Source}. Only `url` is mandatory.
1✔
77
     *
1✔
78
     * @constructor
1✔
79
     */
1✔
80
    constructor(source) {
1✔
81
        source.format = source.format || 'image/png';
19✔
82

19✔
83
        super(source);
19✔
84

19✔
85
        if (!source.crs) {
19!
UNCOV
86
            throw new Error('New TMSSource/WMTSSource: crs is required');
×
UNCOV
87
        }
×
88

19✔
89
        this.isTMSSource = true;
19✔
90

19✔
91
        if (!source.extent) {
19✔
92
            // default to the global extent
17✔
93
            this.extent = globalExtentTMS.get(source.crs);
17✔
94
        }
17✔
95

19✔
96
        this.zoom = source.zoom;
19✔
97

19✔
98
        this.isInverted = source.isInverted || false;
19✔
99
        this.crs = CRS.formatToTms(source.crs);
19✔
100
        this.tileMatrixSetLimits = source.tileMatrixSetLimits;
19✔
101
        this.extentSetlimits = {};
19✔
102
        this.tileMatrixCallback = source.tileMatrixCallback || (zoomLevel => zoomLevel);
19✔
103

19✔
104
        if (!this.zoom) {
19✔
105
            if (this.tileMatrixSetLimits) {
16✔
106
                const arrayLimits = Object.keys(this.tileMatrixSetLimits);
3✔
107
                const size = arrayLimits.length;
3✔
108
                const maxZoom = Number(arrayLimits[size - 1]);
3✔
109
                const minZoom = maxZoom - size + 1;
3✔
110

3✔
111
                this.zoom = {
3✔
112
                    min: minZoom,
3✔
113
                    max: maxZoom,
3✔
114
                };
3✔
115
            } else {
16✔
116
                this.zoom = { min: 0, max: Infinity };
13✔
117
            }
13✔
118
        }
16✔
119
    }
19✔
120

1✔
121
    urlFromExtent(extent) {
1✔
122
        return URLBuilder.xyz(extent, this);
8✔
123
    }
8✔
124

1✔
125
    onLayerAdded(options) {
1✔
126
        super.onLayerAdded(options);
7✔
127
        // Build extents of the set of identical zoom tiles.
7✔
128
        const parent = options.out.parent;
7✔
129
        // The extents crs is chosen to facilitate in raster tile process.
7✔
130
        const crs = parent ? parent.extent.crs : options.out.crs;
7✔
131
        if (this.tileMatrixSetLimits && !this.extentSetlimits[crs]) {
7✔
132
            this.extentSetlimits[crs] = {};
2✔
133
            extent.crs = this.crs;
2✔
134
            for (let i = this.zoom.max; i >= this.zoom.min; i--) {
2✔
135
                const tmsl = this.tileMatrixSetLimits[i];
7✔
136
                const { west, north } = extent.set(i, tmsl.minTileRow, tmsl.minTileCol).as(crs);
7✔
137
                const { east, south } = extent.set(i, tmsl.maxTileRow, tmsl.maxTileCol).as(crs);
7✔
138
                this.extentSetlimits[crs][i] = new Extent(crs, west, east, south, north);
7✔
139
            }
7✔
140
        }
2✔
141
    }
7✔
142

1✔
143
    extentInsideLimit(extent, zoom) {
1✔
144
        // This layer provides data starting at level = layer.source.zoom.min
11✔
145
        // (the zoom.max property is used when building the url to make
11✔
146
        //  sure we don't use invalid levels)
11✔
147
        return zoom >= this.zoom.min && zoom <= this.zoom.max &&
11✔
148
                (this.extentSetlimits[extent.crs] == undefined || this.extentSetlimits[extent.crs][zoom].intersectsExtent(extent));
11✔
149
    }
11✔
150
}
1✔
151

1✔
152
export default TMSSource;
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