From 0e9b736aa707642de91a615b03fd509dfd4251fa Mon Sep 17 00:00:00 2001 From: Fouad Valadbeigi Date: Tue, 24 Jan 2023 15:57:43 +0100 Subject: [PATCH 1/2] remove redundant call to prerender from old code, some review fixes --- src/geo/lng_lat.js | 3 +-- src/geo/projection/globe_util.js | 4 ++-- src/render/draw_custom.js | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/geo/lng_lat.js b/src/geo/lng_lat.js index ab91ecd8d94..4ded4ae0f4f 100644 --- a/src/geo/lng_lat.js +++ b/src/geo/lng_lat.js @@ -130,8 +130,7 @@ class LngLat { toEcef(altitude: number): [number, number, number] { const altInEcef = globeMetersToEcef(altitude); const radius = GLOBE_RADIUS + altInEcef; - const ecef = latLngToECEF(this.lat, this.lng, radius); - return [ecef[0], ecef[1], ecef[2]]; + return latLngToECEF(this.lat, this.lng, radius); } /** diff --git a/src/geo/projection/globe_util.js b/src/geo/projection/globe_util.js index 406e8584151..8bccd25d49d 100644 --- a/src/geo/projection/globe_util.js +++ b/src/geo/projection/globe_util.js @@ -16,7 +16,7 @@ import {members as globeLayoutAttributes} from '../../terrain/globe_attributes.j import posAttributes from '../../data/pos_attributes.js'; import {TriangleIndexArray, GlobeVertexArray, LineIndexArray, PosArray} from '../../data/array_types.js'; import {Aabb, Ray} from '../../util/primitives.js'; -import LngLat from '../lng_lat.js'; +import LngLat, {earthRadius} from '../lng_lat.js'; import LngLatBounds from '../lng_lat_bounds.js'; import type Painter from '../../render/painter.js'; @@ -68,7 +68,7 @@ const GLOBE_LOW_ZOOM_TILE_AABBS = [ ]; export function globeMetersToEcef(d: number): number { - return d * mercatorZfromAltitude(1, 0.0) * 2.0 * GLOBE_RADIUS * Math.PI; + return d * GLOBE_RADIUS / earthRadius; } export function globePointCoordinate(tr: Transform, x: number, y: number, clampToHorizon: boolean = true): ?MercatorCoordinate { diff --git a/src/render/draw_custom.js b/src/render/draw_custom.js index 96dd4e6bde3..9b13df75beb 100644 --- a/src/render/draw_custom.js +++ b/src/render/draw_custom.js @@ -32,7 +32,6 @@ function drawCustom(painter: Painter, sourceCache: SourceCache, layer: CustomSty painter.setCustomLayerDefaults(); context.setColorMode(painter.colorModeForRenderPass()); - prerender.call(implementation, context.gl, painter.transform.customLayerMatrix()); if (painter.transform.projection.name === "globe") { prerender.call(implementation, context.gl, painter.transform.customLayerMatrix(), painter.transform.getProjection(), painter.transform.globeToMercatorMatrix(), globeToMercatorTransition(painter.transform.zoom)); } else { From 7a28a008982e0e0ca90836184c7aa5dc6807b60c Mon Sep 17 00:00:00 2001 From: Fouad Valadbeigi Date: Tue, 24 Jan 2023 18:18:34 +0100 Subject: [PATCH 2/2] avoid reallocation use cast --- src/geo/lng_lat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geo/lng_lat.js b/src/geo/lng_lat.js index 4ded4ae0f4f..0be5b59c4e8 100644 --- a/src/geo/lng_lat.js +++ b/src/geo/lng_lat.js @@ -130,7 +130,7 @@ class LngLat { toEcef(altitude: number): [number, number, number] { const altInEcef = globeMetersToEcef(altitude); const radius = GLOBE_RADIUS + altInEcef; - return latLngToECEF(this.lat, this.lng, radius); + return (latLngToECEF(this.lat, this.lng, radius): any); } /**