Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf41e8d

Browse files
committed
refactor(Layer): remove Object.assign of config
1 parent 83eb0d9 commit cf41e8d

27 files changed

+503
-192
lines changed

examples/layers/JSONLayers/GeoidMNT.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"updateStrategy": {
55
"type": 0
66
},
7-
"zmin": -12000,
7+
"clampValues": {
8+
"min": -12000
9+
},
810
"source": {
911
"url": "https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/geoid/geoid/bil/%TILEMATRIX/geoid_%COL_%ROW.bil",
1012
"format": "image/x-bil;bits=32",

examples/source_file_geojson_3d.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
crs: 'EPSG:4326',
5555
format: 'application/json',
5656
}),
57-
transparent: true,
5857
opacity: 0.7,
5958
zoom: { min: 10 },
6059
style: {

examples/source_stream_wfs_raster.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@
5353
itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
5454
itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);
5555

56-
function isValidData(data) {
57-
if(data.features[0].geometries.length < 1000) {
58-
return data;
59-
}
60-
}
61-
6256
var wfsBuildingSource = new itowns.WFSSource({
6357
url: 'https://data.geopf.fr/wfs/ows?',
6458
version: '2.0.0',
@@ -102,7 +96,6 @@
10296
width: 2.0,
10397
},
10498
},
105-
isValidData: isValidData,
10699
source: wfsBuildingSource,
107100
zoom: { max: 20, min: 13 },
108101
});

src/Converter/Feature2Texture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default {
122122

123123
c.width = sizeTexture;
124124
c.height = sizeTexture;
125-
const ctx = c.getContext('2d');
125+
const ctx = c.getContext('2d', { willReadFrequently: true });
126126
if (backgroundColor) {
127127
ctx.fillStyle = backgroundColor.getStyle();
128128
ctx.fillRect(0, 0, sizeTexture, sizeTexture);

src/Core/Prefab/Globe/Atmosphere.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ const spaceColor = new THREE.Color(0x030508);
2929
const limitAlti = 600000;
3030
const mfogDistance = ellipsoidSizes.x * 160.0;
3131

32-
32+
/**
33+
* @extends GeometryLayer
34+
*/
3335
class Atmosphere extends GeometryLayer {
3436
/**
3537
* It's layer to simulate Globe atmosphere.
@@ -39,8 +41,6 @@ class Atmosphere extends GeometryLayer {
3941
* * [Atmosphere Shader From Space (Atmospheric scattering)](http://stainlessbeer.weebly.com/planets-9-atmospheric-scattering.html)
4042
* * [Accurate Atmospheric Scattering (NVIDIA GPU Gems 2)](https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering).
4143
*
42-
* @extends GeometryLayer
43-
*
4444
* @param {string} id - The id of the layer Atmosphere.
4545
* @param {Object} [options] - options layer.
4646
* @param {number} [options.Kr] - `Kr` is the rayleigh scattering constant.

src/Core/Prefab/Globe/GlobeLayer.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ const scaledHorizonCullingPoint = new THREE.Vector3();
1717
* @property {boolean} isGlobeLayer - Used to checkout whether this layer is a
1818
* GlobeLayer. Default is true. You should not change this, as it is used
1919
* internally for optimisation.
20+
*
21+
* @extends TiledGeometryLayer
2022
*/
2123
class GlobeLayer extends TiledGeometryLayer {
2224
/**
2325
* A {@link TiledGeometryLayer} to use with a {@link GlobeView}. It has
2426
* specific method for updating and subdivising its grid.
2527
*
26-
* @extends TiledGeometryLayer
27-
*
2828
* @param {string} id - The id of the layer, that should be unique. It is
2929
* not mandatory, but an error will be emitted if this layer is added a
3030
* {@link View} that already has a layer going by that id.
31-
* @param {THREE.Object3d} [object3d=THREE.Group] - The object3d used to
31+
* @param {THREE.Object3D} [object3d=THREE.Group] - The object3d used to
3232
* contain the geometry of the TiledGeometryLayer. It is usually a
3333
* `THREE.Group`, but it can be anything inheriting from a `THREE.Object3d`.
3434
* @param {Object} [config] - Optional configuration, all elements in it
@@ -46,24 +46,34 @@ class GlobeLayer extends TiledGeometryLayer {
4646
* @throws {Error} `object3d` must be a valid `THREE.Object3d`.
4747
*/
4848
constructor(id, object3d, config = {}) {
49+
const {
50+
minSubdivisionLevel = 2,
51+
maxSubdivisionLevel = 19,
52+
...tiledConfig
53+
} = config;
54+
4955
// Configure tiles
5056
const scheme = schemeTiles.get('EPSG:4326');
5157
const schemeTile = globalExtentTMS.get('EPSG:4326').subdivisionByScheme(scheme);
5258

5359
// Supported tile matrix set for color/elevation layer
54-
config.tileMatrixSets = [
60+
const tileMatrixSets = [
5561
'EPSG:4326',
5662
'EPSG:3857',
5763
];
58-
const uvCount = config.tileMatrixSets.length;
64+
const uvCount = tileMatrixSets.length;
5965
const builder = new BuilderEllipsoidTile({ crs: 'EPSG:4978', uvCount });
6066

61-
super(id, object3d || new THREE.Group(), schemeTile, builder, config);
67+
super(id, object3d || new THREE.Group(), schemeTile, builder, {
68+
tileMatrixSets,
69+
...tiledConfig,
70+
});
6271

6372
this.isGlobeLayer = true;
6473
this.options.defaultPickingRadius = 5;
65-
this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 2 : this.minSubdivisionLevel;
66-
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 19 : this.maxSubdivisionLevel;
74+
this.minSubdivisionLevel = minSubdivisionLevel;
75+
this.maxSubdivisionLevel = maxSubdivisionLevel;
76+
6777
this.extent = this.schemeTile[0].clone();
6878

6979
for (let i = 1; i < this.schemeTile.length; i++) {

src/Core/Prefab/Planar/PlanarLayer.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import PlanarTileBuilder from './PlanarTileBuilder';
88
* @property {boolean} isPlanarLayer - Used to checkout whether this layer is a
99
* PlanarLayer. Default is true. You should not change this, as it is used
1010
* internally for optimisation.
11+
* @extends TiledGeometryLayer
1112
*/
1213
class PlanarLayer extends TiledGeometryLayer {
1314
/**
1415
* A {@link TiledGeometryLayer} to use with a {@link PlanarView}. It has
1516
* specific method for updating and subdivising its grid.
1617
*
17-
* @extends TiledGeometryLayer
18-
*
1918
* @param {string} id - The id of the layer, that should be unique. It is
2019
* not mandatory, but an error will be emitted if this layer is added a
2120
* {@link View} that already has a layer going by that id.
@@ -34,17 +33,28 @@ class PlanarLayer extends TiledGeometryLayer {
3433
* @throws {Error} `object3d` must be a valid `THREE.Object3d`.
3534
*/
3635
constructor(id, extent, object3d, config = {}) {
36+
const {
37+
minSubdivisionLevel = 0,
38+
maxSubdivisionLevel = 5,
39+
...tiledConfig
40+
} = config;
41+
3742
const tileMatrixSets = [extent.crs];
3843
if (!globalExtentTMS.get(extent.crs)) {
3944
// Add new global extent for this new crs projection.
4045
globalExtentTMS.set(extent.crs, extent);
4146
}
42-
config.tileMatrixSets = tileMatrixSets;
43-
super(id, object3d || new THREE.Group(), [extent], new PlanarTileBuilder({ crs: extent.crs }), config);
47+
48+
const builder = new PlanarTileBuilder({ crs: extent.crs });
49+
super(id, object3d || new THREE.Group(), [extent], builder, {
50+
tileMatrixSets,
51+
...tiledConfig,
52+
});
4453
this.isPlanarLayer = true;
4554
this.extent = extent;
46-
this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 0 : this.minSubdivisionLevel;
47-
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 5 : this.maxSubdivisionLevel;
55+
56+
this.minSubdivisionLevel = minSubdivisionLevel;
57+
this.maxSubdivisionLevel = maxSubdivisionLevel;
4858
}
4959
}
5060

src/Layer/C3DTilesLayer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ function object3DHasFeature(object3d) {
5454
return object3d.geometry && object3d.geometry.attributes._BATCHID;
5555
}
5656

57+
/**
58+
* @extends GeometryLayer
59+
*/
5760
class C3DTilesLayer extends GeometryLayer {
5861
#fillColorMaterialsBuffer;
5962
/**
6063
* @deprecated Deprecated 3D Tiles layer. Use {@link OGC3DTilesLayer} instead.
61-
* @extends GeometryLayer
6264
*
6365
* @example
6466
* // Create a new 3d-tiles layer from a web server
@@ -86,7 +88,7 @@ class C3DTilesLayer extends GeometryLayer {
8688
* {@link View} that already has a layer going by that id.
8789
* @param {object} config configuration, all elements in it
8890
* will be merged as is in the layer.
89-
* @param {C3TilesSource} config.source The source of 3d Tiles.
91+
* @param {C3DTilesSource} config.source The source of 3d Tiles.
9092
*
9193
* name.
9294
* @param {Number} [config.sseThreshold=16] The [Screen Space Error](https://github.com/CesiumGS/3d-tiles/blob/main/specification/README.md#geometric-error)
@@ -143,8 +145,8 @@ class C3DTilesLayer extends GeometryLayer {
143145
if (!exists) { console.warn("The points cloud size mode doesn't exist. Use 'VALUE' or 'ATTENUATED' instead."); } else { this.pntsSizeMode = config.pntsSizeMode; }
144146
}
145147

146-
/** @type {Style} */
147-
this.style = config.style || null;
148+
/** @type {Style | null} */
149+
this._style = config.style || null;
148150

149151
/** @type {Map<string, THREE.MeshStandardMaterial>} */
150152
this.#fillColorMaterialsBuffer = new Map();

src/Layer/ColorLayer.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ import { deprecatedColorLayerOptions } from 'Core/Deprecated/Undeprecator';
4444
* * `1`: used to amplify the transparency effect.
4545
* * `2`: unused.
4646
* * `3`: could be used by your own glsl code.
47+
*
48+
* @extends RasterLayer
4749
*/
4850
class ColorLayer extends RasterLayer {
4951
/**
5052
* A simple layer, usually managing a texture to display on a view. For example,
5153
* it can be an aerial view of the ground or a simple transparent layer with the
5254
* roads displayed.
5355
*
54-
* @extends Layer
55-
*
5656
* @param {string} id - The id of the layer, that should be unique. It is
5757
* not mandatory, but an error will be emitted if this layer is added a
5858
* {@link View} that already has a layer going by that id.
@@ -91,16 +91,45 @@ class ColorLayer extends RasterLayer {
9191
*/
9292
constructor(id, config = {}) {
9393
deprecatedColorLayerOptions(config);
94-
super(id, config);
94+
95+
const {
96+
effect_type = 0,
97+
effect_parameter = 1.0,
98+
transparent,
99+
...rasterConfig
100+
} = config;
101+
102+
super(id, rasterConfig);
103+
104+
/**
105+
* @type {boolean}
106+
* @readonly
107+
*/
95108
this.isColorLayer = true;
96-
this.defineLayerProperty('visible', true);
97-
this.defineLayerProperty('opacity', 1.0);
98-
this.defineLayerProperty('sequence', 0);
99-
this.transparent = config.transparent || (this.opacity < 1.0);
109+
110+
/**
111+
* @type {boolean}
112+
*/
113+
this.visible = true;
114+
this.defineLayerProperty('visible', this.visible);
115+
116+
/**
117+
* @type {number}
118+
*/
119+
this.opacity = 1.0;
120+
this.defineLayerProperty('opacity', this.opacity);
121+
122+
/**
123+
* @type {number}
124+
*/
125+
this.sequence = 0;
126+
this.defineLayerProperty('sequence', this.sequence);
127+
128+
this.transparent = transparent || (this.opacity < 1.0);
100129
this.noTextureParentOutsideLimit = config.source ? config.source.isFileSource : false;
101130

102-
this.effect_type = config.effect_type ?? 0;
103-
this.effect_parameter = config.effect_parameter ?? 1.0;
131+
this.effect_type = effect_type;
132+
this.effect_parameter = effect_parameter;
104133

105134
// Feature options
106135
this.buildExtent = true;

src/Layer/CopcLayer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class CopcLayer extends PointCloudLayer {
3030
*/
3131
constructor(id, config) {
3232
super(id, config);
33+
34+
/**
35+
* @type {boolean}
36+
* @readonly
37+
*/
3338
this.isCopcLayer = true;
3439

3540
const resolve = () => this;

0 commit comments

Comments
 (0)