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
</div>
<div class="nested">
<div
:id="`list-${basemap.id}`"
v-if="basemap.layers"
class="ui segments layers-container"
>
Sébastien DA ROCHA
committed
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
<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 Sortable from "sortablejs";
Sébastien DA ROCHA
committed
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
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 };
}),
});
},
//* drag & drop *//
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//* Get the names of the current layers in order.
const currentLayersNamesInOrder = Array.from(
document.getElementsByClassName("layer-item")
).map((el) => el.id);
//* increment value 'order' in this.basemap.layers looping over layers from template ^
let order = 0;
let movedLayers = [];
for (let id of currentLayersNamesInOrder) {
let matchingLayer = this.basemap.layers.find(
(el) => el.dataKey === Number(id)
);
if (matchingLayer) {
matchingLayer["order"] = order;
movedLayers.push(matchingLayer);
order += 1;
}
}
//* update the store
this.$store.commit("map/UPDATE_BASEMAP", {
layers: movedLayers,
id: this.basemap.id,
title: this.basemap.title,
errors: this.basemap.errors,
});
},
initSortable() {
new Sortable(document.getElementById(`list-${this.basemap.id}`), {
animation: 150,
handle: ".layer-handle-sort", // The element that is active to drag
ghostClass: "blue-background-class",
dragClass: "white-opacity-background-class",
onEnd: this.onlayerMove.bind(this),
});
},
Sébastien DA ROCHA
committed
},
"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
this.initSortable();
// if (!this.basemap.title) {
// this.$store.commit("map/UPDATE_BASEMAP", {
// id: this.basemap.id,
// title: newValue,
// });
// }
},
Sébastien DA ROCHA
committed
};
</script>
<style scoped>
.button {
margin-right: 0.5em !important;
}
</style>