Skip to content

Commit

Permalink
refactor(RasterTile): emit event when raster elevation changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Mar 15, 2023
1 parent 17aaa8b commit ea52ee1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Layer/ElevationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ElevationLayer extends RasterLayer {
updateBBox();

// listen elevation updating
rasterElevationNode.addEventListener('updatedElevation', updateBBox);
rasterElevationNode.addEventListener('rasterElevationLevelChanged', updateBBox);

// listen scaling elevation updating
this.addEventListener('scale-property-changed', updateBBox);
Expand Down
9 changes: 8 additions & 1 deletion src/Renderer/RasterTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,22 @@ export class RasterElevationTile extends RasterTile {
}

initFromParent(parent, extents) {
const currentLevel = this.level;
super.initFromParent(parent, extents);
this.updateMinMaxElevation();
if (currentLevel !== this.level) {
this.dispatchEvent({ type: 'rasterElevationLevelChanged', node: this });
}
}

setTextures(textures, offsetScales) {
const currentLevel = this.level;
this.replaceNoDataValueFromTexture(textures[0]);
super.setTextures(textures, offsetScales);
this.updateMinMaxElevation();
if (currentLevel !== this.level) {
this.dispatchEvent({ type: 'rasterElevationLevelChanged', node: this });
}
}

updateMinMaxElevation() {
Expand All @@ -182,7 +190,6 @@ export class RasterElevationTile extends RasterTile {
if (this.min != min || this.max != max) {
this.min = min;
this.max = max;
this.dispatchEvent({ type: 'updatedElevation', node: this });
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/tilemesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ describe('TileMesh', function () {
material.addLayer = () => {};
material.setSequenceElevation = () => {};

it('event updatedElevation RasterElevationTile sets TileMesh bounding box ', () => {
it('event rasterElevationLevelChanged RasterElevationTile sets TileMesh bounding box ', () => {
const tileMesh = new TileMesh(geom, material, planarlayer, extent.as('EPSG:3857'), 0);
const rasterNode = elevationLayer.setupRasterNode(tileMesh);
const min = 50;
const max = 500;
rasterNode.min = min;
rasterNode.max = max;
rasterNode.dispatchEvent({ type: 'updatedElevation', node: rasterNode });
rasterNode.dispatchEvent({ type: 'rasterElevationLevelChanged', node: rasterNode });
assert.equal(tileMesh.obb.z.min, min);
assert.equal(tileMesh.obb.z.max, max);

rasterNode.min = null;
rasterNode.max = null;
rasterNode.dispatchEvent({ type: 'updatedElevation', node: rasterNode });
rasterNode.dispatchEvent({ type: 'rasterElevationLevelChanged', node: rasterNode });
assert.equal(tileMesh.obb.z.min, min);
assert.equal(tileMesh.obb.z.max, max);
});
Expand Down

0 comments on commit ea52ee1

Please sign in to comment.