Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mki-c2c committed Aug 24, 2023
1 parent 8ed86d2 commit fbacc59
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 107 deletions.
13 changes: 3 additions & 10 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { onMounted, onUnmounted, watch } from 'vue'
import { storeToRefs } from 'pinia'
import MapLibreLayer from '@/lib/ol-maplibre-layer'
import olLayerGroup from 'ol/layer/Group.js'
import { MapLibreLayerType } from './composables/map/map.model'
import HeaderBar from './components/header/header-bar.vue'
Expand All @@ -25,6 +24,7 @@ import { statePersistorStyleService } from '@/services/state-persistor/state-per
import { statePersistorMyMapService } from '@/services/state-persistor/state-persistor-mymap.service'
import { useAppStore } from '@/stores/app.store'
import useMap from '@/composables/map/map.composable'
import traverseLayer from '@/lib/tools.js'
// Important, keep order!
statePersistorMyMapService.bootstrap()
Expand All @@ -45,15 +45,6 @@ watch(layersOpen, () =>
onMounted(() => window.addEventListener('resize', resizeMap))
onUnmounted(() => window.removeEventListener('resize', resizeMap))
function traverseLayer(layer, ancestors, visitor) {
const descend = visitor(layer, ancestors)
if (descend && layer instanceof olLayerGroup) {
layer.getLayers().forEach(childLayer => {
traverseLayer(childLayer, [...ancestors, layer], visitor)
})
}
}
function resizeMap() {
// Update all canvas size when layer panel is opened/closed
const map = useMap().getOlMap()
Expand All @@ -62,6 +53,8 @@ function resizeMap() {
map.updateSize()
// And trigger update MapLibre layers' canvas size
// the utility function traverseLayer is used as a workaround until OL is updated to 6.15
// then the function getAllLayers below (added in OL v.6.10.0) can be used
// map.getAllLayers().forEach(layer => {
traverseLayer(map.getLayerGroup(), [], layer => {
if (layer instanceof MapLibreLayer) {
Expand Down
5 changes: 1 addition & 4 deletions src/composables/map/ol.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,7 @@ 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)
return layer ? layersCache.get(layer.id) : null
}

function applyOnBgLayer(
Expand Down
4 changes: 1 addition & 3 deletions src/composables/mvt-styles/mvt-styles.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export default function useMvtStyles() {
const newVectorSources: VectorSourceDict = new Map()
styleStore.bgVectorSources.forEach((vectorSource, key) => {
if (key === bgLayer.id) {
const newVectorSource = Object.assign({}, vectorSource, {
xyz_custom: serial,
})
const newVectorSource = { ...vectorSource, xyz_custom: serial }
newVectorSources.set(key, newVectorSource)
} else {
newVectorSources.set(key, vectorSource)
Expand Down
10 changes: 10 additions & 0 deletions src/lib/tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import olLayerGroup from 'ol/layer/Group.js'

export default function traverseLayer(layer, ancestors, visitor) {
const descend = visitor(layer, ancestors)
if (descend && layer instanceof olLayerGroup) {
layer.getLayers().forEach(childLayer => {
traverseLayer(childLayer, [...ancestors, layer], visitor)
})
}
}
90 changes: 0 additions & 90 deletions src/stores/app.store.ts.orig

This file was deleted.

0 comments on commit fbacc59

Please sign in to comment.