Newer
Older
Sébastien DA ROCHA
committed
<template>
<div class="ui segment">
<div class="field required">
<label for="basemap-title">Titre</label>
<input
Sébastien DA ROCHA
committed
type="text"
name="basemap-title"
required
/>
<ul
v-if="basemap.errors && basemap.errors.length > 0"
id="errorlist-title"
class="errorlist"
>
<li>
{{ basemap.errors }}
</li>
</ul>
Sébastien DA ROCHA
committed
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
</div>
<div class="nested">
<div v-if="basemap.layers" class="ui segments layers-container">
<ProjectMappingContextLayer
v-for="layer in basemap.layers"
:key="'layer-' + layer.dataKey"
:layer="layer"
:basemapid="basemap.id"
/>
</div>
<div class="ui buttons">
<a
@click="addLayer"
class="ui compact small icon left floated button green"
>
<i class="ui plus icon"></i>
<span>Ajouter une couche</span>
</a>
</div>
<div @click="deleteBasemap" class="ui buttons">
<a
class="
ui
compact
red
small
icon
right
floated
button button-hover-green
"
>
<i class="ui trash alternate icon"></i>
<span>Supprimer ce fond cartographique</span>
</a>
</div>
</div>
</div>
</template>
<script>
import ProjectMappingContextLayer from "@/components/project/ProjectMappingContextLayer.vue";
export default {
name: "Project_mapping_basemap",
props: ["basemap"],
components: {
ProjectMappingContextLayer,
},
computed: {
maxLayersCount: function () {
return this.basemap.layers.reduce((acc, curr) => {
if (curr.dataKey > acc) {
return curr.dataKey;
} else {
return acc;
}
}, 0);
},
},
methods: {
deleteBasemap() {
this.$store.commit("map/DELETE_BASEMAP", this.basemap.id);
},
addLayer(layer) {
const newLayer = {
dataKey: this.maxLayersCount + 1,
opacity: "1.00",
order: 0,
queryable: false,
title: "Open street map",
...layer,
};
this.$store.commit("map/UPDATE_BASEMAP", {
layers: [...this.basemap.layers, newLayer],
id: this.basemap.id,
title: this.basemap.title,
Sébastien DA ROCHA
committed
});
},
updateTitle(evt) {
this.$store.commit("map/UPDATE_BASEMAP", {
id: this.basemap.id,
title: evt.title,
errors: evt.errors,
Sébastien DA ROCHA
committed
});
},
removeLayer(dataKey) {
this.layers = this.layers.filter((layer) => layer.dataKey !== dataKey);
},
fillLayersWithDatakey(layers) {
let dataKey = 0;
this.$store.commit("map/REPLACE_BASEMAP_LAYERS", {
basemapId: this.basemap.id,
layers: layers.map((el) => {
dataKey += 1;
return { dataKey, ...el };
}),
});
},
},
"basemap.title": {
handler: function (newValue, oldValue) {
if (newValue !== oldValue) {
if (newValue === "")
this.basemap.errors = "Veuillez compléter ce champ.";
else this.basemap.errors = "";
this.updateTitle(this.basemap);
},
},
Sébastien DA ROCHA
committed
created() {
if (this.basemap.layers) {
//* add datakeys to layers coming from api
Sébastien DA ROCHA
committed
this.fillLayersWithDatakey(this.basemap.layers);
}
},
// destroyed(){
// this.errors = [];
// }
Sébastien DA ROCHA
committed
// mounted() { //* not present in original
// if (!this.basemap.title) {
// this.$store.commit("map/UPDATE_BASEMAP", {
// id: this.basemap.id,
// title: newValue,
// });
// }
// },
};
</script>
<style scoped>
.button {
margin-right: 0.5em !important;
}
</style>