-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathdataSourceProvider.js
More file actions
326 lines (291 loc) · 11.9 KB
/
dataSourceProvider.js
File metadata and controls
326 lines (291 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import * as THREE from 'three';
import assert from 'assert';
import { updateLayeredMaterialNodeImagery, updateLayeredMaterialNodeElevation } from 'Process/LayeredMaterialNodeProcessing';
import FeatureProcessing from 'Process/FeatureProcessing';
import TileMesh from 'Core/TileMesh';
import { Extent } from '@itowns/geographic';
import { globalExtentTMS } from 'Core/Tile/TileGrid';
import OBB from 'Renderer/OBB';
import DataSourceProvider from 'Provider/DataSourceProvider';
import Fetcher from 'Provider/Fetcher';
import WMTSSource from 'Source/WMTSSource';
import WMSSource from 'Source/WMSSource';
import WFSSource from 'Source/WFSSource';
import LayerUpdateState from 'Layer/LayerUpdateState';
import ColorLayer from 'Layer/ColorLayer';
import ElevationLayer from 'Layer/ElevationLayer';
import GeometryLayer from 'Layer/GeometryLayer';
import PlanarLayer from 'Core/Prefab/Planar/PlanarLayer';
import Style from 'Core/Style';
import Feature2Mesh from 'Converter/Feature2Mesh';
import LayeredMaterial from 'Renderer/LayeredMaterial';
import { EMPTY_TEXTURE_ZOOM } from 'Renderer/RasterTile';
import sinon from 'sinon';
import holes from '../data/geojson/holesPoints.geojson';
describe('Provide in Sources', function () {
// TODO We should mock the creation of all layers creation.
// Misc var to initialize a TileMesh instance
const geom = new THREE.BufferGeometry();
geom.OBB = new OBB(new THREE.Vector3(), new THREE.Vector3(1, 1, 1));
const globalExtent = globalExtentTMS.get('EPSG:3857');
const material = new LayeredMaterial();
const zoom = 10;
const sizeTile = globalExtent.planarDimensions().x / 2 ** zoom;
const extent = new Extent('EPSG:3857', 0, sizeTile, 0, sizeTile);
let stubFetcherJson;
let stubFetcherTexture;
let planarlayer;
let elevationlayer;
let colorlayer;
let nodeLayer;
let nodeLayerElevation;
let featureLayer;
// Mock scheduler
const context = {
view: {
notifyChange: () => true,
},
scheduler: {
commands: [],
execute: (cmd) => {
context.scheduler.commands.push(cmd);
return new Promise(() => { /* no-op */ });
},
},
};
before(function () {
stubFetcherJson = sinon.stub(Fetcher, 'json')
.callsFake(() => Promise.resolve(JSON.parse(holes)));
stubFetcherTexture = sinon.stub(Fetcher, 'texture')
.callsFake(() => Promise.resolve(new THREE.Texture()));
planarlayer = new PlanarLayer('globe', globalExtent, new THREE.Group());
colorlayer = new ColorLayer('color', { crs: 'EPSG:3857', source: false });
elevationlayer = new ElevationLayer('elevation', { crs: 'EPSG:3857', source: false });
planarlayer.attach(colorlayer);
planarlayer.attach(elevationlayer);
const fakeNode = { material, setBBoxZ: () => {}, addEventListener: () => {} };
colorlayer.setupRasterNode(fakeNode);
elevationlayer.setupRasterNode(fakeNode);
nodeLayer = material.getLayer(colorlayer.id);
nodeLayerElevation = material.getLayer(elevationlayer.id);
featureLayer = new GeometryLayer('geom', new THREE.Group(), {
crs: 'EPSG:4978',
mergeFeatures: false,
zoom: { min: 10 },
source: false,
style: new Style({
fill: {
extrusion_height: 5000,
color: new THREE.Color(0xffcc00),
},
}),
});
featureLayer.update = FeatureProcessing.update;
featureLayer.convert = Feature2Mesh.convert();
featureLayer.source = new WFSSource({
url: 'http://domain.com',
typeName: 'name',
format: 'application/json',
extent: globalExtent,
crs: 'EPSG:3857',
});
planarlayer.attach(featureLayer);
context.elevationLayers = [elevationlayer];
context.colorLayers = [colorlayer];
});
after(function () {
stubFetcherJson.restore();
stubFetcherTexture.restore();
});
beforeEach('reset state', function () {
// clear commands array
context.scheduler.commands = [];
});
it('should get wmts texture with DataSourceProvider', (done) => {
colorlayer.source = new WMTSSource({
url: 'http://domain.com',
name: 'name',
format: 'image/png',
tileMatrixSet: 'PM',
crs: 'EPSG:3857',
extent: globalExtent,
zoom: {
min: 0,
max: 12,
},
});
colorlayer.source.onLayerAdded({ out: colorlayer });
const tile = new TileMesh(geom, material, planarlayer, extent);
material.visible = true;
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.parent = { };
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
assert.equal(textures.length, 1);
assert.equal(textures[0].isTexture, true);
done();
}).catch(done);
});
it('should get wmts texture elevation with DataSourceProvider', (done) => {
elevationlayer.source = new WMTSSource({
url: 'http://domain.com',
name: 'name',
format: 'image/png',
tileMatrixSet: 'PM',
crs: 'EPSG:3857',
zoom: {
min: 0,
max: 12,
},
});
elevationlayer.source.onLayerAdded({ out: elevationlayer });
const tile = new TileMesh(geom, material, planarlayer, extent, zoom);
material.visible = true;
nodeLayerElevation.level = EMPTY_TEXTURE_ZOOM;
tile.parent = {};
updateLayeredMaterialNodeElevation(context, elevationlayer, tile, tile.parent);
updateLayeredMaterialNodeElevation(context, elevationlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
assert.equal(textures.length, 1);
assert.equal(textures[0].isTexture, true);
done();
}).catch(done);
});
it('should get wms texture with DataSourceProvider', (done) => {
colorlayer.source = new WMSSource({
url: 'http://domain.com',
name: 'name',
format: 'image/png',
extent: globalExtent,
crs: 'EPSG:3857',
zoom: {
min: 0,
max: 12,
},
});
// May be move in layer Constructor
colorlayer.source.onLayerAdded({ out: colorlayer });
const tile = new TileMesh(geom, material, planarlayer, extent, zoom);
material.visible = true;
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.parent = { };
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
assert.equal(textures.length, 1);
assert.equal(textures[0].isTexture, true);
done();
}).catch(done);
});
it('should get 3 meshs with WFS source and DataSourceProvider', (done) => {
const tile = new TileMesh(geom, material, planarlayer, extent, featureLayer.zoom.min);
material.visible = true;
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.parent = { pendingSubdivision: false };
featureLayer.mergeFeatures = false;
tile.layerUpdateState = { test: new LayerUpdateState() };
featureLayer.source.onLayerAdded({ out: featureLayer });
featureLayer.update(context, featureLayer, tile);
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((features) => {
assert.equal(features[0].meshes.children.length, 4);
done();
}).catch(done);
});
it('should get 1 mesh with WFS source and DataSourceProvider and mergeFeatures == true', (done) => {
const tile = new TileMesh(
geom,
material,
planarlayer,
extent,
featureLayer.zoom.min);
tile.material.visible = true;
tile.parent = { pendingSubdivision: false };
featureLayer.source.uid = 8;
featureLayer.mergeFeatures = true;
featureLayer.cache.clear();
featureLayer.source._featuresCaches = {};
featureLayer.source.onLayerAdded({ out: featureLayer });
featureLayer.update(context, featureLayer, tile);
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((features) => {
assert.ok(features[0].meshes.children[0].isMesh);
assert.ok(features[0].meshes.children[1].isPoints);
assert.equal(features[0].meshes.children[0].children.length, 0);
assert.equal(features[0].meshes.children[1].children.length, 0);
done();
}).catch(done);
});
it('should get 1 texture with WFS source and DataSourceProvider', (done) => {
const tile = new TileMesh(
geom,
material,
planarlayer,
extent,
zoom);
material.visible = true;
tile.parent = { pendingSubdivision: false };
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.material.visible = true;
featureLayer.source.uid = 22;
const colorlayerWfs = new ColorLayer('color', { crs: 'EPSG:3857',
source: featureLayer.source,
style: {
fill: {
color: 'red',
opacity: 0.5,
},
stroke: {
color: 'white',
width: 2.0,
},
point: {
color: 'white',
line: 'green',
},
},
});
colorlayerWfs.source.onLayerAdded({ out: colorlayerWfs });
updateLayeredMaterialNodeImagery(context, colorlayerWfs, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayerWfs, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((textures) => {
assert.equal(textures.length, 1);
assert.ok(textures[0].isTexture);
done();
}).catch(done);
});
it('should get updated RasterLayer', (done) => {
colorlayer.source = new WMTSSource({
url: 'http://domain.com',
name: 'name',
format: 'image/png',
tileMatrixSet: 'PM',
crs: 'EPSG:3857',
extent: globalExtent,
zoom: {
min: 0,
max: 12,
},
});
const tile = new TileMesh(geom, new LayeredMaterial(), planarlayer, extent);
tile.material.visible = true;
nodeLayer.level = EMPTY_TEXTURE_ZOOM;
tile.parent = { };
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
updateLayeredMaterialNodeImagery(context, colorlayer, tile, tile.parent);
DataSourceProvider.executeCommand(context.scheduler.commands[0])
.then((result) => {
tile.material.setSequence([colorlayer.id]);
tile.material.getLayer(colorlayer.id).setTextures(result, [new THREE.Vector4()]);
assert.equal(tile.material.uniforms.colorTextures.value[0].anisotropy, 1);
tile.material.updateLayersUniforms();
assert.equal(tile.material.uniforms.colorTextures.value[0].anisotropy, 16);
done();
}).catch(done);
});
});