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

Process and Layer imagery/elevation #1068

Merged
merged 7 commits into from
Mar 13, 2019
2 changes: 1 addition & 1 deletion examples/layers/JSONLayers/Region.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"west": "-6880639.13669047",
"east": "6215707.87640867",
"south": "-2438398.99670629",
"north": "6637050.04559519"
"north": "8837050.04559519"
},
"transparent" : true,
"featureInfoMimeType" : "",
Expand Down
60 changes: 33 additions & 27 deletions src/Converter/convertToTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ import Cache from 'Core/Scheduler/Cache';

const dimensions = new THREE.Vector2();

function setTileFromTiledLayer(tile, tileLayer) {
tile.material.transparent = tileLayer.opacity < 1.0;
tile.material.opacity = tileLayer.opacity;

if (tileLayer.diffuse) {
tile.material.diffuse = tileLayer.diffuse;
}

if (__DEBUG__) {
tile.material.showOutline = tileLayer.showOutline || false;
tile.material.wireframe = tileLayer.wireframe || false;
}

if (tileLayer.isGlobeLayer) {
// Computes a point used for horizon culling.
// If the point is below the horizon,
// the tile is guaranteed to be below the horizon as well.
tile.horizonCullingPoint = tile.extent.center().as('EPSG:4978').xyz();
tile.extent.dimensions(dimensions).multiplyScalar(THREE.Math.DEG2RAD);

// alpha is maximum angle between two points of tile
const alpha = dimensions.length();
const h = Math.abs(1.0 / Math.cos(alpha * 0.5));
tile.horizonCullingPoint.setLength(h * tile.horizonCullingPoint.length());
}
}

export default {
convert(requester, extent, layer) {
const builder = layer.builder;
Expand Down Expand Up @@ -45,12 +72,14 @@ export default {
};
}

// build tile
// build tile mesh
geometry._count++;
const material = new LayeredMaterial(layer.materialOptions);
const tile = new TileMesh(geometry, material, layer, extent, level);
// TODO semble ne pas etre necessaire
tile.layers.set(layer.threejsLayer);

// Commented because layer.threejsLayer is undefined;
// Fix me: conflict with object3d added in view.scene;
// tile.layers.set(layer.threejsLayer);
zarov marked this conversation as resolved.
Show resolved Hide resolved

if (parent && parent.isTileMesh) {
// get parent extent transformation
Expand All @@ -62,9 +91,6 @@ export default {

tile.position.copy(position);
tile.quaternion.copy(quaternion);

tile.material.transparent = layer.opacity < 1.0;
tile.material.opacity = layer.opacity;
tile.visible = false;
tile.updateMatrix();

Expand All @@ -74,27 +100,7 @@ export default {

tile.add(tile.obb);

if (layer.diffuse) {
tile.material.diffuse = layer.diffuse;
}

if (__DEBUG__) {
tile.material.showOutline = layer.showOutline || false;
tile.material.wireframe = layer.wireframe || false;
}

if (layer.isGlobeLayer) {
// Computes a point used for horizon culling.
// If the point is below the horizon,
// the tile is guaranteed to be below the horizon as well.
tile.horizonCullingPoint = tile.extent.center().as('EPSG:4978').xyz();
tile.extent.dimensions(dimensions).multiplyScalar(THREE.Math.DEG2RAD);

// alpha is maximum angle between two points of tile
const alpha = dimensions.length();
const h = Math.abs(1.0 / Math.cos(alpha * 0.5));
tile.horizonCullingPoint.setLength(h * tile.horizonCullingPoint.length());
}
setTileFromTiledLayer(tile, layer);

return Promise.resolve(tile);
},
Expand Down
8 changes: 8 additions & 0 deletions src/Core/TileMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class TileMesh extends THREE.Mesh {
this.layer = layer;
this.extent = extent;
this.level = level;
// Set equivalent tiled extent zoom
// Is used to set zoom for each texture fetched with no tiled extent
// It's more simple to set zoom here instead of reverse ingeneer
// Removable with a table pixel/extent.size
if (!this.extent.zoom) {
this.extent.zoom = level;
}

this.material.objectId = this.id;

this.obb = this.geometry.OBB.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function _preprocessLayer(view, layer, provider, parentLayer) {
_syncGeometryLayerVisibility(layer, view);
// Find projection layer, this is projection destination
layer.projection = view.referenceCrs;
} else if (layer.source.tileMatrixSet === 'PM') {
} else if (layer.source.tileMatrixSet === 'PM' || layer.source.projection == 'EPSG:3857') {
layer.projection = 'EPSG:3857';
} else {
layer.projection = parentLayer.extent.crs();
Expand Down
2 changes: 1 addition & 1 deletion src/Layer/LayerUpdateState.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function LayerUpdateState() {
this.errorCount = 0;
}

LayerUpdateState.prototype.canTryUpdate = function canTryUpdate(timestamp) {
LayerUpdateState.prototype.canTryUpdate = function canTryUpdate(timestamp = Date.now()) {
switch (this.state) {
case UPDATE_STATE.IDLE: {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Layer/TiledGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class TiledGeometryLayer extends GeometryLayer {
// Prepare ColorLayer sequence order
// In this moment, there is only one color layers sequence, because they are attached to tileLayer.
// In future, the sequence must be returned by parent geometry layer.
context.ColorLayerSequenceOrder = ImageryLayers.getColorLayersIdOrderedBySequence(context.colorLayers);
this.colorLayersOrder = ImageryLayers.getColorLayersIdOrderedBySequence(context.colorLayers);

let commonAncestor;
for (const source of sources.values()) {
Expand Down
20 changes: 3 additions & 17 deletions src/Process/FeatureProcessing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as THREE from 'three';
import LayerUpdateState from 'Layer/LayerUpdateState';
import CancelledCommandException from 'Core/Scheduler/CancelledCommandException';
import ObjectRemovalHelper from 'Process/ObjectRemovalHelper';

import handlingError from 'Process/handlerNodeError';

const vector = new THREE.Vector3();
function applyOffset(obj, offset, quaternion, offsetAltitude = 0) {
Expand Down Expand Up @@ -72,9 +71,7 @@ export default {
node.layerUpdateState[layer.id] = new LayerUpdateState();
}

const ts = Date.now();

if (!node.layerUpdateState[layer.id].canTryUpdate(ts)) {
if (!node.layerUpdateState[layer.id].canTryUpdate()) {
return;
}

Expand Down Expand Up @@ -155,17 +152,6 @@ export default {
node.layerUpdateState[layer.id].failure(1, true);
}
},
(err) => {
if (err instanceof CancelledCommandException) {
node.layerUpdateState[layer.id].success();
} else if (err instanceof SyntaxError) {
node.layerUpdateState[layer.id].failure(0, true);
} else {
node.layerUpdateState[layer.id].failure(Date.now());
window.setTimeout(() => {
context.view.notifyChange(layer, false);
}, node.layerUpdateState[layer.id].secondsUntilNextTry() * 1000);
}
});
err => handlingError(err, node, layer, node.level, context.view));
},
};
Loading