Skip to content
Snippets Groups Projects
EditingToolbar.vue 4.17 KiB
Newer Older
DESPRES Damien's avatar
DESPRES Damien committed
<template>
  <div class="editionToolbar">
    <div class="leaflet-bar">
      <a
        v-if="showDrawTool || isEditing"
        :class="{ active: isSnapEnabled }"
        :data-tooltip="`${ isSnapEnabled ? 'Désactiver' : 'Activer' } l'accrochage aux points`"
        data-position="top right"
        @click="toggleSnap"
      >
Timothee P's avatar
Timothee P committed
        <i
          class="magnet icon"
          aria-hidden="true"
        />
        <span class="sr-only">{{ isSnapEnabled ? 'Désactiver' : 'Activer' }} l'accrochage aux points</span>
      </a>

      <a
        v-if="showDrawTool"
        class="leaflet-draw-draw-polygon active"
        :title="
          editionService.geom_type === 'polygon' ? 'Dessiner un polygone' :
          editionService.geom_type === 'linestring' ? 'Dessiner une ligne' :
          'Dessiner un point'
        "
      >
        <img
          v-if="editionService.geom_type === 'linestring'"
          class="list-image-type"
          src="@/assets/img/line.png"
DESPRES Damien's avatar
DESPRES Damien committed
        >
        <img
          v-if="editionService.geom_type === 'point'"
          class="list-image-type"
          src="@/assets/img/marker.png"
        >
        <img
          v-if="editionService.geom_type === 'polygon'"
          class="list-image-type"
          src="@/assets/img/polygon.png"
        >
      </a>

      <div v-else>
Florent Lavelle's avatar
Florent Lavelle committed
        <a
          :class="{ active: isEditing }"
          @click="update"
        >
DESPRES Damien's avatar
DESPRES Damien committed
          <i class="edit outline icon" />
Florent Lavelle's avatar
Florent Lavelle committed
          <span class="sr-only">Modifier l'objet</span>
        </a>
        <a
          :class="{ active: isDeleting }"
          @click="deleteObj"
        >
Florent Lavelle's avatar
Florent Lavelle committed
          <i class="trash alternate outline icon" />
Florent Lavelle's avatar
Florent Lavelle committed
          <span class="sr-only">Supprimer l'objet</span>
        </a>
DESPRES Damien's avatar
DESPRES Damien committed
      </div>
    </div>
  </div>
</template>

<script>
import editionService from '@/services/edition-service';

export default {
Florent Lavelle's avatar
Florent Lavelle committed

DESPRES Damien's avatar
DESPRES Damien committed
  name: 'EditingToolbar',
Florent Lavelle's avatar
Florent Lavelle committed

DESPRES Damien's avatar
DESPRES Damien committed
  data() {
    return {
      editionService: editionService,
Florent Lavelle's avatar
Florent Lavelle committed
      isEditing: false,
DESPRES Damien's avatar
DESPRES Damien committed
    };
  },
Florent Lavelle's avatar
Florent Lavelle committed

DESPRES Damien's avatar
DESPRES Damien committed
  computed: {
    showDrawTool() {
      return this.editionService && this.editionService.editing_feature === undefined;
DESPRES Damien's avatar
DESPRES Damien committed
  methods: {
Florent Lavelle's avatar
Florent Lavelle committed
    update() {
DESPRES Damien's avatar
DESPRES Damien committed
      editionService.activeUpdateFeature();
Florent Lavelle's avatar
Florent Lavelle committed
      this.isDeleting = false;
      this.isEditing = true;
DESPRES Damien's avatar
DESPRES Damien committed
    },
Florent Lavelle's avatar
Florent Lavelle committed
    deleteObj() {
DESPRES Damien's avatar
DESPRES Damien committed
      editionService.activeDeleteFeature();
Florent Lavelle's avatar
Florent Lavelle committed
      this.isEditing = false;
      this.isDeleting = true;
DESPRES Damien's avatar
DESPRES Damien committed
    },
    toggleSnap() {
      if (this.isSnapEnabled) {
        editionService.removeSnapInteraction(this.map);
      } else {
        editionService.addSnapInteraction(this.map);
      }
      this.isSnapEnabled = !this.isSnapEnabled;
    }
DESPRES Damien's avatar
DESPRES Damien committed
  }
};
</script>

Florent Lavelle's avatar
Florent Lavelle committed
<style lang="less" scoped>

DESPRES Damien's avatar
DESPRES Damien committed
.editionToolbar{
  position: absolute;
  top: 80px;
Florent Lavelle's avatar
Florent Lavelle committed
  right: 6px;
Florent Lavelle's avatar
Florent Lavelle committed
  border: 2px solid rgba(0,0,0,.2);
Florent Lavelle's avatar
Florent Lavelle committed
  border-radius: 4px;
Florent Lavelle's avatar
Florent Lavelle committed
  background-clip: padding-box;
  padding: 0;
Florent Lavelle's avatar
Florent Lavelle committed
}
.leaflet-bar {
Florent Lavelle's avatar
Florent Lavelle committed

  a:first-child {
    border-top-left-radius: 2px;
    border-top-right-radius: 2px;
  }
  a:last-child {
    border-bottom-left-radius: 2px;
    border-bottom-right-radius: 2px;
    border-bottom: none;
  }

  a, .leaflet-control-layers-toggle {
    background-position: 50% 50%;
    background-repeat: no-repeat;
    display: block;
  }

  a {
    background-color: #fff;
    width: 30px;
    height: 30px;
    display: block;
    text-align: center;
    text-decoration: none;
    color: black;

    i {
      margin: 0;
      vertical-align: middle;
      &.magnet {
        transform: rotate(90deg);
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        opacity: .85;
      }
Florent Lavelle's avatar
Florent Lavelle committed
    }
  }

Florent Lavelle's avatar
Florent Lavelle committed
  .active {
    background-color: rgba(255, 145, 0, 0.904);
    color: #fff;

    i {
      font-weight: bold;
    }

    img {
      filter: invert(100%) sepia(0%) saturate(7500%) hue-rotate(282deg) brightness(105%) contrast(100%);
    }
  }

Florent Lavelle's avatar
Florent Lavelle committed
  .list-image-type {
    height: 20px;
    vertical-align: middle;
    margin: 5px 0 5px 0;
  }
  a:hover {
    cursor: pointer !important;
    background-color: #ebebeb !important;
  }
  a:focus {
    background-color: #ebebeb !important;
  }
DESPRES Damien's avatar
DESPRES Damien committed
</style>