Skip to content

Add elevation and country code lookup functionality to map components#233

Open
Claudio-Chies wants to merge 2 commits intodbrgn:mainfrom
Claudio-Chies:pr-flightloging_location_behaviour2
Open

Add elevation and country code lookup functionality to map components#233
Claudio-Chies wants to merge 2 commits intodbrgn:mainfrom
Claudio-Chies:pr-flightloging_location_behaviour2

Conversation

@Claudio-Chies
Copy link
Contributor

@Claudio-Chies Claudio-Chies commented Jan 26, 2026

Auto-fill elevation and country code when placing location marker

Description

When adding or editing a location, the elevation and country code fields are now automatically filled when the user places a marker on the map (via double-click/tap or by dragging).

This re-implements the proposed changes from #198 in a less invasive way, no version bump, same structure

Changes

  • Elevation lookup: Uses Mapbox Terrain v2 vector tileset (contour polygons) to query elevation at the marker position. (~10m precision).
  • Country code lookup: Uses Mapbox Countries v1 vector tileset to query the country code at the marker position.
  • Zoom limitation: Elevation data is only available at zoom level 9+. When zoomed out further, a hint is shown: "Zoom in on the map to auto-fill the elevation." to reduce number of queris
  • Data layers: The vector tilesets are added as invisible layers and only loaded when locations are being edited.

Key Differences to PR #198

  • No version bump to MapLibre 5
  • no "hack" with terrain exaggeration
  • Reduced number of tiles loaded
  • kept old map-layer import style

Notes

  • This code was generated with the help of AI (GitHub Copilot).
  • The implementation uses vector tilesets instead of the Tilequery API to avoid rate limits and network latency.
  • Elevation precision is ~10m (contour interval), which is sufficient for paragliding launch/landing locations.

Closes #55

Summary by CodeRabbit

  • New Features
    • Auto-populates elevation and country info when marker position changes (drag or update).
    • Adds zoom-level guidance to prompt users to zoom in for accurate elevation.
    • Location form now displays map-derived elevation/country feedback and hint UI.
    • Localized hint text added for English and German.

✏️ Tip: You can customize this high-level summary in your review settings.

@Claudio-Chies
Copy link
Contributor Author

In Action:

Screencast.from.2026-01-26.14-58-19.mp4

@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

Walkthrough

Adds map-based elevation and country lookups: BaseMap queries terrain contours and country boundaries after marker moves and emits results via new onElevationLookup and onCountryLookup callbacks propagated through SingleMap to LocationForm for form updates and hints.

Changes

Cohort / File(s) Summary
Map lookup & layers
frontend/src/lib/components/BaseMap.svelte
Adds MIN_ZOOM_FOR_ELEVATION_QUERY, queryElevation, queryCountryCode, and performLocationDataLookup; initializes invisible terrain-contours-data and countries-data layers when editable; triggers lookups on marker drag/end and position updates; exposes onElevationLookup and onCountryLookup props.
Callback forwarding
frontend/src/lib/components/SingleMap.svelte
Adds public props onElevationLookup and onCountryLookup (optional) and forwards them to BaseMap invocation.
Form integration & UI
frontend/src/routes/locations/LocationForm.svelte
Adds showElevationHint state, handleElevationLookup and handleCountryLookup handlers; wires SingleMap events to update elevation and countryCode fields; displays a conditional hint when zoom is too low.
Localization
frontend/src/translations/en/translation.json, frontend/src/translations/de/translation.json
Adds location.hint--zoom-in-elevation translations (English and German).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SingleMap
    participant BaseMap
    participant DataLayers as Terrain & Countries
    participant LocationForm

    User->>SingleMap: drag marker / change position
    activate SingleMap
    SingleMap->>BaseMap: forward position update
    activate BaseMap
    BaseMap->>DataLayers: queryElevation(coords)
    BaseMap->>DataLayers: queryCountryCode(coords)
    activate DataLayers
    DataLayers-->>BaseMap: elevation (or null) + zoomTooLow
    DataLayers-->>BaseMap: countryCode (or null)
    deactivate DataLayers
    BaseMap-->>SingleMap: onElevationLookup({elevation, zoomTooLow})
    BaseMap-->>SingleMap: onCountryLookup({countryCode})
    deactivate BaseMap
    SingleMap-->>LocationForm: forward lookup events
    deactivate SingleMap
    activate LocationForm
    LocationForm->>LocationForm: set elevation / set hint / set countryCode
    deactivate LocationForm
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding elevation and country code lookup functionality to map components, which is the primary focus of the changeset.
Linked Issues check ✅ Passed The PR successfully implements the core requirement from #55 to extract altitude/elevation from Mapbox when editing locations. The implementation uses vector tilesets (Mapbox Terrain v2) to query elevation at marker positions, fulfilling the objective of providing altitude data during location editing.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objectives. The PR introduces elevation and country code lookups, adds necessary callbacks to map components, integrates handlers in LocationForm, and includes translations for the zoom-in hint—all supporting the core elevation/country lookup feature without unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/src/routes/locations/LocationForm.svelte (1)

237-241: Bug: wrong field error displayed for name field.

The error message displays fieldErrors.longitude instead of fieldErrors.name.

🐛 Proposed fix
     {`#if` fieldErrors.name !== undefined}
       <div class="field-error">
-        {$i18n.t('common.error', {message: fieldErrors.longitude})}
+        {$i18n.t('common.error', {message: fieldErrors.name})}
       </div>
     {/if}
🤖 Fix all issues with AI agents
In `@frontend/src/translations/de/translation.json`:
- Line 223: Run the i18n parser locally and commit the sync changes: execute the
project command npm run i18n:parse, review the generated updates to translation
files (ensure the translation key "hint--zoom-in-elevation" and other keys are
updated), add and commit the resulting files, and push the branch so CI no
longer reports translations out of sync.

In `@frontend/src/translations/en/translation.json`:
- Around line 223-224: Remove the extra blank line before the
"hint--zoom-in-elevation" translation key to match the project's i18n formatting
and then run the parser to regenerate translation artifacts: run `npm run
i18n:parse` locally (this will re-sync translation files), review the generated
changes, and commit them; ensure the translation key "hint--zoom-in-elevation"
is adjacent to the surrounding entries with no stray blank line so the i18n sync
pipeline passes.
🧹 Nitpick comments (2)
frontend/src/routes/locations/LocationForm.svelte (1)

41-47: Consider clearing countryCode when lookup returns null for consistency.

The handleElevationLookup clears elevation when the lookup returns null, but handleCountryLookup does not clear countryCode. This creates asymmetric behavior. If the marker is placed over international waters or an area without country data, the previous country code persists while elevation is cleared.

Consider whether the country code should also be cleared when the lookup returns null:

♻️ Optional: Clear countryCode when null
   function handleCountryLookup(data: {countryCode: string | null}) {
     const {countryCode: newCountryCode} = data;
     if (newCountryCode !== null) {
       countryCode = newCountryCode;
+    } else {
+      countryCode = '';
     }
   }
frontend/src/lib/components/BaseMap.svelte (1)

329-359: Consider tile loading timing for lookups.

The data layers are initialized on style.load, but tiles may not be fully loaded when the user first interacts with the marker. If queryRenderedFeatures is called before the tiles for terrain-contours-data or countries-data are loaded at the marker's location, it will return empty results.

This is likely acceptable since:

  1. Users typically zoom/pan before placing markers, allowing tiles to load
  2. The UI handles null results gracefully (shows hint for elevation)

However, consider noting this behavior in the hint message or triggering a re-lookup when the user zooms/pans to load new tiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract altitude from Mapbox when editing location

1 participant