Skip to content

Commit

Permalink
clarify naming of method to avoid side effect where getLayer is calle…
Browse files Browse the repository at this point in the history
…d, without wanting to create it.
  • Loading branch information
mki-c2c committed Aug 22, 2023
1 parent d4de48b commit 19cfb89
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/composables/map/ol.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default function useOpenLayers() {
}

function addLayer(olMap: OlMap, layer: Layer) {
const baseLayer = getLayerFromCache(layer)
const baseLayer = getOrCreateLayer(layer)
olMap.addLayer(baseLayer)
}

Expand Down Expand Up @@ -234,9 +234,7 @@ export default function useOpenLayers() {
layersCache.set(id, layer)
}

function getLayerFromCache(
layer: Layer | undefined | null
): BaseLayer | null {
function getOrCreateLayer(layer: Layer | undefined | null): BaseLayer | null {
if (layer === null || layer === undefined) return null
const id = layer.id

Expand All @@ -250,6 +248,15 @@ export default function useOpenLayers() {
}
}

function getLayerFromCache(
layer: Layer | undefined | null
): BaseLayer | null {
if (layer === null || layer === undefined) return null
const id = layer.id

return layersCache.get(id)
}

function applyOnBgLayer(
olMap: OlMap,
callbackFunction: (bgLayer: BaseLayer) => void
Expand Down

0 comments on commit 19cfb89

Please sign in to comment.