Skip to content
Snippets Groups Projects
Feature_edit.vue 34.3 KiB
Newer Older
<template>
  <div v-frag>
    <div class="fourteen wide column">
      <h1 v-if="feature && currentRouteName === 'editer-signalement'">
Timothee P's avatar
Timothee P committed
        Mise à jour du signalement "{{ feature.title || feature.feature_id }}"
        v-else-if="feature_type && currentRouteName === 'ajouter-signalement'"
        Création d'un signalement <small>[{{ feature_type.title }}]</small>
      </h1>

      <form
        id="form-feature-edit"
        action=""
        method="post"
        enctype="multipart/form-data"
        class="ui form"
      >
        <!-- Feature Fields -->
        <div class="two fields">
leandro's avatar
leandro committed
          <div :class="field_title">
            <label :for="form.title.id_for_label">{{ form.title.label }}</label>
              :id="form.title.id_for_label"
              v-model="form.title.value"
              :maxlength="form.title.field.max_length"
              :name="form.title.html_name"
            >
            <ul
              id="errorlist-title"
              class="errorlist"
            >
              <li
                v-for="error in form.title.errors"
                :key="error"
              >
            <label :for="form.status.id_for_label">{{
              form.status.label
              :options="allowedStatusChoices"
              :selected="selected_status.name"
          <label :for="form.description.id_for_label">{{
            form.description.label
            v-model="form.description.value"
            :name="form.description.html_name"
          <label :for="form.geom.id_for_label">{{ form.geom.label }}</label>
          <div
            v-if="feature_type && feature_type.geom_type === 'point'"
            v-frag
          >
                id="add-geo-image"
                type="button"
                class="ui compact button"
                @click="toggleGeoRefModal"
                <i class="file image icon" />Importer une image géoréférencée
              </button>
              Vous pouvez utiliser une image géoréférencée pour localiser le
              signalement.
            </p>

            <div
              v-if="showGeoRef"
              class="ui dimmer modals page transition visible active"
              style="display: flex !important"
            >
              <div
                class="ui mini modal transition visible active"
                style="display: block !important"
                <i
                  class="close icon"
                  @click="toggleGeoRefModal"
                />
                <div class="content">
                  <h3>Importer une image géoréférencée</h3>
                  <form
                    id="form-geo-image"
                    class="ui form"
                    enctype="multipart/form-data"
                  >
                    <p>
                      Attention, si vous avez déjà saisi une géométrie, celle
                      issue de l'image importée l'écrasera.
                    </p>
                    <div class="field georef-btn">
                      <label>Image (png ou jpeg)</label>
                      <label
                        class="ui icon button"
                        for="image_file"
                      >
                        <i class="file icon" />
                        <span class="label">{{ geoRefFileLabel }}</span>
                      </label>
                      <input
                        id="image_file"
                        ref="file"
                        type="file"
                        accept="image/jpeg, image/png"
                        style="display: none"
                        name="image_file"
                        class="image_file"
                        @change="handleFileUpload"
                      >
                      <ul
                        v-if="erreurUploadMessage"
                        class="errorlist"
                      >
                        <li>
                          {{ erreurUploadMessage }}
                        </li>
                      </ul>
                    </div>
                    <button
                      id="get-geom-from-image-file"
                      type="button"
                      :class="[
                        'ui compact button',
                        file && !erreurUploadMessage ? 'green' : 'disabled',
                        { red: erreurUploadMessage },
                      ]"
                      @click="georeferencement"
                      <i class="plus icon" />
DESPRES Damien's avatar
DESPRES Damien committed
            </div>
DESPRES Damien's avatar
DESPRES Damien committed
            <p v-if="showGeoPositionBtn">
                id="create-point-geoposition"
                type="button"
                class="ui compact button"
                @click="create_point_geoposition"
                <i class="ui map marker alternate icon" />Positionner le
                signalement à partir de votre géolocalisation
              </button>
            </p>
            <span
              v-if="erreurGeolocalisationMessage"
              id="erreur-geolocalisation"
              <div class="ui negative message">
                <div class="header">
                  Une erreur est survenue avec la fonctionnalité de
                  géolocalisation
                </div>
                <p id="erreur-geolocalisation-message">
                  {{ erreurGeolocalisationMessage }}
                </p>
          <ul
            id="errorlist-geom"
            class="errorlist"
          >
            <li
              v-for="error in form.geom.errors"
              :key="error"
            >
            :id="form.geom.id_for_label"
            v-model="form.geom.value"
            type="hidden"
            :name="form.geom.html_name"
          >
          <div
            class="ui tab active map-container"
            data-tab="map"
          >
            <div
              id="map"
              ref="map"
            />
            <SidebarLayers v-if="basemaps && map" />
        <div class="ui horizontal divider">
          DONNÉES MÉTIER
        </div>
          v-for="(field, index) in orderedCustomFields"
          :key="field.field_type + index"
          class="field"
        >
          <FeatureExtraForm :field="field" />
          <div class="ui horizontal divider">
            PIÈCES JOINTES
          </div>
          <div
            v-if="isOffline() !== true"
            id="formsets-attachment"
          >
            <FeatureAttachmentForm
Timothee P's avatar
Timothee P committed
              v-for="attachForm in attachmentFormset"
              :key="attachForm.dataKey"
              ref="attachementForm"
Timothee P's avatar
Timothee P committed
              :attachment-form="attachForm"
          <button
            id="add-attachment"
            type="button"
            class="ui compact basic button button-hover-green"
            @click="add_attachement_formset"
            <i class="ui plus icon" />Ajouter une pièce jointe
          </button>
        </div>
          <div class="ui horizontal divider">
            SIGNALEMENTS LIÉS
          </div>
          <div id="formsets-link">
            <FeatureLinkedForm
Timothee P's avatar
Timothee P committed
              v-for="linkForm in linkedFormset"
              :key="linkForm.dataKey"
              ref="linkedForm"
Timothee P's avatar
Timothee P committed
              :linked-form="linkForm"
            />
          </div>
          <button
            id="add-link"
            type="button"
            class="ui compact basic button button-hover-green"
            @click="add_linked_formset"
            <i class="ui plus icon" />Ajouter une liaison
          </button>
        <div class="ui divider" />
        <button
          type="button"
          class="ui teal icon button"
          @click="postForm"
        >
          <i class="white save icon" /> Enregistrer les changements
import frag from 'vue-frag';
import { mapState, mapGetters } from 'vuex';
import FeatureAttachmentForm from '@/components/feature/FeatureAttachmentForm';
import FeatureLinkedForm from '@/components/feature/FeatureLinkedForm';
import FeatureExtraForm from '@/components/feature/FeatureExtraForm';
import Dropdown from '@/components/Dropdown.vue';
import SidebarLayers from '@/components/map-layers/SidebarLayers';
import featureAPI from '@/services/feature-api';

import L from 'leaflet';
import 'leaflet-draw';
import { mapUtil } from '@/assets/js/map-util.js';
import axios from '@/axios-client.js';
import flip from '@turf/flip';
  name: 'FeatureEdit',
    FeatureAttachmentForm,
    FeatureLinkedForm,
      baseUrl: this.$store.state.configuration.BASE_URL,
      file: null,
      showGeoRef: false,
      showGeoPositionBtn: true,
      erreurGeolocalisationMessage: null,
      erreurUploadMessage: null,
      attachmentDataKey: 0,
      linkedDataKey: 0,
      form: {
          id_for_label: 'name',
          html_name: 'name',
          label: 'Nom',
          value: '',
          id_for_label: 'status',
          html_name: 'status',
          label: 'Statut',
            value: 'draft',
            name: 'Brouillon',
          id_for_label: 'description',
          html_name: 'description',
          label: 'Description',
          value: '',
          label: 'Localisation',
    ...mapGetters('feature_type', ['feature_type']),
    ...mapState(['user', 'USER_LEVEL_PROJECTS']),
    ...mapState('projects', ['project']),
    ...mapState('map', ['basemaps']),
    ...mapState('feature', [
      'attachmentFormset',
      'linkedFormset',
      'features',
      'extra_form',
      'statusChoices',
    field_title() {
      if (this.feature_type) {
        if (this.feature_type.title_optional) {
          return 'field';
leandro's avatar
leandro committed
        }
      }
      return 'required field';
leandro's avatar
leandro committed
    },

    currentRouteName() {
      return this.$route.name;
    },
      return this.$store.state.feature.current_feature;
    orderedCustomFields() {
      return [...this.extra_form].sort((a, b) => a.position - b.position);
    geoRefFileLabel() {
      if (this.file) {
        return this.file.name;
      }
      return 'Sélectionner une image ...';
    selected_status: {
      get() {
        return this.form.status.value;
      },
      set(newValue) {
        this.form.status.value = newValue;
        this.updateStore();
      },
    },

    allowedStatusChoices() {
      if (this.project) {
        const isModerate = this.project.moderation;
        const userStatus = this.USER_LEVEL_PROJECTS[this.project.slug];
Timothee P's avatar
Timothee P committed
        const isOwnFeature = this.feature
          ? this.feature.creator === this.user.id //* prevent undefined feature
          : false; //* si le contributeur est l'auteur du signalement
          //* si admin, modérateur ou super contributeur, statuts toujours disponible: Brouillon, Publié, Archivé
          userStatus === 'Modérateur' ||
          userStatus === 'Administrateur projet' ||
          (userStatus === 'Super Contributeur' && !isModerate)
          return this.statusChoices.filter((el) => el.value !== 'pending');
        } else if (userStatus === 'Super Contributeur' && isModerate) {
            (el) => el.value === 'draft' || el.value === 'pending'
        } else if (userStatus === 'Contributeur') {
          //* cas particuliers du contributeur
            this.currentRouteName === 'ajouter-signalement' ||
            //* même cas à l'ajout d'une feature ou si feature n'a pas été créé par le contributeur
            return isModerate
              ? this.statusChoices.filter(
                (el) => el.value === 'draft' || el.value === 'pending'
              )
              : this.statusChoices.filter(
                (el) => el.value === 'draft' || el.value === 'published'
              );
          } else {
            //* à l'édition d'une feature et si le contributeur est l'auteur de la feature
            return isModerate
              ? this.statusChoices.filter(
                (el) => el.value !== 'published' //* toutes sauf "Publié"
              )
                (el) => el.value !== 'pending' //* toutes sauf "En cours de publication"
              );
      return [];
  created() {
    this.$store.commit(
      'feature_type/SET_CURRENT_FEATURE_TYPE_SLUG',
      this.$route.params.slug_type_signal
    );
    //* empty previous feature data, not emptying by itself since it doesn't update by itself anymore
    if (this.currentRouteName === 'ajouter-signalement') {
      this.$store.commit('feature/SET_CURRENT_FEATURE', []);
    }

    if (this.$route.params.slug_signal) {
      this.getFeatureAttachments();
      this.getLinkedFeatures();
    }
  },

  mounted() {
    let promises = [
      this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug),
Timothee P's avatar
Timothee P committed
      this.$store.dispatch('projects/GET_PROJECT_INFO', this.$route.params.slug),
    ];
    if (this.$route.params.slug_signal) {
      promises.push(
        this.$store.dispatch('feature/GET_PROJECT_FEATURE', {
          project_slug: this.$route.params.slug,
          feature_id: this.$route.params.slug_signal,
        })
      );
    }

    Promise.all(promises).then(() => {
      this.initForm();
      this.initMap();
      this.onFeatureTypeLoaded();
      this.initExtraForms(this.feature);

      setTimeout(
        function () {
          mapUtil.addGeocoders(this.$store.state.configuration);
        }.bind(this),
        1000
      );
    });
  },

  destroyed() {
    //* be sure that previous Formset have been cleared for creation
    this.$store.commit('feature/CLEAR_ATTACHMENT_FORM');
    this.$store.commit('feature/CLEAR_LINKED_FORM');
    this.$store.commit('feature/CLEAR_EXTRA_FORM');
  },

    isOffline() {
      return navigator.onLine == false;
    initForm() {
      if (this.currentRouteName === 'editer-signalement') {
        for (let key in this.feature) {
          if (key && this.form[key]) {
            if (key === 'status') {
              const value = this.feature[key];
              this.form[key].value = this.statusChoices.find(
                (key) => key.value === value
              );
            } else {
              this.form[key].value = this.feature[key];
            }
          }
        }
        this.updateStore();
DESPRES Damien's avatar
DESPRES Damien committed
    create_point_geoposition() {
      function success(position) {
        const latitude = position.coords.latitude;
        const longitude = position.coords.longitude;
DESPRES Damien's avatar
DESPRES Damien committed

        var layer = L.circleMarker([latitude, longitude]);
        this.add_layer_call_back(layer);
DESPRES Damien's avatar
DESPRES Damien committed
        this.map.setView([latitude, longitude]);
      }

      function error(err) {
        this.erreurGeolocalisationMessage = err.message;
        if (err.message === 'User denied geolocation prompt') {
Timothee P's avatar
Timothee P committed
          this.erreurGeolocalisationMessage =
Timothee P's avatar
Timothee P committed
            "La géolocalisation a été désactivée par l'utilisateur";
DESPRES Damien's avatar
DESPRES Damien committed
      }
      this.erreurGeolocalisationMessage = null;
DESPRES Damien's avatar
DESPRES Damien committed
      if (!navigator.geolocation) {
        this.erreurGeolocalisationMessage =
          "La géolocalisation n'est pas supportée par votre navigateur.";
DESPRES Damien's avatar
DESPRES Damien committed
      } else {
        navigator.geolocation.getCurrentPosition(
          success.bind(this),
          error.bind(this)
        );
DESPRES Damien's avatar
DESPRES Damien committed
      }
    },
    toggleGeoRefModal() {
      if (this.showGeoRef) {
        //* when popup closes, empty form
        this.erreurUploadMessage = '';
        this.file = null;
      }
      this.showGeoRef = !this.showGeoRef;
    },

DESPRES Damien's avatar
DESPRES Damien committed
    handleFileUpload() {
      this.erreurUploadMessage = '';
DESPRES Damien's avatar
DESPRES Damien committed
      this.file = this.$refs.file.files[0];
    },
DESPRES Damien's avatar
DESPRES Damien committed
      const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}exif-geom-reader/`;
      let formData = new FormData();
      formData.append('image_file', this.file);
            'Content-Type': 'multipart/form-data',
          if (response.data.geom.indexOf('POINT') >= 0) {
            let regexp = /POINT\s\((.*)\s(.*)\)/;
            let arr = regexp.exec(response.data.geom);
            let json = {
              type: 'Feature',
              geometry: {
                type: 'Point',
                coordinates: [parseFloat(arr[1]), parseFloat(arr[2])],
DESPRES Damien's avatar
DESPRES Damien committed
              },
              properties: {},
DESPRES Damien's avatar
DESPRES Damien committed
            };
            this.updateMap(json);
            this.updateGeomField(json);
DESPRES Damien's avatar
DESPRES Damien committed
            // Set Attachment
              title: 'Localisation',
              info: '',
              id: 'loc',
              attachment_file: this.file.name,
              fileToImport: this.file,
DESPRES Damien's avatar
DESPRES Damien committed
          }
DESPRES Damien's avatar
DESPRES Damien committed
        })
          console.error({ error });
          if (error && error.response && error.response) {
            this.erreurUploadMessage = error.response.data.error;
          } else {
            this.erreurUploadMessage =
              "Une erreur est survenue pendant l'import de l'image géoréférencée";
          }
DESPRES Damien's avatar
DESPRES Damien committed
        });
    },
    initExtraForms(feature) {
      function findCurrentValue(label) {
        const field = feature.feature_data.find((el) => el.label === label);
        return field ? field.value : null;
      let extraForm = this.feature_type.customfield_set.map((field) => {
        return {
          ...field,
          //* add value field to extra forms from feature_type and existing values if feature is defined
          value:
            feature && feature.feature_data
              ? findCurrentValue(field.label)
              : null,
      this.$store.commit('feature/SET_EXTRA_FORM', extraForm);
    add_attachement_formset() {
      this.$store.commit('feature/ADD_ATTACHMENT_FORM', {
        dataKey: this.attachmentDataKey,
      }); // * create an object with the counter in store
      this.attachmentDataKey += 1; // * increment counter for key in v-for
    addAttachment(attachment) {
      this.$store.commit('feature/ADD_ATTACHMENT_FORM', {
        dataKey: this.attachmentDataKey,
        title: attachment.title,
        attachment_file: attachment.attachment_file,
        info: attachment.info,
        fileToImport: attachment.fileToImport,
        id: attachment.id,
      });
      this.attachmentDataKey += 1;
    addExistingAttachementFormset(attachementFormset) {
      for (const attachment of attachementFormset) {
        this.addAttachment(attachment);
    add_linked_formset() {
      this.$store.commit('feature/ADD_LINKED_FORM', {
        dataKey: this.linkedDataKey,
      }); // * create an object with the counter in store
      this.linkedDataKey += 1; // * increment counter for key in v-for
    addExistingLinkedFormset(linkedFormset) {
      for (const linked of linkedFormset) {
        this.$store.commit('feature/ADD_LINKED_FORM', {
          dataKey: this.linkedDataKey,
          relation_type: linked.relation_type,
          feature_to: linked.feature_to,
        });
        this.linkedDataKey += 1;
      }
    },
      this.$store.commit('feature/UPDATE_FORM', {
        title: this.form.title.value,
        status: this.form.status.value,
        description: this.form.description,
        geometry: this.form.geom.value,
        feature_id: this.feature ? this.feature.feature_id : '',
      if (this.form.title.value) {
        this.form.title.errors = [];
        !this.form.title.errors.includes('Veuillez compléter ce champ.')
        this.form.title.errors.push('Veuillez compléter ce champ.');
          .getElementById('errorlist-title')
          .scrollIntoView({ block: 'end', inline: 'nearest' });
      }
      return false;
    },

    checkFormGeom() {
      if (this.form.geom.value) {
        this.form.geom.errors = [];
        return true;
      } else if (
        !this.form.geom.errors.includes('Valeur géométrique non valide.')
        this.form.geom.errors.push('Valeur géométrique non valide.');
          .getElementById('errorlist-geom')
          .scrollIntoView({ block: 'end', inline: 'nearest' });
    checkAddedForm() {
      let isValid = true; //* fallback if all customForms returned true
      if (this.$refs.attachementForm) {
        for (const attachementForm of this.$refs.attachementForm) {
          if (attachementForm.checkForm() === false) {
            isValid = false;
          }
        }
      }
      if (this.$refs.linkedForm) {
        for (const linkedForm of this.$refs.linkedForm) {
          if (linkedForm.checkForm() === false) {
            isValid = false;
          }
        }
      }
      return isValid;
    },

      let is_valid = true;
      if (!this.feature_type.title_optional) {
        is_valid =
          this.checkFormTitle() &&
          this.checkFormGeom() &&
          this.checkAddedForm();
      } else {
        is_valid = this.checkFormGeom() && this.checkAddedForm();
leandro's avatar
leandro committed
      }
        //* in a moderate project, at edition of a published feature by someone else than admin or moderator, switch published status to draft.
          this.currentRouteName === 'editer-signalement' &&
          this.form.status.value.value === 'published' &&
          !this.permissions.is_project_administrator &&
          !this.permissions.is_project_moderator
          this.form.status.value = { name: 'Brouillon', value: 'draft' };
          this.updateStore();
        this.$store.dispatch('feature/SEND_FEATURE', this.currentRouteName);
    //* ************* MAP *************** *//

DESPRES Damien's avatar
DESPRES Damien committed
      var geomLeaflet = {
        point: 'circlemarker',
        linestring: 'polyline',
        polygon: 'polygon',
DESPRES Damien's avatar
DESPRES Damien committed
      var geomType = this.feature_type.geom_type;
DESPRES Damien's avatar
DESPRES Damien committed
      var drawConfig = {
        polygon: false,
        marker: false,
        polyline: false,
        rectangle: false,
        circle: false,
        circlemarker: false,
      };
      drawConfig[geomLeaflet[geomType]] = true;
DESPRES Damien's avatar
DESPRES Damien committed

      L.drawLocal = {
        draw: {
          toolbar: {
            actions: {
              title: 'Annuler le dessin',
              text: 'Annuler',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            finish: {
              title: 'Terminer le dessin',
              text: 'Terminer',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            undo: {
              title: 'Supprimer le dernier point dessiné',
              text: 'Supprimer le dernier point',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            buttons: {
              polyline: 'Dessiner une polyligne',
              polygon: 'Dessiner un polygone',
              rectangle: 'Dessiner un rectangle',
              circle: 'Dessiner un cercle',
              marker: 'Dessiner une balise',
              circlemarker: 'Dessiner un point',
DESPRES Damien's avatar
DESPRES Damien committed
          },
          handlers: {
            circle: {
              tooltip: {
                start: 'Cliquer et glisser pour dessiner le cercle.',
              radius: 'Rayon',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            circlemarker: {
              tooltip: {
                start: 'Cliquer sur la carte pour placer le point.',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            marker: {
              tooltip: {
                start: 'Cliquer sur la carte pour placer la balise.',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            polygon: {
              tooltip: {
                start: 'Cliquer pour commencer à dessiner.',
                cont: 'Cliquer pour continuer à dessiner.',
                end: 'Cliquer sur le premier point pour terminer le dessin.',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            polyline: {
              error: '<strong>Error:</strong> shape edges cannot cross!',
DESPRES Damien's avatar
DESPRES Damien committed
              tooltip: {
                start: 'Cliquer pour commencer à dessiner.',
                cont: 'Cliquer pour continuer à dessiner.',
                end: 'Cliquer sur le dernier point pour terminer le dessin.',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            rectangle: {
              tooltip: {
                start: 'Cliquer et glisser pour dessiner le rectangle.',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            simpleshape: {
              tooltip: {
                end: 'Relâcher la souris pour terminer de dessiner.',
DESPRES Damien's avatar
DESPRES Damien committed
        },
        edit: {
          toolbar: {
            actions: {
              save: {
                title: 'Sauver les modifications',
                text: 'Sauver',
DESPRES Damien's avatar
DESPRES Damien committed
              },
              cancel: {
                  'Annuler la modification, annule toutes les modifications',
                text: 'Annuler',
DESPRES Damien's avatar
DESPRES Damien committed
              },
              clearAll: {
                title: "Effacer l'objet",
                text: 'Effacer',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            buttons: {
              edit: "Modifier l'objet",
              editDisabled: 'Aucun objet à modifier',
              remove: "Supprimer l'objet",
              removeDisabled: 'Aucun objet à supprimer',
DESPRES Damien's avatar
DESPRES Damien committed
          },
          handlers: {
            edit: {
              tooltip: {
                text: "Faites glisser les marqueurs ou les balises pour modifier l'élément.",
                subtext: 'Cliquez sur Annuler pour annuler les modifications..',
DESPRES Damien's avatar
DESPRES Damien committed
            },
            remove: {
              tooltip: {
                text: 'Cliquez sur un élément pour le supprimer.',
DESPRES Damien's avatar
DESPRES Damien committed
      this.drawnItems = new L.FeatureGroup();
      this.map.addLayer(this.drawnItems);

      this.drawControlFull = new L.Control.Draw({
        position: 'topright',
DESPRES Damien's avatar
DESPRES Damien committed
        edit: {
          featureGroup: this.drawnItems,
DESPRES Damien's avatar
DESPRES Damien committed
        },
        draw: drawConfig,
DESPRES Damien's avatar
DESPRES Damien committed

      this.drawControlEditOnly = new L.Control.Draw({
        position: 'topright',
DESPRES Damien's avatar
DESPRES Damien committed
        edit: {
          featureGroup: this.drawnItems,
DESPRES Damien's avatar
DESPRES Damien committed
        },
      if (this.currentRouteName === 'editer-signalement') {
DESPRES Damien's avatar
DESPRES Damien committed
        this.map.addControl(this.drawControlEditOnly);
      } else {
        this.map.addControl(this.drawControlFull);
      }
      this.changeMobileBtnOrder();
        'draw:created',
        function (e) {
          var layer = e.layer;
          this.add_layer_call_back(layer);
        }.bind(this)
      );
DESPRES Damien's avatar
DESPRES Damien committed
      //var wellknown;// TODO Remplacer par autre chose

        'draw:edited',
        function (e) {
          var layers = e.layers;
          let self = this;
          layers.eachLayer(function (layer) {
            self.updateGeomField(layer.toGeoJSON());
          });
        }.bind(this)
      );

      this.map.on(
        'draw:deleted',
        function () {
          this.drawControlEditOnly.remove(this.map);
          this.drawControlFull.addTo(this.map);
          this.updateGeomField('');
          if (geomType === 'point') {
            this.erreurGeolocalisationMessage = '';
DESPRES Damien's avatar
DESPRES Damien committed
    },
    updateMap(geomFeatureJSON) {
      if (this.drawnItems) this.drawnItems.clearLayers();
DESPRES Damien's avatar
DESPRES Damien committed
      var geomType = this.feature_type.geom_type;
      if (geomFeatureJSON) {
Timothee P's avatar
Timothee P committed
        var geomJSON = flip(geomFeatureJSON.geometry);
        if (geomType === 'point') {
          L.circleMarker(geomJSON.coordinates).addTo(this.drawnItems);
        } else if (geomType === 'linestring') {
          L.polyline(geomJSON.coordinates).addTo(this.drawnItems);
        } else if (geomType === 'polygon') {
          L.polygon(geomJSON.coordinates).addTo(this.drawnItems);
DESPRES Damien's avatar
DESPRES Damien committed
        }
Timothee P's avatar
Timothee P committed
        this.map.fitBounds(this.drawnItems.getBounds(), { padding: [25, 25] });
DESPRES Damien's avatar
DESPRES Damien committed
      } else {
        this.map.setView(
          this.$store.state.configuration.DEFAULT_MAP_VIEW.center,
          this.$store.state.configuration.DEFAULT_MAP_VIEW.zoom
        );
    updateGeomField(newGeom) {
      this.form.geom.value = newGeom.geometry;
      this.updateStore();
DESPRES Damien's avatar
DESPRES Damien committed
    },
      var mapDefaultViewCenter =
        this.$store.state.configuration.DEFAULT_MAP_VIEW.center;
      var mapDefaultViewZoom =
        this.$store.state.configuration.DEFAULT_MAP_VIEW.zoom;