Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@vicb
Copy link
Owner

@vicb vicb commented Jan 3, 2026

Do not use the sampler before it is ready

Summary by Sourcery

Ensure 3D map live tracking only starts once the ArcGIS API and elevation data are fully initialized.

Bug Fixes:

  • Guard live tracking rendering on both graphics layer availability and API load state to avoid using the sampler before it is ready.
  • Prevent location handling from running when the view center is undefined to avoid runtime errors.
  • Ensure elevation tiles are only fetched and processed after the underlying elevation layer has loaded.

Enhancements:

  • Replace the dynamic elevation-layer factory with a dedicated ExaggeratedElevationLayer subclass that cleanly encapsulates elevation exaggeration behavior.

Summary by CodeRabbit

  • New Features

    • Added elevation-exaggeration support with a configurable multiplier for 3D terrain.
  • Bug Fixes

    • Improved 3D rendering stability by gating display until the mapping API is ready.
    • Made location tracking more tolerant of undefined coordinates to reduce view glitches.
  • Refactor

    • Modernized elevation layer architecture for consistent behavior across initialization and updates.

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

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 3, 2026

Reviewer's Guide

Refactors the exaggerated elevation layer into a typed BaseElevationLayer subclass, ensures the ArcGIS elevation sampler loads before use, guards against undefined view centers in the watcher, and gates rendering of the 3D tracking component on the ArcGIS API load state.

Sequence diagram for 3D tracking gating on ArcGIS API readiness

sequenceDiagram
  actor User
  participant Map3dElement
  participant Store
  participant ArcgisApi
  participant ArcgisView
  participant Tracking3dElement

  User->>Map3dElement: load_component()
  Map3dElement->>Store: setApiLoading(true)
  Store-->>Map3dElement: stateChanged(loadingApi=true)
  Map3dElement->>Map3dElement: apiLoaded = false

  ArcgisApi-->>ArcgisView: initialize_view_and_layers()
  ArcgisView-->>Store: setApiLoading(false)
  Store-->>Map3dElement: stateChanged(loadingApi=false)
  Map3dElement->>Map3dElement: apiLoaded = true

  Map3dElement->>Map3dElement: render()
  Map3dElement->>Tracking3dElement: render_tracking3d_element(layer,gndLayer,tracks,currentTrackId,timeSec,multiplier)
  activate Tracking3dElement
  Tracking3dElement-->>User: display_3d_live_tracking
  deactivate Tracking3dElement
Loading

Updated class diagram for Map3dElement and ExaggeratedElevationLayer

classDiagram
  class Map3dElement {
    - GraphicsLayer graphicsLayer
    - GraphicsLayer gndGraphicsLayer
    - boolean apiLoaded
    - ExaggeratedElevationLayer elevationLayer
    - number multiplier
    + stateChanged(state RootState) void
    + connectedCallback() void
    + firstUpdated() void
    + render() unknown
  }

  class BaseElevationLayer {
    + load() Promise~void~
    + fetchTile(level number,row number,col number,options BaseElevationLayerFetchTileOptions) ElevationTileData
    + addResolvingPromise(promise Promise~void~) void
  }

  class ElevationLayer {
    + url string
    + load() Promise~void~
    + fetchTile(level number,row number,col number,options BaseElevationLayerFetchTileOptions) ElevationTileData
  }

  class ExaggeratedElevationLayer {
    + number multiplier
    + ElevationLayer _elevation
    + ExaggeratedElevationLayer(multiplier number,properties BaseElevationLayerProperties)
    + load() Promise~void~
    + fetchTile(level number,row number,col number,options BaseElevationLayerFetchTileOptions) ElevationTileData
  }

  Map3dElement --> ExaggeratedElevationLayer : uses_as_elevationLayer
  ExaggeratedElevationLayer --|> BaseElevationLayer : extends
  ExaggeratedElevationLayer --> ElevationLayer : wraps_for_sampling
Loading

File-Level Changes

Change Details Files
Track ArcGIS API load state and gate 3D tracking rendering on it.
  • Introduce a reactive apiLoaded state field on the Map3dElement component.
  • Set apiLoaded based on the global app loadingApi flag in stateChanged and reset it to false in connectedCallback when (re)initializing the API.
  • Require both graphicsLayer and apiLoaded to be truthy before rendering the tracking3d-element.
apps/fxc-front/src/app/components/3d/map3d-element.ts
Replace dynamic createSubclass elevation layer helper with a concrete ExaggeratedElevationLayer subclass.
  • Remove the generic createElevationLayer helper and its Layer cache, and define an ExaggeratedElevationLayer class annotated with ArcGIS decorators and explicit properties for multiplier and underlying ElevationLayer.
  • Update construction sites to instantiate ExaggeratedElevationLayer directly instead of calling createElevationLayer.
  • Implement load() to create and load the wrapped ElevationLayer using an explicit HTTPS URL and register its promise with addResolvingPromise.
  • Implement fetchTile() to no-op safely when the underlying elevation layer is missing and to multiply elevation values by the configured multiplier when available.
apps/fxc-front/src/app/components/3d/map3d-element.ts
Harden center-watch handler against undefined Point values.
  • Change the watch callback signature for view.center to accept an optional Point and early-return when the point is undefined before calling handleLocation.
apps/fxc-front/src/app/components/3d/map3d-element.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link

coderabbitai bot commented Jan 3, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Replaces the elevation-layer factory with a decorated ExaggeratedElevationLayer class, adds an apiLoaded state flag to gate 3D rendering, and updates lifecycle and render logic to create/swap the exaggerated elevation layer and tolerate undefined location Points.

Changes

Cohort / File(s) Summary
3D Map Element Refactoring & API Load Gating
apps/fxc-front/src/app/components/3d/map3d-element.ts
Added arcgisDecorators import and applied @subclass()/@property() usage; removed createElevationLayer() factory and introduced ExaggeratedElevationLayer class (constructor, load, fetchTile, multiplier property); added apiLoaded state flag and used it to guard rendering and lifecycle flows; updated elevation layer creation, replacement, and map ground wiring; made location watch tolerant of undefined Points; adjusted render conditions for tracking3d-element.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰
I hopped through code, a curious sprite,
Made hills more tall and pixels light,
Decorators stitched my new-layer seam,
The map waits patient for API gleam,
Now elevation sings β€” a rabbit's dream.

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title 'fix 3D live tracking' accurately summarizes the main objective of the pull request, which is to fix the 3D live tracking feature by ensuring the ArcGIS API is ready before using it.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vicb/exa

πŸ“œ Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between ac4f140 and 752b85c.

πŸ“’ Files selected for processing (1)
  • apps/fxc-front/src/app/components/3d/map3d-element.ts
🧰 Additional context used
🧬 Code graph analysis (1)
apps/fxc-front/src/app/components/3d/map3d-element.ts (1)
libs/common/src/lib/runtime-track.ts (1)
  • Point (6-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Sourcery review
  • GitHub Check: build (22.x)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Cloudflare Pages
πŸ”‡ Additional comments (7)
apps/fxc-front/src/app/components/3d/map3d-element.ts (7)

10-10: LGTM!

The decorator import is necessary for the new ExaggeratedElevationLayer subclass and follows the standard ArcGIS pattern for custom layer implementation.


62-63: Excellent fix for the sampler readiness issue.

The apiLoaded flag correctly gates 3D rendering until the ArcGIS API and elevation data are ready. The lifecycle flow is sound: initialized to false in connectedCallback, synchronized with Redux state in stateChanged, and ultimately set to true when the view's when() callback completes (line 243).

Also applies to: 84-84, 146-146


124-127: LGTM!

The multiplier change handling correctly removes the old elevation layer and replaces it with a fresh ExaggeratedElevationLayer instance. The instantiation pattern now matches the standard ArcGIS properties-based constructor.


159-159: LGTM!

Initialization of the elevation layer now uses the dedicated ExaggeratedElevationLayer class with the properties-based pattern, improving encapsulation and maintainability.


255-259: Good defensive coding.

The guard prevents handleLocation from receiving undefined coordinate values when view.center is not yet initialized, avoiding potential runtime errors.


417-417: Perfect fix for the sampler readiness issue.

The dual condition this.graphicsLayer != null && this.apiLoaded ensures that tracking3d-element (and its use of elevationSampler on line 421) only renders after both the graphics layer and the ArcGIS API are fully initialized. This directly addresses the PR objective to prevent using the sampler before it's ready.


451-489: Solid refactoring to a dedicated elevation layer subclass.

The ExaggeratedElevationLayer implementation follows ArcGIS patterns correctly:

  • Uses @subclass() and @property() decorators appropriately
  • Constructor now accepts a single properties object including multiplier, addressing previous feedback
  • load() correctly initializes the internal elevation layer and registers the promise with addResolvingPromise
  • fetchTile() properly applies the multiplier to elevation values

The encapsulation is much cleaner than the previous factory function approach.

Note: The fetchTile method still has the critical issue flagged in the separate comment above.


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
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • In ExaggeratedElevationLayer.fetchTile, returning an empty object when _elevation is undefined can hide loading issues and produce invalid data; consider awaiting the layer load or throwing/logging an explicit error instead of returning a dummy tile.
  • The ExaggeratedElevationLayer constructor always overrides multiplier from its first parameter and ignores any multiplier that might be passed via properties; if this class is ever instantiated by the ArcGIS runtime or via JSON, you may want to derive multiplier from properties to avoid surprising behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ExaggeratedElevationLayer.fetchTile`, returning an empty object when `_elevation` is undefined can hide loading issues and produce invalid data; consider awaiting the layer load or throwing/logging an explicit error instead of returning a dummy tile.
- The `ExaggeratedElevationLayer` constructor always overrides `multiplier` from its first parameter and ignores any `multiplier` that might be passed via `properties`; if this class is ever instantiated by the ArcGIS runtime or via JSON, you may want to derive `multiplier` from `properties` to avoid surprising behavior.

## Individual Comments

### Comment 1
<location> `apps/fxc-front/src/app/components/3d/map3d-element.ts:472-478` </location>
<code_context>
-  const layer = new Layer();
-  layer.multiplier = multiplier;
-  return layer;
+  async fetchTile(
+    level: number,
+    row: number,
+    col: number,
+    options?: __esri.BaseElevationLayerFetchTileOptions,
+  ): Promise<__esri.ElevationTileData> {
+    if (!this._elevation) {
+      return {} as any;
+    }
</code_context>

<issue_to_address>
**issue (bug_risk):** Avoid returning an empty object when `_elevation` is not yet initialized.

Casting `{}` to `any` when `_elevation` is undefined breaks the contract of returning a valid `ElevationTileData` and can cause subtle runtime errors if `fetchTile` is called before `load` completes. Instead, either wait for initialization (e.g., `if (!this._elevation) await this.load();`) or throw a clear error so callers never receive an invalid tile payload.
</issue_to_address>

### Comment 2
<location> `apps/fxc-front/src/app/components/3d/map3d-element.ts:458-460` </location>
<code_context>
-          return data;
-        });
-      },
+  constructor(multiplier: number, properties?: __esri.BaseElevationLayerProperties | undefined) {
+    super(properties);
+    this.multiplier = multiplier;
+  }
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Custom constructor signature may diverge from the standard ArcGIS layer construction pattern.

The current signature `(multiplier: number, properties?)` only forwards `properties` to `super` and relies on positional args, which diverges from the usual `new Layer({ ...properties })` pattern. This risks misuse if the layer is ever instantiated via standard ArcGIS mechanisms or elsewhere with `new ExaggeratedElevationLayer({ multiplier: 2 })`, where `multiplier` would be ignored.

Consider accepting a single `properties` object that includes `multiplier`:

```ts
constructor(properties?: __esri.BaseElevationLayerProperties & { multiplier?: number }) {
  super(properties);
  if (properties?.multiplier != null) {
    this.multiplier = properties.multiplier;
  }
}
```

and update call sites to `new ExaggeratedElevationLayer({ multiplier: this.multiplier })` to match the standard pattern.

Suggested implementation:

```typescript
  constructor(
    properties?: __esri.BaseElevationLayerProperties & { multiplier?: number },
  ) {
    super(properties);
    if (properties?.multiplier != null) {
      this.multiplier = properties.multiplier;
    }
  }


```

You will also need to update all instantiations of `ExaggeratedElevationLayer` in this file (and elsewhere in the codebase) to follow the standard ArcGIS pattern. For example, change:

```ts
new ExaggeratedElevationLayer(this.multiplier)
```

to:

```ts
new ExaggeratedElevationLayer({ multiplier: this.multiplier })
```

and if there were existing properties:

```ts
new ExaggeratedElevationLayer(this.multiplier, { id: 'exaggerated-elev' })
```

to:

```ts
new ExaggeratedElevationLayer({ id: 'exaggerated-elev', multiplier: this.multiplier })
```

Search for `new ExaggeratedElevationLayer(` and adjust each call accordingly so the first (and only) argument is a single properties object that may include `multiplier`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

Comment on lines +472 to +478
async fetchTile(
level: number,
row: number,
col: number,
options?: __esri.BaseElevationLayerFetchTileOptions,
): Promise<__esri.ElevationTileData> {
if (!this._elevation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Avoid returning an empty object when _elevation is not yet initialized.

Casting {} to any when _elevation is undefined breaks the contract of returning a valid ElevationTileData and can cause subtle runtime errors if fetchTile is called before load completes. Instead, either wait for initialization (e.g., if (!this._elevation) await this.load();) or throw a clear error so callers never receive an invalid tile payload.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 3, 2026

Deploying flyxc with Β Cloudflare Pages Β Cloudflare Pages

Latest commit: 752b85c
Status:Β βœ…Β  Deploy successful!
Preview URL: https://abe85254.flyxc.pages.dev
Branch Preview URL: https://vicb-exa.flyxc.pages.dev

View logs

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: 0

🧹 Nitpick comments (1)
apps/fxc-front/src/app/components/3d/map3d-element.ts (1)

451-488: Consider improving the fallback in fetchTile when _elevation is undefined.

The class implementation is well-structured with proper ArcGIS decorators. However, returning {} as any (lines 478-479) when _elevation is undefined could cause subtle issues downstream if fetchTile is called before load() completes.

Consider returning a more explicit empty tile structure or throwing an error to make the failure mode clearer:

πŸ”Ž Suggested alternative
  async fetchTile(
    level: number,
    row: number,
    col: number,
    options?: __esri.BaseElevationLayerFetchTileOptions,
  ): Promise<__esri.ElevationTileData> {
    if (!this._elevation) {
-     return {} as any;
+     throw new Error('ExaggeratedElevationLayer: fetchTile called before load completed');
    }
    const data = await this._elevation.fetchTile(level, row, col, options);

Alternatively, if the ArcGIS framework expects a silent fallback, the current approach is acceptable given the apiLoaded gating now prevents premature usage.

πŸ“œ Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e473026 and ac4f140.

πŸ“’ Files selected for processing (1)
  • apps/fxc-front/src/app/components/3d/map3d-element.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build (22.x)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Sourcery review
  • GitHub Check: Cloudflare Pages
πŸ”‡ Additional comments (8)
apps/fxc-front/src/app/components/3d/map3d-element.ts (8)

10-10: LGTM!

The import is correctly added to support the ArcGIS decorators used in the new ExaggeratedElevationLayer class.


62-63: LGTM!

The new apiLoaded state property is properly declared and will correctly trigger re-renders when the API loading status changes.


84-84: LGTM!

The boolean inversion correctly maps the loading state to readiness: apiLoaded becomes true only when loadingApi is false.


121-128: LGTM!

The elevation layer replacement logic correctly removes the old layer before adding the new one with the updated multiplier.


144-147: LGTM!

Resetting apiLoaded to false in connectedCallback ensures the component starts in a safe state when reconnecting, and correctly triggers the API loading flow.


158-159: LGTM!

Correctly uses the new ExaggeratedElevationLayer class for initial elevation layer creation.


253-260: LGTM!

Good defensive programming. The optional Point parameter and null check prevent potential runtime errors when view.center is undefined during initialization or transitions.


416-423: Core fix: correctly gates 3D element rendering until API is ready.

This addresses the PR objective by ensuring tracking3d-element (which receives the elevationSampler) is not rendered until apiLoaded is true, preventing premature sampler usage.

Do not use the sampler before it is ready
@vicb vicb merged commit 23da754 into master Jan 3, 2026
7 checks passed
@vicb vicb deleted the vicb/exa branch January 3, 2026 15:05
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.

2 participants