Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check on entry.Layer needs to happen before assigning entry.Layer.zIndex #1336

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

simon-leech
Copy link
Contributor

@simon-leech simon-leech commented Jun 18, 2024

MVT Clone Fix

Description

Bug fix here.
If entry.Layer is undefined - ie the layer to clone is not accessible, and the entry has no zIndex. The code attempts to set the entry.zIndex to entry.Layer.zIndex. But as entry.Layer does not exist, it crashes.

  // Assign the mvt layer to be cloned from mapview layers.
  entry.Layer = entry.mapview.layers[entry.layer]

  entry.zIndex ??= entry.Layer.zIndex

  if (!entry.Layer) {
    console.warn('mvt_clone Layer not found in mapview.layers object.')
    return;
  }

To fix this I simply swapped the code around. This way - if the entry.Layer does not exist then the return happens and no crash occurs.

  // Assign the mvt layer to be cloned from mapview layers.
  entry.Layer = entry.mapview.layers[entry.layer]

  if (!entry.Layer) {
    console.warn('mvt_clone Layer not found in mapview.layers object.')
    return;
  }

  entry.zIndex ??= entry.Layer.zIndex

Type of Change

Please delete options that are not relevant, and select all options that apply.

  • ✅ Bug fix (non-breaking change which fixes an issue)

How have you tested this?

Tested locally.

Testing Checklist

Please delete options that are not relevant, and select all options that apply.

  • ✅ Existing Tests still pass
  • ✅ Updated Existing Tests
  • ✅ New Tests Added
  • ✅ Ran locally on my machine

Code Quality Checklist

Please delete options that are not relevant, and select all options that apply.

  • ✅ My code follows the guidelines of XYZ
  • ✅ My code has been commented
  • ✅ Documentation has been updated
  • ✅ New and existing unit tests pass locally with my changes
  • ✅ Main has been merged into this PR

@simon-leech simon-leech added the Bug A genuine bug. There must be some form of error exception to work with. label Jun 18, 2024
@simon-leech simon-leech marked this pull request as ready for review June 18, 2024 18:42
Copy link
Member

@dbauszus-glx dbauszus-glx left a comment

Choose a reason for hiding this comment

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

excellent

@dbauszus-glx dbauszus-glx merged commit 627418b into GEOLYTIX:main Jun 19, 2024
4 checks passed
@simon-leech simon-leech deleted the mvt-clone-fix branch June 19, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A genuine bug. There must be some form of error exception to work with.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants