Skip to content

Commit

Permalink
refactor(PlanarLayer): homogeneisation with GlobeLayer in args
Browse files Browse the repository at this point in the history
to sasu
  • Loading branch information
ftoromanoff committed Jul 5, 2024
1 parent c609e23 commit 74fa9ab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/view_multi_25d.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
obj.updateMatrixWorld(true);

const tileLayer = new itowns.PlanarLayer('planar' + wms.name + index,
extent, obj, { disableSkirt: true });
obj, { disableSkirt: true, extent });

view.addLayer(tileLayer);

Expand Down
12 changes: 10 additions & 2 deletions src/Core/Prefab/Planar/PlanarLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class PlanarLayer 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 {Extent} extent - The extent to define the layer within.
* @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`.
Expand All @@ -30,14 +29,23 @@ class PlanarLayer extends TiledGeometryLayer {
* contains three elements `name, protocol, extent`, these elements will be
* available using `layer.name` or something else depending on the property
* name.
* @param {Extent} config.extent - The extent to define the layer within.
* @param {number} [config.maxSubdivisionLevel=5] - Maximum subdivision
* level for this tiled layer.
* @param {number} [config.maxDeltaElevationLevel=4] - Maximum delta between
* two elevations tile.
*
* @throws {Error} `object3d` must be a valid `THREE.Object3d`.
*/
constructor(id, extent, object3d, config = {}) {
constructor(id, object3d, config = {}) {
if (arguments.length > 3 || object3d.isExtent) {
console.warn("Deprecated: change in arguments, 'extent' should be set in config");
// eslint-disable-next-line prefer-rest-params
const [, ext,, conf = {}] = arguments;
conf.extent = ext;
config = conf;
}
const extent = config.extent;
const tms = CRS.formatToTms(extent.crs);

const scheme = schemeTiles.get(tms);
Expand Down
11 changes: 7 additions & 4 deletions src/Core/Prefab/PlanarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import View from 'Core/View';
import CameraUtils from 'Utils/CameraUtils';

import PlanarControls from 'Controls/PlanarControls';
import PlanarLayer from './Planar/PlanarLayer';
import PlanarLayer from 'Core/Prefab/Planar/PlanarLayer';
import { ellipsoidSizes } from 'Core/Math/Ellipsoid';

class PlanarView extends View {
/**
Expand Down Expand Up @@ -43,7 +44,7 @@ class PlanarView extends View {
super(extent.crs, viewerDiv, options);
this.isPlanarView = true;

const tileLayer = new PlanarLayer('planar', extent, options.object3d, options);
const tileLayer = new PlanarLayer('planar', options.object3d, options);
this.mainLoop.gfxEngine.label2dRenderer.infoTileLayer = tileLayer.info;

this.addLayer(tileLayer);
Expand All @@ -52,8 +53,10 @@ class PlanarView extends View {
// Configure camera
const dim = extent.planarDimensions();
const max = Math.max(dim.x, dim.y);
this.camera3D.near = 0.1;
this.camera3D.far = this.camera3D.isOrthographicCamera ? 2000 : 2 * max;
// this.camera3D.near = 0.1;
// this.camera3D.far = this.camera3D.isOrthographicCamera ? 2000 : 2 * max;
this.camera3D.near = Math.max(15.0, 0.000002352 * ellipsoidSizes.x);
this.camera3D.far = ellipsoidSizes.x * 10;
this.camera3D.updateProjectionMatrix();

const placement = options.placement || {};
Expand Down
2 changes: 1 addition & 1 deletion test/unit/dataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Provide in Sources', function () {
stubFetcherTexture = sinon.stub(Fetcher, 'texture')
.callsFake(() => Promise.resolve(new THREE.Texture()));

planarlayer = new PlanarLayer('globe', globalExtent, new THREE.Group());
planarlayer = new PlanarLayer('globe', new THREE.Group(), { extent: globalExtent });
colorlayer = new ColorLayer('color', { crs: 'EPSG:3857', source: false });
elevationlayer = new ElevationLayer('elevation', { crs: 'EPSG:3857', source: false });

Expand Down
2 changes: 1 addition & 1 deletion test/unit/tilemesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('TileMesh', function () {
const globalExtent = globalExtentTMS.get('EPSG:3857');
// const view = new PlanarView(viewerDiv, globalExtent, { maxSubdivisionLevel: 20 });

const planarlayer = new PlanarLayer('globe', globalExtent, new THREE.Group());
const planarlayer = new PlanarLayer('globe', new THREE.Group(), { extent: globalExtent });

// Mock scheduler
const context = {
Expand Down

0 comments on commit 74fa9ab

Please sign in to comment.