Newer
Older
Sébastien DA ROCHA
committed
<template>
<div
:id="layer.dataKey"
class="ui segment layer-item"
>
Sébastien DA ROCHA
committed
<div class="ui divided form">
<div
class="field"
data-type="layer-field"
>
<label
for="form.layer.id_for_label"
class="layer-handle-sort"
>
Sébastien DA ROCHA
committed
</label>
<Dropdown

Timothee P
committed
:options="availableLayerOptions"
Sébastien DA ROCHA
committed
:selected="selectedLayer.name"
:selection.sync="selectedLayer"
:search="true"
:placeholder="placeholder"
/>
</div>
<div class="fields">
<div
class="field three wide {% if form.opacity.errors %} error{% endif %}"
>
<label for="opacity">Opacité</label>
<input
v-model.number="layerOpacity"
oninput="validity.valid||(value='');"
step="0.01"
min="0"
max="1"
Sébastien DA ROCHA
committed
</div>
<div class="field three wide">
<div
class="ui checkbox"
@click="updateLayer({ ...layer, queryable: !layer.queryable })"
Sébastien DA ROCHA
committed
>
Sébastien DA ROCHA
committed
<label for="queryable"> Requêtable</label>
</div>
</div>
</div>
<div
class="field"
@click="removeLayer"
>
Sébastien DA ROCHA
committed
<div class="ui compact small icon floated button button-hover-red">
<i
class="ui grey trash alternate icon"
aria-hidden="true"
/>
Sébastien DA ROCHA
committed
<span>Supprimer cette couche</span>
</div>
</div>
</div>
</div>
</template>
<script>
import Dropdown from '@/components/Dropdown.vue';
import { mapState } from 'vuex';
Sébastien DA ROCHA
committed
export default {
Sébastien DA ROCHA
committed
components: {
Dropdown,
},
props: {
layer:
{
type: Object,
default: null,
},
basemapid:
{
type: Number,
default: null,
},
},
Sébastien DA ROCHA
committed
computed: {
Sébastien DA ROCHA
committed
selectedLayer: {
get() {

Timothee P
committed
return this.retrieveLayer(this.layer.title) || [];
Sébastien DA ROCHA
committed
},
set(newValue) {
this.updateLayer({
...this.layer,
service: newValue.name,
title: newValue.value,
id: matchingLayer.id,
Sébastien DA ROCHA
committed
},
},
layerOpacity: {
get() {
return this.layer.opacity;
},
set(newValue) {
if (newValue) {
//* check if value was filled
this.updateLayer({ ...this.layer, opacity: newValue });
}
Sébastien DA ROCHA
committed
},
},

Timothee P
committed
availableLayerOptions: function () {
return this.availableLayers.map((el) => {
return {
id: el.id,
value: el.title,
title: el.title,
};
Sébastien DA ROCHA
committed
});
},
placeholder: function () {
return this.selectedLayer && this.selectedLayer.name
Sébastien DA ROCHA
committed
},
},
mounted() {
const matchingLayer = this.retrieveLayer(this.layer.title);
if (matchingLayer !== undefined) {
this.updateLayer({
...this.layer,
service: matchingLayer.service,
title: matchingLayer.title,
id: matchingLayer.id,
});
}
},
Sébastien DA ROCHA
committed
methods: {
retrieveLayer(title) {

Timothee P
committed
return this.availableLayerOptions.find((el) => el.title === title);
Sébastien DA ROCHA
committed
},
removeLayer() {
this.$store.commit('map/DELETE_BASEMAP_LAYER', {
Sébastien DA ROCHA
committed
basemapId: this.basemapid,
layerId: this.layer.dataKey,
});
},
updateLayer(layer) {
this.$store.commit('map/UPDATE_BASEMAP_LAYER', {
Sébastien DA ROCHA
committed
basemapId: this.basemapid,
layerId: this.layer.dataKey,
layer,
});
},
},
};