view client/src/layers/Identify.vue @ 782:cb6dc630c702

client: improve identify code * Use mapState() instead of mapGetters() for simple access to a state of the store, without explicit getter.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 26 Sep 2018 14:57:35 +0200
parents 6d214b3bed35
children 1d8ccdb532de
line wrap: on
line source

<template>
    <div class="identifymenu">
        <div @click="collapse" class="d-flex flex-column ui-element minimizer">
            <div>
                <i class="fa fa-info"></i>
            </div>
        </div>
        <div :class="identifyStyle">
            <div v-if="!collapsed" class="card-body">
                <div class="headline">
                    <h4 class="card-title">Identified</h4>
                </div>
                <hr>
                <div class="d-flex flex-column">
                  <div v-for="feature of identifiedFeatures" :key="feature.getId()">
                    {{ feature.getId().replace(/[.][^.]*$/,"") /* cut away everything from the last . to the end */}}:
                    <small v-for="(value, key) in prepareProperties(feature)" :key="key">
                      <div v-if="value">{{key}}:{{value}}</div>
                    </small>
                  </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style lang="scss">
.identifymenu {
  position: relative;
  margin-right: $offset;
}
.identify {
  background-color: white;
  margin-left: $small-offset;
  opacity: $slight-transparent;
}

.identifycollapsed {
  height: $icon-height;
  width: $icon-width;
  transition: $transition-fast;
}

.identifyexpanded {
  min-height: $identify-height;
  width: $identify-width;
}

.minimizer {
  position: absolute;
  z-index: 2;
  right: 0;
  margin-top: $x-small-offset;
  border-radius: $border-radius;
  height: $icon-width;
  width: $icon-height;
}
</style>

<script>
import { mapState } from "vuex";

export default {
  name: "identify",
  data() {
    return {
      collapsed: true
    };
  },
  computed: {
    ...mapState("mapstore", ['identifiedFeatures']),
    identifyStyle() {
      return {
        "ui-element": true,
        card: true,
        identify: true,
        shadow: true,
        identifyexpanded: !this.collapsed,
        identifycollapsed: this.collapsed
      };
    }
  },
  methods: {
    collapse() {
      this.collapsed = !this.collapsed;
    },
    prepareProperties(feature) {
      // return dict object with propertyname:plainvalue prepared for display
      var properties = feature.getProperties();
      delete properties[feature.getGeometryName()];
      return properties;
    }
  }
};
</script>