Repository navigation
feat(core): apply local meter scales in custom projections - #10745
Conversation
|
8039c42 to
1a80405
Compare
1a80405 to
be5c334
Compare
be5c334 to
db51ab8
Compare
|
Tested this stack (head Cause: Measurement. Map meters per ground meter is
On the UTM central meridian PROJ gives exactly k0 = 0.9996 at every latitude. This stack gives 0.99290 (north, equator) and 1.00274 (east, 75°N). The same estimate fills the 64×64 size-scale texture ( Why the scale-accuracy test passes: The fix depends on the CRS's figure of the Earth. Checked locally by patching
So a single constant cannot be right for all of them. The estimator needs the target CRS's semi-major axis and eccentricity: /** Ground meters per degree (east, north) on an ellipsoid; e2 = 0 for a sphere. */
function metersPerDegree(latitude: number, a: number, e2: number): [east: number, north: number] {
const lat = (Math.min(Math.max(latitude, -89.9), 89.9) * Math.PI) / 180;
const w = 1 - e2 * Math.sin(lat) ** 2;
const east = (a * Math.cos(lat)) / Math.sqrt(w);
const north = (a * (1 - e2)) / (w * Math.sqrt(w));
return [(east * Math.PI) / 180, (north * Math.PI) / 180];
}A proj4 converter does not expose its ellipsoid.
EPSG codes need a lookup in any case: EPSG:3857 and EPSG:32618 are both "WGS 84" by name but sit on different figures. Happy to open a PR against this branch once you pick a direction. |
d874f2d to
3fdce2e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3fdce2e. Configure here.
|
Thanks @athomct for the investigation. I’ve updated the default estimator to use a hardcoded WGS84 ellipsoid for ground distances, independently of the target projection’s coordinate formulas. Applications using a different Earth model can override this with getDistanceScale. Also introduced independent reference in the unit test and added the UTM and NAD83 Albers cases you reported. |
299d5e4 to
7ca311c
Compare
ibgreen
left a comment
There was a problem hiding this comment.
Thanks Xiaoji, local meter sizing is a useful completion of this first custom-projection stack. Sampling distortion at each object, using an area-equivalent scalar to preserve marker shape, and keeping position altitude on the fixed map-meter scale give the API a clear coordinate contract. Anchor-aware getDistanceScales() also addresses the earlier camera-dependent aggregation sizing concern.
Approving the overall direction, with four remaining issues recorded inline: distinguishing failed scale measurements from valid samples, preserving positive sizing when Taylor reconstruction fails, handling feet-based source units, and releasing resources for removed views. Please address these as the implementation progresses.
The numerical estimator would fit naturally in math.gl: source-unit conversion, the ground-distance metric, Jacobian and area-equivalent scale calculation, and explicit validity handling. The GPU encoding, shader bindings, and resource lifecycle belong in deck.gl. This could also let the estimator consume math.gl/crs metadata rather than expanding ad hoc CRS string interpretation in core.
Static review at 7ca311c; tests were not run.
| 1 | ||
| ] | ||
| : [1, 1, 1]; | ||
| const metersPerUnit = [1, 1, 1]; |
There was a problem hiding this comment.
[P2] Account for source linear units before estimating ground-meter scale. isGeographicCrs() recognizes +units=ft and +units=us-ft as linear, but this branch assigns one meter to each input unit. For a simple feet-to-map-meters converter, the measured scale is approximately 0.3048 instead of 1, so meter-sized objects render at about 30.48% of the intended size. This source-unit limitation remains from the earlier viewport implementation and now also feeds the local scale field. Please convert recognized source units to meters, or require an explicit getDistanceScale override for units the estimator cannot interpret. math.gl/crs metadata could supply this conversion.
There was a problem hiding this comment.
This requires parsing the CRS string, will address in a follow up PR when we switch to @math.gl/crs.
bde9915 to
cfcde0f
Compare

For #10739 (PR 6 of 6)
Account for local projection distortion when rendering meter-sized objects and altitude.
Changed list
Method
Generation
Generate a 64×64 scale grid over the projection’s normalized extent. At each valid sample, inverse-project its position and estimate the local projection derivatives using one-meter displacements in world coordinates.
Use the square root of the absolute Jacobian determinant to obtain an area-equivalent scalar scale. Applying the same scale in both horizontal directions preserves the aspect ratio of anchored objects rather than reproducing directional distortion.
Compute scale slopes from neighboring samples, then extend valid values and slopes one cell into unsampled regions to cover valid positions near curved projection boundaries. Reuse the generated resource across camera changes; regenerate when its projection configuration changes.
Encoding
Each grid cell stores four floats:
[scale, dScale/dX, dScale/dY, altitudeScale]A zero scale marks an invalid sample. WebGL stores float bit patterns in an integer texture; WebGPU uses a
vec4<f32>storage buffer with direct address lookup.Interpolation
Fetch the nearest cell and reconstruct the local scale using its slopes:
Altitude scale receives the same relative adjustment. This requires one record lookup without bilinear filtering. Four-cell blending and higher-order interpolation remain documented alternatives if greater continuity or precision is needed.
Measured approximation error
Current harness results, in percent. “Center” covers a 128×128 common-unit square; “whole” covers valid positions within the 512×512 extent. Discontinuity measures the scale jump across nearest-cell boundaries, relative to the reference scale.
Test domains: Web Mercator through ±85.0511° latitude; Equal Earth worldwide; north-polar stereographic from 60°S to 90°N; Albers over
[-135, 30, -45, 75].All sampled valid positions retrieved valid scale values. Tests enforce error and discontinuity below 1%. These are sampled maxima for these configurations, not universal bounds. Equal Earth’s exact poles are excluded from relative-error calculations because the numerical reference is singular there, but sample validity is still checked.
Note
Medium Risk
Changes core projection shaders and per-view GPU resources for the experimental custom-projection path; ordinary MapView rendering stays on the existing code path via shader defines.
Overview
Custom projection views now size meter-based layer geometry (radius, width, elevation) using a location-dependent scale field instead of a single viewport-center correction. A new
toBoundsoption defines the map-meter extent used to build that field without changing position normalization.The viewport precomputes a 64×64 grid of area-equivalent scales (shape-preserving, not directionally stretched), with slopes and neighbor bleeding for curved boundaries.
ProjectionScaleResourcescaches a WebGLrgba32uinttexture or WebGPU storage buffer per view, regenerated when CRS/bounds signatures change and released when views are removed.The
projectshader module gains an opt-inUSE_EXTERNAL_PROJECTIONpath (enabled for custom geospatial viewports) that samples the field via nearest-texel Taylor reconstruction. Aggregation layers (including heatmap weight passes) pass the scale resource through draw; max-weight reduction explicitly disables external projection.Default geographic distortion estimation switches from a simple spherical model to WGS84 ellipsoidal ground distances. Documentation, the custom-projection test app (
toBoundson stereographic), render golden tests, and extensive unit/error harnesses cover the new behavior and fallbacks (viewport-center scale outsidetoBoundsor invalid samples).Reviewed by Cursor Bugbot for commit cfcde0f. Bugbot is set up for automated code reviews on this repo. Configure here.