Skip to content

Commit 479e8b4

Browse files
committed
PB-2055: Use getZIndex instead ref. Vue's watch also works for getter function.
1 parent 8d6f8fc commit 479e8b4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packages/viewer/src/modules/map/components/openlayers/utils/useAddLayerToMap.composable.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { default as Layer } from 'ol/layer/Layer'
22
import type Map from 'ol/Map'
33

44
import VectorSource from 'ol/source/Vector'
5-
import { type MaybeRef, onBeforeUnmount, onMounted, toRef, toValue, watch } from 'vue'
5+
import { type MaybeRef, onBeforeUnmount, onMounted, toValue, watch } from 'vue'
66

77
/**
88
* Vue composable that will handle the addition or removal of an OpenLayers layer. This is a
@@ -19,16 +19,14 @@ import { type MaybeRef, onBeforeUnmount, onMounted, toRef, toValue, watch } from
1919
*
2020
* @param layer - The OpenLayers layer to add to the map
2121
* @param map - The OpenLayers map instance
22-
* @param zIndex - A getter function that returns the z-index value. Defaults to () => -1 (no z-index set).
22+
* @param getZIndex - A getter function that returns the z-index value. Defaults to () => -1 (no z-index set).
2323
*/
2424
export default function useAddLayerToMap(
2525
layer: MaybeRef<Layer>,
2626
map: MaybeRef<Map>,
27-
zIndex: () => number = () => -1
27+
getZIndex: () => number = () => -1
2828
) {
29-
const zIndexRef = toRef(zIndex)
30-
31-
watch(zIndexRef, (newValue) => {
29+
watch(getZIndex, (newValue) => {
3230
if (newValue >= 0) {
3331
toValue(layer).setZIndex(newValue)
3432
}
@@ -49,8 +47,9 @@ export default function useAddLayerToMap(
4947
})
5048

5149
function addLayerToMap(): void {
52-
if (zIndexRef.value !== -1) {
53-
toValue(layer).setZIndex(zIndexRef.value)
50+
const currentZIndex = getZIndex()
51+
if (currentZIndex !== -1) {
52+
toValue(layer).setZIndex(currentZIndex)
5453
}
5554
toValue(map).addLayer(toValue(layer))
5655
}

0 commit comments

Comments
 (0)