Newer
Older
Sébastien DA ROCHA
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
<div class="ui segment layer-item">
<div class="ui divided form">
<div class="field" data-type="layer-field">
<label for="form.layer.id_for_label" class="layer-handle-sort">
<i class="th icon"></i>couche
</label>
<!-- {% if is_empty %} {# TODO arranger le dropdown pour les ajout à la volée
#} {# le selecteur de couche ne s'affichant pas correctement on passe
par un field django par defaut en attendant #} -->
<!-- {{ form.layer }} -->
<!-- {% else %} -->
<Dropdown
:options="availableLayers"
:selected="selectedLayer.name"
:selection.sync="selectedLayer"
:search="true"
:placeholder="placeholder"
/>
<!-- {{ form.layer.errors }} -->
</div>
<div class="fields">
<div
class="field three wide {% if form.opacity.errors %} error{% endif %}"
>
<label for="opacity">Opacité</label>
<input type="number" v-model.number="layerOpacity" step="0.01" />
<!-- {{ form.opacity.errors }} -->
</div>
<div class="field three wide">
<div
@click="updateLayer({ ...layer, queryable: !layer.queryable })"
class="ui checkbox"
>
<input type="checkbox" v-model="layer.queryable" name="queryable" />
<label for="queryable"> Requêtable</label>
</div>
<!-- {{ form.queryable.errors }} -->
</div>
</div>
<div @click="removeLayer" class="field">
<div class="ui compact small icon floated button button-hover-red">
<i class="ui grey trash alternate icon"></i>
<span>Supprimer cette couche</span>
</div>
</div>
</div>
</div>
</template>
<script>
import Dropdown from "@/components/Dropdown.vue";
import { mapState } from "vuex";
export default {
name: "ProjectMappingContextLayer",
props: ["layer", "basemapid"],
components: {
Dropdown,
},
computed: {
...mapState("map", ["layers", "availableLayers"]),
selectedLayer: {
get() {
const matchingLayer = this.retrieveLayer(this.layer.title);
return {
name: matchingLayer ? matchingLayer.service : "",
value: this.layer ? this.layer.title : "",
};
},
set(newValue) {
const matchingLayer = this.retrieveLayer(this.layer.title);
this.updateLayer({
...this.layer,
service: newValue.name,
title: newValue.value,
id: matchingLayer.id,
});
},
},
layerOpacity: {
get() {
return this.layer.opacity;
},
set(newValue) {
this.updateLayer({ ...this.layer, opacity: newValue });
},
},
availableLayers: function () {
return this.layers.map((el) => {
return { name: el.service, value: el.title };
});
},
placeholder: function () {
return this.selectedLayer && this.selectedLayer.name
? this.selectedLayer.name
: "Choisissez une couche";
},
},
methods: {
retrieveLayer(title) {
return this.layers.find((el) => el.title === title);
},
removeLayer() {
this.$store.commit("map/DELETE_BASEMAP_LAYER", {
basemapId: this.basemapid,
layerId: this.layer.dataKey,
});
},
updateLayer(layer) {
this.$store.commit("map/UPDATE_BASEMAP_LAYER", {
basemapId: this.basemapid,
layerId: this.layer.dataKey,
layer,
});
},
},
mounted() {
const matchingLayer = this.retrieveLayer(this.layer.title);
this.updateLayer({
...this.layer,
service: matchingLayer.service,
title: matchingLayer.title,
id: matchingLayer.id,
});
},
};
</script>