Skip to content

Commit

Permalink
refactor(Layer): remove Object.assign of config
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Nov 27, 2024
1 parent 83eb0d9 commit e3e92aa
Show file tree
Hide file tree
Showing 27 changed files with 504 additions and 192 deletions.
4 changes: 3 additions & 1 deletion examples/layers/JSONLayers/GeoidMNT.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"updateStrategy": {
"type": 0
},
"zmin": -12000,
"clampValues": {
"min": -12000
},
"source": {
"url": "https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/geoid/geoid/bil/%TILEMATRIX/geoid_%COL_%ROW.bil",
"format": "image/x-bil;bits=32",
Expand Down
1 change: 0 additions & 1 deletion examples/source_file_geojson_3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
crs: 'EPSG:4326',
format: 'application/json',
}),
transparent: true,
opacity: 0.7,
zoom: { min: 10 },
style: {
Expand Down
7 changes: 0 additions & 7 deletions examples/source_stream_wfs_raster.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@
itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);

function isValidData(data) {
if(data.features[0].geometries.length < 1000) {
return data;
}
}

var wfsBuildingSource = new itowns.WFSSource({
url: 'https://data.geopf.fr/wfs/ows?',
version: '2.0.0',
Expand Down Expand Up @@ -102,7 +96,6 @@
width: 2.0,
},
},
isValidData: isValidData,
source: wfsBuildingSource,
zoom: { max: 20, min: 13 },
});
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/Feature2Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default {

c.width = sizeTexture;
c.height = sizeTexture;
const ctx = c.getContext('2d');
const ctx = c.getContext('2d', { willReadFrequently: true });
if (backgroundColor) {
ctx.fillStyle = backgroundColor.getStyle();
ctx.fillRect(0, 0, sizeTexture, sizeTexture);
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Prefab/Globe/Atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const spaceColor = new THREE.Color(0x030508);
const limitAlti = 600000;
const mfogDistance = ellipsoidSizes.x * 160.0;


/**
* @extends GeometryLayer
*/
class Atmosphere extends GeometryLayer {
/**
* It's layer to simulate Globe atmosphere.
Expand All @@ -39,8 +41,6 @@ class Atmosphere extends GeometryLayer {
* * [Atmosphere Shader From Space (Atmospheric scattering)](http://stainlessbeer.weebly.com/planets-9-atmospheric-scattering.html)
* * [Accurate Atmospheric Scattering (NVIDIA GPU Gems 2)](https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering).
*
* @extends GeometryLayer
*
* @param {string} id - The id of the layer Atmosphere.
* @param {Object} [options] - options layer.
* @param {number} [options.Kr] - `Kr` is the rayleigh scattering constant.
Expand Down
26 changes: 18 additions & 8 deletions src/Core/Prefab/Globe/GlobeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ const scaledHorizonCullingPoint = new THREE.Vector3();
* @property {boolean} isGlobeLayer - Used to checkout whether this layer is a
* GlobeLayer. Default is true. You should not change this, as it is used
* internally for optimisation.
*
* @extends TiledGeometryLayer
*/
class GlobeLayer extends TiledGeometryLayer {
/**
* A {@link TiledGeometryLayer} to use with a {@link GlobeView}. It has
* specific method for updating and subdivising its grid.
*
* @extends TiledGeometryLayer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
* {@link View} that already has a layer going by that id.
* @param {THREE.Object3d} [object3d=THREE.Group] - The object3d used to
* @param {THREE.Object3D} [object3d=THREE.Group] - The object3d used to
* contain the geometry of the TiledGeometryLayer. It is usually a
* `THREE.Group`, but it can be anything inheriting from a `THREE.Object3d`.
* @param {Object} [config] - Optional configuration, all elements in it
Expand All @@ -46,24 +46,34 @@ class GlobeLayer extends TiledGeometryLayer {
* @throws {Error} `object3d` must be a valid `THREE.Object3d`.
*/
constructor(id, object3d, config = {}) {
const {
minSubdivisionLevel = 2,
maxSubdivisionLevel = 19,
...tiledConfig
} = config;

// Configure tiles
const scheme = schemeTiles.get('EPSG:4326');
const schemeTile = globalExtentTMS.get('EPSG:4326').subdivisionByScheme(scheme);

// Supported tile matrix set for color/elevation layer
config.tileMatrixSets = [
const tileMatrixSets = [
'EPSG:4326',
'EPSG:3857',
];
const uvCount = config.tileMatrixSets.length;
const uvCount = tileMatrixSets.length;
const builder = new BuilderEllipsoidTile({ crs: 'EPSG:4978', uvCount });

super(id, object3d || new THREE.Group(), schemeTile, builder, config);
super(id, object3d || new THREE.Group(), schemeTile, builder, {
tileMatrixSets,
...tiledConfig,
});

this.isGlobeLayer = true;
this.options.defaultPickingRadius = 5;
this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 2 : this.minSubdivisionLevel;
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 19 : this.maxSubdivisionLevel;
this.minSubdivisionLevel = minSubdivisionLevel;
this.maxSubdivisionLevel = maxSubdivisionLevel;

this.extent = this.schemeTile[0].clone();

for (let i = 1; i < this.schemeTile.length; i++) {
Expand Down
22 changes: 16 additions & 6 deletions src/Core/Prefab/Planar/PlanarLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import PlanarTileBuilder from './PlanarTileBuilder';
* @property {boolean} isPlanarLayer - Used to checkout whether this layer is a
* PlanarLayer. Default is true. You should not change this, as it is used
* internally for optimisation.
* @extends TiledGeometryLayer
*/
class PlanarLayer extends TiledGeometryLayer {
/**
* A {@link TiledGeometryLayer} to use with a {@link PlanarView}. It has
* specific method for updating and subdivising its grid.
*
* @extends TiledGeometryLayer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
* {@link View} that already has a layer going by that id.
Expand All @@ -34,17 +33,28 @@ class PlanarLayer extends TiledGeometryLayer {
* @throws {Error} `object3d` must be a valid `THREE.Object3d`.
*/
constructor(id, extent, object3d, config = {}) {
const {
minSubdivisionLevel = 0,
maxSubdivisionLevel = 5,
...tiledConfig
} = config;

const tileMatrixSets = [extent.crs];
if (!globalExtentTMS.get(extent.crs)) {
// Add new global extent for this new crs projection.
globalExtentTMS.set(extent.crs, extent);
}
config.tileMatrixSets = tileMatrixSets;
super(id, object3d || new THREE.Group(), [extent], new PlanarTileBuilder({ crs: extent.crs }), config);

const builder = new PlanarTileBuilder({ crs: extent.crs });
super(id, object3d || new THREE.Group(), [extent], builder, {
tileMatrixSets,
...tiledConfig,
});
this.isPlanarLayer = true;
this.extent = extent;
this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 0 : this.minSubdivisionLevel;
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 5 : this.maxSubdivisionLevel;

this.minSubdivisionLevel = minSubdivisionLevel;
this.maxSubdivisionLevel = maxSubdivisionLevel;
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Layer/C3DTilesLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ function object3DHasFeature(object3d) {
return object3d.geometry && object3d.geometry.attributes._BATCHID;
}

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

/** @type {Style} */
this.style = config.style || null;
/** @type {Style | null} */
this._style = config.style || null;

/** @type {Map<string, THREE.MeshStandardMaterial>} */
this.#fillColorMaterialsBuffer = new Map();
Expand Down
47 changes: 38 additions & 9 deletions src/Layer/ColorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ import { deprecatedColorLayerOptions } from 'Core/Deprecated/Undeprecator';
* * `1`: used to amplify the transparency effect.
* * `2`: unused.
* * `3`: could be used by your own glsl code.
*
* @extends RasterLayer
*/
class ColorLayer extends RasterLayer {
/**
* A simple layer, usually managing a texture to display on a view. For example,
* it can be an aerial view of the ground or a simple transparent layer with the
* roads displayed.
*
* @extends Layer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
* {@link View} that already has a layer going by that id.
Expand Down Expand Up @@ -91,16 +91,45 @@ class ColorLayer extends RasterLayer {
*/
constructor(id, config = {}) {
deprecatedColorLayerOptions(config);
super(id, config);

const {
effect_type = 0,
effect_parameter = 1.0,
transparent,
...rasterConfig
} = config;

super(id, rasterConfig);

/**
* @type {boolean}
* @readonly
*/
this.isColorLayer = true;
this.defineLayerProperty('visible', true);
this.defineLayerProperty('opacity', 1.0);
this.defineLayerProperty('sequence', 0);
this.transparent = config.transparent || (this.opacity < 1.0);

/**
* @type {boolean}
*/
this.visible = true;
this.defineLayerProperty('visible', this.visible);

/**
* @type {number}
*/
this.opacity = 1.0;
this.defineLayerProperty('opacity', this.opacity);

/**
* @type {number}
*/
this.sequence = 0;
this.defineLayerProperty('sequence', this.sequence);

this.transparent = transparent || (this.opacity < 1.0);
this.noTextureParentOutsideLimit = config.source ? config.source.isFileSource : false;

this.effect_type = config.effect_type ?? 0;
this.effect_parameter = config.effect_parameter ?? 1.0;
this.effect_type = effect_type;
this.effect_parameter = effect_parameter;

// Feature options
this.buildExtent = true;
Expand Down
5 changes: 5 additions & 0 deletions src/Layer/CopcLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class CopcLayer extends PointCloudLayer {
*/
constructor(id, config) {
super(id, config);

/**
* @type {boolean}
* @readonly
*/
this.isCopcLayer = true;

const resolve = () => this;
Expand Down
52 changes: 45 additions & 7 deletions src/Layer/ElevationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import { RasterElevationTile } from 'Renderer/RasterTile';
* ```
* @property {number} colorTextureElevationMinZ - elevation minimum in `useColorTextureElevation` mode.
* @property {number} colorTextureElevationMaxZ - elevation maximum in `useColorTextureElevation` mode.
*
* @extends RasterLayer
*/
class ElevationLayer extends RasterLayer {
/**
* A simple layer, managing an elevation texture to add some reliefs on the
* plane or globe view for example.
*
* @extends Layer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
* {@link View} that already has a layer going by that id.
Expand Down Expand Up @@ -59,14 +59,52 @@ class ElevationLayer extends RasterLayer {
* view.addLayer(elevation);
*/
constructor(id, config = {}) {
super(id, config);
const {
scale = 1.0,
noDataValue,
clampValues,
useRgbaTextureElevation,
useColorTextureElevation,
colorTextureElevationMinZ,
colorTextureElevationMaxZ,
bias,
mode,
...rasterConfig
} = config;

super(id, rasterConfig);

/**
* @type {boolean}
* @readonly
*/
this.isElevationLayer = true;

this.noDataValue = noDataValue;

if (config.zmin || config.zmax) {
console.warn('Config using zmin and zmax are deprecated, use {clampValues: {min, max}} structure.');
}
this.zmin = config.clampValues?.min ?? config.zmin;
this.zmax = config.clampValues?.max ?? config.zmax;
this.isElevationLayer = true;
this.defineLayerProperty('scale', this.scale || 1.0);

/**
* @type {number | undefined}
*/
this.zmin = clampValues?.min ?? config.zmin;

/**
* @type {number | undefined}
*/
this.zmax = clampValues?.max ?? config.zmax;

this.defineLayerProperty('scale', scale);

this.useRgbaTextureElevation = useRgbaTextureElevation;
this.useColorTextureElevation = useColorTextureElevation;
this.colorTextureElevationMinZ = colorTextureElevationMinZ;
this.colorTextureElevationMaxZ = colorTextureElevationMaxZ;

this.bias = bias;
this.mode = mode;
}

/**
Expand Down
Loading

0 comments on commit e3e92aa

Please sign in to comment.