Skip to content

Commit 68bc127

Browse files
committed
Use the layer collection proxy for layer list.
1 parent 9257dba commit 68bc127

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/components/layerlist/LayerList.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<wgu-layerlistitem
55
v-for="layer in displayedLayers"
66
:key="layer.get('lid')"
7-
:layer="layer"
7+
:layer="layer.getLayer()"
88
:mapView="map.getView()"
99
:showLegends="showLegends"
1010
:showOpacityControls="showOpacityControls"
@@ -13,6 +13,7 @@
1313
</template>
1414

1515
<script>
16+
import { LayerCollectionProxy } from '@/util/Layer';
1617
import { Mapable } from '../../mixins/Mapable';
1718
import LayerListItem from './LayerListItem'
1819
@@ -28,7 +29,7 @@ export default {
2829
},
2930
data () {
3031
return {
31-
layers: []
32+
layersProxy: undefined
3233
}
3334
},
3435
methods: {
@@ -37,16 +38,23 @@ export default {
3738
* Bind to the layers from the OpenLayers map.
3839
*/
3940
onMapBound () {
40-
this.layers = this.map.getLayers().getArray();
41+
this.layersProxy = new LayerCollectionProxy(this.map.getLayers(),
42+
['lid', 'displayInLayerList', 'isBaseLayer']);
4143
}
4244
},
45+
destroyed () {
46+
this.layersProxy.destroy();
47+
},
4348
computed: {
4449
/**
4550
* Reactive property to return the OpenLayers layers to be shown in the control.
4651
* Remarks: The 'displayInLayerList' attribute should default to true per convention.
4752
*/
4853
displayedLayers () {
49-
return this.layers
54+
if (!this.layersProxy) {
55+
return [];
56+
}
57+
return this.layersProxy.getArray()
5058
.filter(layer => layer.get('displayInLayerList') !== false && !layer.get('isBaseLayer'))
5159
.reverse();
5260
}

0 commit comments

Comments
 (0)