diff --git a/src/Converter/Feature2Mesh.js b/src/Converter/Feature2Mesh.js index f459bb29e5..3a9d07408e 100644 --- a/src/Converter/Feature2Mesh.js +++ b/src/Converter/Feature2Mesh.js @@ -10,6 +10,19 @@ import Coordinates from 'Core/Geographic/Coordinates'; const coord = new Coordinates('EPSG:4326', 0, 0, 0); +/** + * @class + * @classdesc FeatureContext is a class to store all informations + * about context to generate the style of each FeatureGeometry. + * + * @property {Coordinates} worldCoord @private Coordinates of the FeatureGeometry in world system. + * @property {Coordinates} localCoordinates @private Are the coordinates systeme origin local or global. + * @property {boolean} isProjected @private Are the coordinates already been projected. + * @property {FeatureGeometry} geometry @private + * @property {Object} globals + * @property {Object} collection + * @property {Coordinates} coordinates + */ class FeatureContext { #worldCoord = new Coordinates('EPSG:4326', 0, 0, 0); #localCoordinates = new Coordinates('EPSG:4326', 0, 0, 0); @@ -17,6 +30,9 @@ class FeatureContext { #geometry = {}; constructor() { + /** + * @constructor + */ this.globals = {}; } @@ -247,11 +263,10 @@ function featureToPoint(feature, options) { coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v)); const style = feature.style.applyContext(context); - const { base_altitude, color } = style.point; - coord.z = 0; + const { color } = style.point; // populate vertices - base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v); + base.copy(normal).multiplyScalar(context.collection.center.z).add(coord).toArray(vertices, v); toColor(color).multiplyScalar(255).toArray(colors, v); batchIds[j] = id; } @@ -319,12 +334,14 @@ function featureToLine(feature, options) { } coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v)); + const style = feature.style.applyContext(context); - const { base_altitude, color } = style.stroke; - coord.z = 0; + const { color } = style.stroke; // populate geometry buffers - base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v); + base.copy(normal).multiplyScalar(context.collection.center.z).add(coord); + base.toArray(vertices, v); + toColor(color).multiplyScalar(255).toArray(colors, v); batchIds[j] = id; } @@ -373,11 +390,10 @@ function featureToPolygon(feature, options) { coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, i)); const style = feature.style.applyContext(context); - const { base_altitude, color } = style.fill; - coord.z = 0; + const { color } = style.fill; // populate geometry buffers - base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, i); + base.copy(normal).multiplyScalar(context.collection.center.z).add(coord).toArray(vertices, i); batchIds[b] = id; toColor(color).multiplyScalar(255).toArray(colors, i); } @@ -463,7 +479,7 @@ function featureToExtrudedPolygon(feature, options) { coord.z = 0; // populate base geometry buffers - base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, i); + base.copy(normal).multiplyScalar(base_altitude - context.collection.center.z).add(coord).toArray(vertices, i); batchIds[b] = id; // populate top geometry buffers diff --git a/src/Core/Geographic/Coordinates.js b/src/Core/Geographic/Coordinates.js index aea1e0cd58..08606c7a29 100644 --- a/src/Core/Geographic/Coordinates.js +++ b/src/Core/Geographic/Coordinates.js @@ -63,7 +63,7 @@ class Coordinates { * @example * itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); * You can find most projections and their proj4 code at [epsg.io]{@link https://epsg.io/} - * @param {number|Array|Coordinates|THREE.Vector3} [v0=0] - + * @param {number|number[]|Coordinates|THREE.Vector3} [v0=0] - * x or longitude value, or a more complex one: it can be an array of three * numbers, being x/lon, x/lat, z/alt, or it can be `THREE.Vector3`. It can * also simply be a Coordinates. @@ -98,7 +98,7 @@ class Coordinates { /** * Sets the Coordinate Reference System. - * @param {String} crs Coordinate Reference System (e.g. 'EPSG:4978') + * @param {string} crs Coordinate Reference System (e.g. 'EPSG:4978') */ setCrs(crs) { CRS.isValid(crs); @@ -107,7 +107,6 @@ class Coordinates { /** * Set the values of this Coordinates. - * * @param {number} [v0=0] - x or longitude value. * @param {number} [v1=0] - y or latitude value. * @param {number} [v2=0] - z or altitude value. @@ -125,8 +124,7 @@ class Coordinates { /** * Set the values of this Coordinates from an array. - * - * @param {Array} array - An array of number to assign to the + * @param {number[]} array - An array of number to assign to the * Coordinates. * @param {number} [offset] - Optional offset into the array. * @@ -139,7 +137,6 @@ class Coordinates { /** * Set the values of this Coordinates from a `THREE.Vector3` or an `Object` * having `x/y/z` properties, like a `Coordinates`. - * * @param {THREE.Vector3|Coordinates} v0 - The object to read the values * from. * @@ -162,7 +159,6 @@ class Coordinates { /** * Copies the values of the passed Coordinates to this one. The CRS is * however not copied. - * * @param {Coordinates} src - The source to copy from. * * @return {Coordinates} This Coordinates. @@ -206,7 +202,6 @@ class Coordinates { /** * Return this Coordinates values into a `THREE.Vector3`. - * * @param {THREE.Vector3} [target] - The target to put the values in. If not * specified, a new vector will be created. * @@ -218,13 +213,11 @@ class Coordinates { /** * Copy values coordinates to array - * * @param {number[]} array - array to store this vector to. If this is not * provided a new array will be created. * @param {number} [offset=0] - optional offset into the array. * - * @return {number[]} Returns an array [x, y, z], or copies x, y and z into - * the provided array. + * @return {number[]} Returns an array [x, y, z], or copies x, y and z into the provided array. */ toArray(array = [], offset = 0) { return THREE.Vector3.prototype.toArray.call(this, array, offset); @@ -233,10 +226,9 @@ class Coordinates { /** * Calculate planar distance between this coordinates and `coord`. * Planar distance is the straight-line euclidean distance calculated in a 2D cartesian coordinate system. - * * @param {Coordinates} coord The coordinate - * @return {number} planar distance * + * @return {number} planar distance */ planarDistanceTo(coord) { this.toVector3(v0).setZ(0); @@ -248,12 +240,10 @@ class Coordinates { * Calculate geodetic distance between this coordinates and `coord`. * **Geodetic distance** is calculated in an ellispoid space as the shortest distance * across the curved surface of the world. - * * => As the crow flies/ Orthodromy - * * @param {Coordinates} coord The coordinate - * @return {number} geodetic distance * + * @return {number} geodetic distance */ geodeticDistanceTo(coord) { this.as('EPSG:4326', coord0); @@ -263,10 +253,9 @@ class Coordinates { /** * Calculate earth euclidean distance between this coordinates and `coord`. - * * @param {Coordinates} coord The coordinate - * @return {number} earth euclidean distance * + * @return {number} earth euclidean distance */ spatialEuclideanDistanceTo(coord) { this.as('EPSG:4978', coord0).toVector3(v0); @@ -276,8 +265,8 @@ class Coordinates { /** * Multiplies this `coordinates` (with an implicit 1 in the 4th dimension) and `mat`. - * * @param {THREE.Matrix4} mat The matrix. + * * @return {Coordinates} return this object. */ applyMatrix4(mat) {