Skip to content
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
32 changes: 19 additions & 13 deletions packages/Main/src/Core/Scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,25 @@ function _instanciateQueue() {
execute(cmd, provider) {
this.counters.pending--;
this.counters.executing++;
return provider.executeCommand(cmd).then((result) => {
this.counters.executing--;
cmd.resolve(result);
// only count successul commands
this.counters.executed++;
}, (err) => {
this.counters.executing--;
cmd.reject(err);
this.counters.failed++;
if (__DEBUG__ && this.counters.failed < 3) {
console.error(err);
}
});
return provider.executeCommand(cmd)
.then((result) => {
this.counters.executing--;
cmd.resolve(result);
// only count successul commands
this.counters.executed++;
})
.catch((err) => {
this.counters.executing--;
cmd.reject(err);
this.counters.failed++;
if (__DEBUG__ && this.counters.failed < 3) {
if (err instanceof AggregateError) {
console.error(err, ...err.errors);
} else {
console.error(err);
}
}
});
},
};
}
Expand Down
5 changes: 3 additions & 2 deletions packages/Main/src/Layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ class Layer extends THREE.EventDispatcher {
let data = this.cache.get(key);
if (!data) {
data = this.source.loadData(from, this)
.then(feat => this.convert(feat, to), (err) => {
throw err;
.then(feat => this.convert(feat, to))
.catch((err) => {
this.source.handlingError(err);
});
this.cache.set(key, data);
}
Expand Down
19 changes: 16 additions & 3 deletions packages/Main/src/Parser/VectorTileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,36 @@ function readPBF(file, options) {
collection.position.set(vFeature0.extent * x + center, vFeature0.extent * y + center, 0).multiply(collection.scale);
collection.updateMatrixWorld();

let styleLayers = options.in.layers;
if (!styleLayers) {
styleLayers = {};
vtLayerNames.forEach((vtLayerName, i) => {
styleLayers[vtLayerName] = [{
id: vtLayerName,
order: i,
filterExpression: { filter: () => true },
}];
});
}

vtLayerNames.forEach((vtLayerName) => {
if (!options.in.layers[vtLayerName]) { return Promise.resolve(collection); }
if (!styleLayers[vtLayerName]) { return; }

const vectorTileLayer = vectorTile.layers[vtLayerName];

for (let i = vectorTileLayer.length - 1; i >= 0; i--) {
const vtFeature = vectorTileLayer.feature(i);
vtFeature.tileNumbers = { x, y: options.extent.row, z };

// Find layers where this vtFeature is used
const layers = options.in.layers[vtLayerName]
const layers = styleLayers[vtLayerName]
.filter(l => l.filterExpression.filter({ zoom: z }, vtFeature));

for (const layer of layers) {
const feature = collection.requestFeatureById(layer.id, vtFeature.type - 1);
feature.id = layer.id;
feature.order = layer.order;
feature.style = options.in.styles[feature.id];
feature.style = options.in.styles?.[feature.id];
vtFeatureToFeatureGeometry(vtFeature, feature);
}

Expand Down
32 changes: 18 additions & 14 deletions packages/Main/src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,24 @@ export function updateLayeredMaterialNodeImagery(context, layer, node, parent) {
node.layerUpdateState[layer.id].newTry();
const command = buildCommand(context.view, layer, extentsSource, extentsDestination, node);

return context.scheduler.execute(command).then(
(results) => {
// Does nothing if the layer has been removed while command was being or waiting to be executed
if (!node.layerUpdateState[layer.id]) {
return;
}
const textures = results.map((texture, index) => (texture != null ? texture :
{ isTexture: false, extent: extentsDestination[index] }));
// TODO: Handle error : result is undefined in provider. throw error
const pitchs = computePitchs(textures, extentsDestination);
nodeLayer.setTextures(textures, pitchs);
node.layerUpdateState[layer.id].success();
},
err => handlingError(err, node, layer, targetLevel, context.view));
return context.scheduler.execute(command)
.then(
(results) => {
// Does nothing if the layer has been removed while command was being or waiting to be executed
if (!node.layerUpdateState[layer.id]) {
return;
}
const textures = results.map((texture, index) => (texture != null ? texture :
{ isTexture: false, extent: extentsDestination[index] }));

// TODO: Handle error : result is undefined in provider. throw error
const pitchs = computePitchs(textures, extentsDestination);
nodeLayer.setTextures(textures, pitchs);
node.layerUpdateState[layer.id].success();
})
.catch((err) => {
handlingError(err, node, layer, targetLevel, context.view);
});
}

export function updateLayeredMaterialNodeElevation(context, layer, node, parent) {
Expand Down
4 changes: 3 additions & 1 deletion packages/Main/src/Provider/DataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default {
const anyFulfilledPromise = results.find(promise => promise.status === 'fulfilled');
if (!anyFulfilledPromise) {
// All promises failed -> reject
return Promise.reject(new Error('Failed to load any data'));

const err = new AggregateError(results.map(r => r.reason), 'Failed to load any data');
return Promise.reject(err);
}
return results.map(prom => (prom.value ? prom.value : null));
});
Expand Down
3 changes: 2 additions & 1 deletion packages/Main/src/Provider/Fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const textureLoader = new TextureLoader();

function checkResponse(response) {
if (!response.ok) {
const error = new Error(`Error loading ${response.url}: status ${response.status}`);
const error = new Error(response.url, { cause: `status ${response.status}` });
error.name = 'FetchError';
error.response = response;
throw error;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/Main/src/Renderer/LayeredMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function updateLayersUniformsForType<Type extends 'c' | 'e'>(
let count = 0;
let width = 0;
let height = 0;
let setSize = false;

// Determine total count of textures and dimensions
// (assuming all textures are same size)
Expand All @@ -125,7 +126,7 @@ function updateLayersUniformsForType<Type extends 'c' | 'e'>(
++i, ++count
) {
const texture = tile.textures[i];
if (!texture) { continue; }
if (!texture.isTexture) { continue; }

textureSetId += `${texture.id}.`;
uOffsetScales[count] = tile.offsetScales[i];
Expand All @@ -135,14 +136,13 @@ function updateLayersUniformsForType<Type extends 'c' | 'e'>(
if (!img || img.width <= 0 || img.height <= 0) {
console.error('Texture image not loaded or has zero dimensions');
uTextureCount.value = 0;
return;
} else if (count == 0) {
} else if (setSize === false) {
width = img.width;
height = img.height;
setSize = true;
} else if (width !== img.width || height !== img.height) {
console.error('Texture dimensions mismatch');
uTextureCount.value = 0;
return;
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/Main/src/Renderer/WebGLComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,23 @@ export function makeDataArrayRenderTarget(
// loop through each tile and its textures
// to render them into DataArrayTexture layers
let currentLayerIndex = 0;

let setTexture = false;

for (const tile of tiles) {
for (
let i = 0;
i < tile.textures.length && currentLayerIndex < max;
++i, ++currentLayerIndex
) {
const texture = tile.textures[i];
if (!texture) { continue; }
if (!texture.isTexture) { continue; }

// Set the current source 2D texture on the quad's material
(material as THREE.ShaderMaterial).uniforms.sourceTexture.value = texture;

if (!currentLayerIndex) {
// Set parameters from the first found texture
if (!setTexture) {
// Set parameters from the first valid texture
arrayTexture.magFilter = texture.magFilter;
arrayTexture.minFilter = texture.minFilter;
arrayTexture.wrapS = texture.wrapS;
Expand All @@ -99,6 +102,7 @@ export function makeDataArrayRenderTarget(
arrayTexture.internalFormat = texture.internalFormat;
arrayTexture.anisotropy = texture.anisotropy;
arrayTexture.premultiplyAlpha = texture.premultiplyAlpha;
setTexture = true;
}

// render this source texture into the current layer
Expand Down
1 change: 1 addition & 0 deletions packages/Main/src/Source/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Source {
}

handlingError(err) {
if (Error.isError(err)) { throw err; }
throw new Error(err);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/Main/test/unit/layeredmaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ describe('material state vs layer state', function () {

layer.visible = false;
node.material.layersNeedUpdate = true;
node.onBeforeRender();
node.onBeforeRender(renderer);
assert.equal(material.uniforms.colorLayers.value[0].id, undefined);

layer.visible = true;
node.material.layersNeedUpdate = true;
node.onBeforeRender();
node.onBeforeRender(renderer);
assert.equal(material.uniforms.colorLayers.value[0].id, layer.id);
assert.equal(material.uniforms.colorLayers.value[0].opacity, layer.opacity);
});
Expand Down
Loading