Skip to content

Commit

Permalink
Show / Hide factories by show/hiding entire layer
Browse files Browse the repository at this point in the history
rather than one by one

73
  • Loading branch information
komali2 committed Jun 25, 2021
1 parent 10960a0 commit 3553a20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/components/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,16 @@ export default createComponent({
]
}
mapControllerRef.value.setFactoryStatusFilter(appliedFilters.value)
mapControllerRef.value.mapInstance.map.getLayers().forEach((layer) => {
const factoryStatus = layer.get('factoryStatus')
if (factoryStatus === undefined) return
const comparableFactoryStatus = factoryStatus === 'default' ? factoryStatus : Number(factoryStatus)
if (!appliedFilters.value.includes(comparableFactoryStatus)) {
layer.setVisible(false)
} else {
layer.setVisible(true)
}
})
}
const filterButtonsData = defaultFactoryDisplayStatuses.map(v => ({
Expand Down
9 changes: 5 additions & 4 deletions src/lib/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export class MapFactoryController {
}

getFactoriesLayerForStatus (factoryStatus: FactoryDisplayStatusType) {
if (!this._factoriesLayerStatusMap[`_${factoryStatus}`]) {
this._factoriesLayerStatusMap[`_${factoryStatus}`] = new VectorSource({ features: [] })
if (!this._factoriesLayerStatusMap[`${factoryStatus}`]) {
this._factoriesLayerStatusMap[`${factoryStatus}`] = new VectorSource({ features: [] })
const clusterSource = new Cluster({
distance: 50,
source: this._factoriesLayerStatusMap[`_${factoryStatus}`]
source: this._factoriesLayerStatusMap[`${factoryStatus}`]
})
const styleCache = {}
const vectorLayer = new VectorLayer({
Expand Down Expand Up @@ -174,9 +174,10 @@ export class MapFactoryController {
}
}
})
vectorLayer.setProperties({ factoryStatus })
this.mapInstance.map.addLayer(vectorLayer)
}
return this._factoriesLayerStatusMap[`_${factoryStatus}`]
return this._factoriesLayerStatusMap[`${factoryStatus}`]
}

public getFactory (id: string) {
Expand Down

0 comments on commit 3553a20

Please sign in to comment.