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

iTowns / itowns / 20853113812

09 Jan 2026 01:16PM UTC coverage: 87.974%. First build
20853113812

Pull #2659

github

web-flow
Merge 7169a4801 into bbd11b5f3
Pull Request #2659: [fix]: Vpc Layer and multisources -> too many request at once

2755 of 3557 branches covered (77.45%)

Branch coverage included in aggregate %.

49 of 101 new or added lines in 9 files covered. (48.51%)

28210 of 31641 relevant lines covered (89.16%)

1198.82 hits per line

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

84.4
/packages/Main/src/Source/VpcSource.js
1
import { CRS } from '@itowns/geographic';
1✔
2
import LASParser from 'Parser/LASParser';
1✔
3
import Fetcher from 'Provider/Fetcher';
1✔
4
import Source from 'Source/Source';
1✔
5
import EntwinePointTileSource from 'Source/EntwinePointTileSource';
1✔
6
import CopcSource from 'Source/CopcSource';
1✔
7

1✔
8
/**
1✔
9
 * An object defining the source of Entwine Point Tile data. It fetches and
1✔
10
 * parses the main configuration file of Entwine Point Tile format,
1✔
11
 * [`ept.json`](https://entwine.io/entwine-point-tile.html#ept-json).
1✔
12
 *
1✔
13
 * @extends Source
1✔
14
 *
1✔
15
 * @property {boolean} isEntwinePointTileSource - Used to checkout whether this
1✔
16
 * source is a EntwinePointTileSource. Default is true. You should not change
1✔
17
 * this, as it is used internally for optimisation.
1✔
18
 * @property {string} url - The URL of the directory containing the whole
1✔
19
 * Entwine Point Tile structure.
1✔
20
 * @property {Object[]|PointCloudSource[]} sources - Array of all the source described in the VPC.
1✔
21
 * initialized with mockSource that will be replace by COPC or EPT Source as soon as any data need
1✔
22
 * to be loaded.
1✔
23
 */
1✔
24
class VpcSource extends Source {
1✔
25
    /**
1✔
26
     * @param {Object} config - The configuration, see {@link Source} for
1✔
27
     * available values.
1✔
28
     * @param {number} [config.colorDepth] - Color depth (in bits).
1✔
29
     * Either 8 or 16 bits. By defaults it will be set to 8 bits for LAS 1.2 and
1✔
30
     * 16 bits for later versions (as mandatory by the specification).
1✔
31
     */
1✔
32
    constructor(config) {
1✔
33
        super(config);
2✔
34

2✔
35
        this.isVpcSource = true;
2✔
36
        this.sources = [];
2✔
37

2✔
38
        this.parser = LASParser.parseChunk;
2✔
39
        this.fetcher = Fetcher.arrayBuffer;
2✔
40

2✔
41
        this.colorDepth = config.colorDepth;
2✔
42

2✔
43
        this.spacing = Infinity;
2✔
44

2✔
45
        this.whenReady = Fetcher.json(this.url, this.networkOptions)
2✔
46
            .then((metadata) => {
2✔
47
                this.metadata = metadata;
2✔
48

2✔
49
                // Set the Crs of the VPC Layer.
2✔
50
                const projsWkt2 = metadata.features.map(f => f.properties['proj:wkt2']);
2✔
51
                const crs = [...new Set(projsWkt2)];
2✔
52
                if (crs.length !== 1) {
2!
53
                    console.warn('Only 1 crs is supported for 1 vpc.');
×
54
                }
×
55
                this.crs = CRS.defsFromWkt(projsWkt2[0]);
2✔
56

2✔
57
                // Set boundsConformings (the bbox) of the VPC Layer
2✔
58
                const boundsConformings = metadata.features
2✔
59
                    .filter(f => f.properties['proj:wkt2'] === projsWkt2[0])
2✔
60
                    .map(f => f.properties['proj:bbox']);
2✔
61

2✔
62
                this.boundsConforming = [
2✔
63
                    Math.min(...boundsConformings.map(b => b[0])),
2✔
64
                    Math.min(...boundsConformings.map(b => b[1])),
2✔
65
                    Math.min(...boundsConformings.map(b => b[2])),
2✔
66
                    Math.max(...boundsConformings.map(b => b[3])),
2✔
67
                    Math.max(...boundsConformings.map(b => b[4])),
2✔
68
                    Math.max(...boundsConformings.map(b => b[5])),
2✔
69
                ];
2✔
70

2✔
71
                // Set the zmin and zmax from the source
2✔
72
                this.zmin = this.boundsConforming[2];
2✔
73
                this.zmax = this.boundsConforming[5];
2✔
74

2✔
75
                /* Set  several object (MockSource) to mock the source that will need to be instantiated.
2✔
76
                 We don't want all child source to be instantiated at once as it will send the fetch request
2✔
77
                 (current architectural choice) thus we want to delay the instanciation of the child source
2✔
78
                 when the data need to be load on a particular node.
2✔
79
                 Creation of 1 mockSource for each item in the stack (that will be replace by a real source
2✔
80
                 when needed, when we will call the load on a node depending of that source).
2✔
81
                */
2✔
82
                this._promises = [];
2✔
83
                this.urls = metadata.features.map(f => f.assets.data.href);
2✔
84
                this.urls.forEach((url, i) => {
2✔
85
                    let resolve;
8✔
86
                    const whenReady = new Promise((re) => {
8✔
87
                        // waiting for source to be instantiate;
8✔
88
                        resolve = re;
8✔
89
                    }).catch((err) => {
8✔
90
                        console.warn(err);
×
91
                        this.handlingError(err);
×
92
                    });
8✔
93

8✔
94
                    const mockSource = {
8✔
95
                        boundsConforming: boundsConformings[i],
8✔
96
                        whenReady,
8✔
97
                        crs: CRS.defsFromWkt(projsWkt2[i]),
8✔
98
                        instantiate: () => {
8✔
NEW
99
                            let newSource;
×
NEW
100

×
NEW
101
                            if (url.includes('.copc')) {
×
NEW
102
                                newSource = new CopcSource({ url });
×
NEW
103
                            } else if (url.includes('.json')) {
×
NEW
104
                                newSource = new EntwinePointTileSource({ url });
×
NEW
105
                            } else {
×
NEW
106
                                const msg = '[VPCLayer]: stack point cloud format not supporter';
×
NEW
107
                                console.warn(msg);
×
NEW
108
                                this.handlingError(msg);
×
NEW
109
                            }
×
NEW
110

×
NEW
111
                            resolve(newSource.whenReady);
×
NEW
112

×
NEW
113
                            this.sources[i] = newSource;
×
NEW
114

×
NEW
115
                            return newSource;
×
116
                        },
8✔
117
                        instantiation: false,
8✔
118
                    };
8✔
119
                    this.sources.push(mockSource);
8✔
120
                });
2✔
121
                return this.sources;
2✔
122
            });
2✔
123
    }
2✔
124
}
1✔
125

1✔
126
export default VpcSource;
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