Repository navigation
Conversation
dkhawk
force-pushed
the
feat/scale-bar-units
branch
from
November 3, 2026 21:10
61326dc to
d1f772a
Compare
Coverage (unit tests)Compared against
Line and branch coverage from unit test reports. History is recorded on the |
dkhawk
force-pushed
the
feat/scale-bar-units
branch
from
November 3, 2026 21:39
d1f772a to
4b87319
Compare
dkhawk
force-pushed
the
feat/scale-bar-units
branch
from
November 3, 2026 21:52
4b87319 to
12eb5aa
Compare
dkhawk
marked this pull request as ready for review
November 3, 2026 21:53
Adopt the Units API from android-maps-utils (MetricUnitsConverter, ImperialUnitsConverter with a 1-mile threshold, NumberFormatSymbols.COMPACT, and toDistanceString) for formatting metric and imperial distances in ScaleBar. Also fix a pre-existing accuracy bug in ScaleBar where the ground distance was previously calculated between Point(0, 0) and Point(widthInPixels, 0) at the top-left corner of the viewport and only recomputed when cameraPositionState.position.zoom changed: - Because Google Maps uses a conformal Web Mercator projection (EPSG:3857), map scale stretches isotropically in both latitude (North-South) and longitude (East-West) by a factor of 1 / cos(latitude) as you move toward the poles. Measuring at the top corner of the screen rather than the center of the map caused the scale bar to reflect the scale at the top edge of the viewport instead of where the camera is focused (for example, when centered on Iceland at zoom 3.15, the top edge of the screen lies in northern Greenland near 82N, causing the top-corner calculation to report 140 km / 87 mi instead of the 429 km / 267 mi width at Iceland). - Measure the scale across the camera target (cameraPositionState.position.target) at the center of the viewport by default, and observe cameraPositionState.position, cameraPositionState.isMoving, and LocalConfiguration.current so the scale bar stays accurate across latitude panning, map bearing rotation, camera tilt, and device orientation changes. - Add a measureAtCenter: Boolean = true parameter to ScaleBar and DisappearingScaleBar so callers can preserve the legacy top-corner behavior (measureAtCenter = false) if desired. - Update ScaleBarActivity with three sets of East-West and North-South reference crosshairs (at 10%, 50%, and 90% of the viewport height) whose ground lengths match the ScaleBar distance, plus UI checkboxes to toggle 'Measure at center' and 'Show crosshairs'. - Add unit and instrumentation tests covering Units API formatting, latitude changes at constant zoom, map bearing rotation, device rotation, and legacy top-corner measurement.
dkhawk
force-pushed
the
feat/scale-bar-units
branch
from
November 4, 2026 00:02
12eb5aa to
ae29c41
Compare
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.systemBarsPadding | ||
| import androidx.compose.foundation.layout.wrapContentSize | ||
| import androidx.compose.material.Checkbox |
| import androidx.compose.material.Checkbox | ||
| import androidx.compose.material.CircularProgressIndicator | ||
| import androidx.compose.material.MaterialTheme | ||
| import androidx.compose.material.Text |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adopt the
android-maps-utilsUnits API inScaleBar:ScaleBarwithMetricUnitsConverter,ImperialUnitsConverter(milesThreshold = 1.miles),NumberFormatSymbols.COMPACT, andLength.toDistanceString(...).1.miles(5,280 ft) threshold so the imperial scale bar transitions from feet to miles at 1 mile, matching the metric transition from meters to kilometers at 1 km (1,000 m).Fix
ScaleBarground distance calculation to measure at the center of the map viewport (measureAtCenter = true):calculateDistancecomputed the ground distance betweenPoint(0, 0)andPoint(widthInPixels, 0)at the top-left corner of the map viewport, and only recomputed whencameraPositionState.position.zoomchanged.EPSG:3857), which stretches map scale isotropically in both latitude (North–South) and longitude (East–West) by a factor of1 / cos(latitude)as you move toward the poles. Because of this stretching, the ground distance per pixel at the top corner of the screen can differ dramatically from the center of the screen where the user is looking.~65° N) atzoom = 3.15, theScaleBarwidth at the center of the screen spans the full coast-to-coast width of Iceland (429 km/267 mi). However, the top corner of the screen (Point(0, 0)) lies up in northern Greenland (~82° N), causing the top-corner calculation to report only140 km/87 mi(over3xsmaller than the scale at the center of the map).measureAtCenter: Boolean = true),ScaleBarandDisappearingScaleBarnow projectcameraPositionState.position.targetto screen coordinates and sample the horizontal pixel span across the center of the viewport (centerPoint.y).cameraPositionState.position,cameraPositionState.isMoving, andLocalConfiguration.currentinsidederivedStateOfso the scale bar updates accurately across latitude panning at constant zoom, map bearing rotation, camera tilt, and device orientation changes.measureAtCenter: Boolean = truetoScaleBarandDisappearingScaleBarso callers can preserve the legacy top-corner behavior (measureAtCenter = false) if desired.Interactive visual verification in
ScaleBarActivity:10%,50%, and90%of the viewport height, where each line's ground length on Earth equals the exact distance reported by theScaleBar.ScaleBar.Testing
:maps-app:connectedDebugAndroidTest&:maps-compose-widgets:connectedDebugAndroidTest):ScaleBarTests: Verifies initial state, fractional kilometers (< 10 km), fractional miles (< 10 mi), latitude changes at constant zoom (Equator vs. Iceland), map bearing rotation (0°,45°,90°,180°,270°), in-place and full-Activity device rotation (Portrait <-> Landscape), and legacy top-corner measurement (measureAtCenter = false).ScaleBarUnitTest: VerifiescalculateDistancecentered at target, legacy top-left fallback, and portrait-to-landscape viewport rotation.:maps-app:testDebugUnitTest):ScaleBarRenderingTests: VerifiesformatMetricDistanceandformatImperialDistanceacross meters/kilometers and feet/miles thresholds.