Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move Layer folder, extract geometric layers from views #815

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/wfs.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
}

view.addLayer({
type: 'geometry',
name: 'lyon_tcl_bus',
update: itowns.FeatureProcessing.update,
convert: itowns.Feature2Mesh.convert({
Expand Down
8 changes: 8 additions & 0 deletions jsdoc-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
"src/Core/Geographic/Coordinates.js",
"src/Core/Layer/Layer.js",
"src/Core/Prefab/GlobeView.js",
"src/Core/Prefab/Globe/GlobeLayer.js",
"src/Core/Prefab/Panorama/PanoramaLayer.js",
"src/Core/Prefab/Planar/PlanarLayer.js",
"src/Core/Scheduler/Cache.js",
"src/Core/Scheduler/Scheduler.js",

"src/Layer/ColorLayer.js",
"src/Layer/ElevationLayer.js",
"src/Layer/GeometryLayer.js",
"src/Layer/TiledGeometryLayer.js",

"src/Parser/GeoJsonParser.js",
"src/Parser/GpxParser.js",
"src/Parser/VectorTileParser.js",
Expand Down
199 changes: 0 additions & 199 deletions src/Core/Layer/Layer.js

This file was deleted.

13 changes: 7 additions & 6 deletions src/Core/MainLoop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventDispatcher } from 'three';
import { GeometryLayer, Layer } from './Layer/Layer';
import Layer from '../Layer/Layer';
import Cache from '../Core/Scheduler/Cache';

export const RENDERING_PAUSED = 0;
Expand Down Expand Up @@ -77,7 +77,7 @@ function updateElements(context, geometryLayer, elements) {
}
}
// update attached layers
for (const attachedLayer of geometryLayer._attachedLayers) {
for (const attachedLayer of geometryLayer.attachedLayers) {
if (attachedLayer.ready) {
attachedLayer.update(context, attachedLayer, sub.element, sub.parent);
}
Expand All @@ -90,7 +90,7 @@ function updateElements(context, geometryLayer, elements) {
Must be a THREE.Object and have a THREE.Material`);
}
// update attached layers
for (const attachedLayer of geometryLayer._attachedLayers) {
for (const attachedLayer of geometryLayer.attachedLayers) {
if (attachedLayer.ready) {
attachedLayer.update(context, attachedLayer, sub.elements[i], sub.parent);
}
Expand Down Expand Up @@ -127,9 +127,10 @@ MainLoop.prototype._update = function _update(view, updateSources, dt) {
updateSources.forEach((src) => {
const layer = src.layer || src;
if (layer instanceof Layer) {
if (!(layer instanceof GeometryLayer)) {
const parentLayer = view.getParentLayer(layer);
if (parentLayer) {
// add the parent layer to update sources
updateSources.add(view.getParentLayer(layer));
updateSources.add(parentLayer);
}
}
});
Expand All @@ -143,7 +144,7 @@ MainLoop.prototype._update = function _update(view, updateSources, dt) {
const srcs = filterChangeSources(updateSources, geometryLayer);
if (srcs.size > 0) {
// `preUpdate` returns an array of elements to update
const elementsToUpdate = geometryLayer.preUpdate(context, geometryLayer, srcs);
const elementsToUpdate = geometryLayer.preUpdate(context, srcs);
// `update` is called in `updateElements`.
updateElements(context, geometryLayer, elementsToUpdate);
// `postUpdate` is called when this geom layer update process is finished
Expand Down
66 changes: 66 additions & 0 deletions src/Core/Prefab/Globe/GlobeLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as THREE from 'three';

import TiledGeometryLayer from '../../../Layer/TiledGeometryLayer';

import { globeCulling, preGlobeUpdate, globeSubdivisionControl, globeSchemeTileWMTS, globeSchemeTile1 } from '../../../Process/GlobeTileProcessing';
import BuilderEllipsoidTile from './BuilderEllipsoidTile';

class GlobeLayer extends TiledGeometryLayer {
/**
* A {@link TiledGeometryLayer} to use with a {@link GlobeView}. It has
* specific method for updating and subdivising its grid.
*
* @constructor
* @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
* contain the geometry of the TiledGeometryLayer. It is usually a
* <code>THREE.Group</code>, but it can be anything inheriting from a
* <code>THREE.Object3d</code>.
* @param {Object} [config] - Optional configuration, all elements in it
* will be merged as is in the layer. For example, if the configuration
* contains three elements <code>name, protocol, extent</code>, these
* elements will be available using <code>layer.name</code> or something
* else depending on the property name.
* @param {number} [config.maxSubdivisionLevel=18] - Maximum subdivision
* level for this tiled layer.
* @param {number} [config.sseSubdivisionThreshold=1] - Threshold level for
* the SSE.
* @param {number} [config.maxDeltaElevationLevel=4] - Maximum delta between
* two elevations tile.
*
* @throws {Error} <code>object3d</code> must be a valid
* <code>THREE.Object3d</code>.
*/
constructor(id, object3d, config = {}) {
super(id, object3d || new THREE.Group(), config);

this.options.defaultPickingRadius = 5;

// Configure tiles
this.schemeTile = globeSchemeTileWMTS(globeSchemeTile1);
this.extent = this.schemeTile[0].clone();
for (let i = 1; i < this.schemeTile.length; i++) {
this.extent.union(this.schemeTile[i]);
}

this.culling = globeCulling(2);
this.subdivision = globeSubdivisionControl(2,
config.maxSubdivisionLevel || 18,
config.sseSubdivisionThreshold || 1.0,
config.maxDeltaElevationLevel || 4);

this.builder = new BuilderEllipsoidTile();
}

preUpdate(context, changeSources) {
preGlobeUpdate(context, this);

return super.preUpdate(context, changeSources);
}
}

export default GlobeLayer;
Loading