GEOLYTIX / xyz

An open source javascript framework for spatial data and application interfaces.
MIT License
86 stars 25 forks source link

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

Closed simon-leech closed 1 week ago

simon-leech commented 1 week ago

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.

How have you tested this?

Tested locally.

Testing Checklist

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

Code Quality Checklist

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