Skip to content

Commit

Permalink
refactor(VectorTile): Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff authored and mgermerie committed Aug 22, 2023
1 parent c3bc003 commit 284c46b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
34 changes: 17 additions & 17 deletions examples/vector_tile_3d_mesh.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,20 @@
// a json file.
function addElevationLayerFromConfig(config) {
config.source = new itowns.WMTSSource(config.source);
view.addLayer(
new itowns.ElevationLayer(config.id, config),
).then(debugMenu.addLayerGUI.bind(debugMenu));
view.addLayer(new itowns.ElevationLayer(config.id, config))
.then(debugMenu.addLayerGUI.bind(debugMenu));
}
itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);

// ---------- DISPLAY ORTHO-IMAGES : ----------

const ortho = itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
config.source = new itowns.WMTSSource(config.source);
var layer = new itowns.ColorLayer('Ortho', config);
return view.addLayer(layer);
});

// ---------- DISPLAY VECTOR TILED MAP DATA AS A ColorLayer : ----------

// Define the source of the ColorLayer data : a vector tiled map from the geoportail.
Expand Down Expand Up @@ -96,16 +103,8 @@
});

// Add the ColorLayer to the scene and to the debug menu.
view.addLayer(mapLayer).then(debugMenu.addLayerGUI.bind(debugMenu));


// ---------- DISPLAY ORTHO-IMAGES : ----------

const ortho = itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
config.source = new itowns.WMTSSource(config.source);
var layer = new itowns.ColorLayer('Ortho', config);
return view.addLayer(layer);
});
view.addLayer(mapLayer)
.then(debugMenu.addLayerGUI.bind(debugMenu));

// ---------- DISPLAY VECTOR TILED BUILDING DATA AS 3D MESHES : ----------

Expand Down Expand Up @@ -133,10 +132,11 @@
});

// Add the FeatureGeometryLayer to the scene and to the debug menu.
view.addLayer(buildingsLayer).then((layer) => {
const gui = debug.GeometryDebug.createGeometryDebugUI(debugMenu.gui, view, layer);
debug.GeometryDebug.addWireFrameCheckbox(gui, view, layer);
})
view.addLayer(buildingsLayer)
.then((layer) => {
const gui = debug.GeometryDebug.createGeometryDebugUI(debugMenu.gui, view, layer);
debug.GeometryDebug.addWireFrameCheckbox(gui, view, layer);
})



Expand Down
24 changes: 14 additions & 10 deletions src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ function featureToPolygon(feature, options) {
const indices = [];

const batchIds = options.batchId ? new Uint32Array(vertices.length / 3) : undefined;
const globals = { fill: true };
let featureId = 0;

const globals = { fill: true };

for (const geometry of feature.geometries) {
const start = geometry.indices[0].offset;
// To avoid integer overflow with index value (32 bits)
Expand Down Expand Up @@ -410,35 +411,38 @@ function area(contour, offset, count) {
const bottomColor = new THREE.Color();
function featureToExtrudedPolygon(feature, options) {
const ptsIn = feature.vertices;

const normals = feature.normals;

const z = options.GlobalZTrans - feature.altitude.min;
const vertices = new Float32Array(ptsIn.length * 2);
const totalVertices = ptsIn.length / 3;

const colors = new Uint8Array(ptsIn.length * 2);
const indices = [];
const totalVertices = ptsIn.length / 3;

const batchIds = options.batchId ? new Uint32Array(vertices.length / 3) : undefined;
let featureId = 0;

const z = options.GlobalZTrans - feature.altitude.min;
const globals = { fill: true };

for (const geometry of feature.geometries) {
const start = geometry.indices[0].offset;

const context = { globals, properties: () => geometry.properties };
const style = feature.style.drawingStylefromContext(context);

// topColor is assigned to the top of extruded polygon
const topColor = toColor(style.fill.color);
// bottomColor is assigned to the bottom of extruded polygon
bottomColor.copy(topColor);
bottomColor.multiplyScalar(0.5);

const start = geometry.indices[0].offset;
const lastIndice = geometry.indices.slice(-1)[0];
const end = lastIndice.offset + lastIndice.count;
const count = end - start;
const isClockWise = geometry.indices[0].ccw ?? (area(ptsIn, start, count) < 0);

// topColor is assigned to the top of extruded polygon
const topColor = toColor(style.fill.color);
// bottomColor is assigned to the bottom of extruded polygon
bottomColor.copy(topColor);
bottomColor.multiplyScalar(0.5);

coordinatesToVertices(ptsIn, normals, vertices, z, start, count);
fillColorArray(colors, count, bottomColor, start);

Expand Down
3 changes: 1 addition & 2 deletions src/Parser/VectorTileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ function readPBF(file, options) {
feature.id = layer.id;
feature.order = layer.order;
feature.style = options.in.styles[feature.id];
feature.hasRawElevationData = false;
vtFeatureToFeatureGeometry(vtFeature, feature);
} else if (!collection.features.find(f => f.id === layer.id)) {
feature = collection.newFeatureByReference(feature);
Expand Down Expand Up @@ -175,7 +174,7 @@ export default {
* @param {InformationsData} options.in - Object containing all styles,
* layers and informations data, see {@link InformationsData}.
*
* @param {Object} options.in.Styles - Object containing subobject with
* @param {Object} options.in.styles - Object containing subobject with
* informations on a specific style layer. Styles available is by `layer.id` and by zoom.
*
* @param {Object} options.in.layers - Object containing subobject with
Expand Down
2 changes: 2 additions & 0 deletions src/Process/FeatureProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default {
const zoomDest = extentsDestination[0].zoom;

// check if it's tile level is equal to display level layer.
// TO DO updata at all level asked
// if ((zoomDest < layer.zoom.min && zoomDest > layer.zoom.max) ||
if (zoomDest != layer.zoom.min ||
// check if there's data in extent tile.
!this.source.extentInsideLimit(node.extent, zoomDest) ||
Expand Down

0 comments on commit 284c46b

Please sign in to comment.