map-control.vue 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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
<template>
  <div class="uni-map-control">
    <img
      :src="imgPath"
      :style="positionStyle"
      class="uni-map-control-icon"
      @click="handleClick"
    >
  </div>
</template>

<script>
import getRealPath from 'uni-platform/helpers/get-real-path'
export default {
  props: {
    id: {
      type: [Number, String],
      default: ''
    },
    position: {
      type: Object,
      required: true
    },
    iconPath: {
      type: String,
      required: true
    },
    clickable: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    imgPath () {
      return getRealPath(this.iconPath)
    },
    positionStyle () {
      let positionStyle = `top:${this.position.top || 0}px;left:${this.position.left || 0}px;`

      if (this.position.width) {
        positionStyle += `width:${this.position.width}px;`
      }
      if (this.position.height) {
        positionStyle += `height:${this.position.height}px;`
      }

      return positionStyle
    }
  },
  methods: {
    handleClick ($event) {
      if (this.clickable) {
        this.$parent.$trigger('controltap', $event, {
          controlId: this.id
        })
      }
      $event.stopPropagation()
    }
  }
}
</script>

<style>
.uni-map-control{
  position:absolute;
  width:0;
  height:0;
  top:0;
  left:0;
  z-index:999;
}
.uni-map-control-icon{
  position:absolute;
  max-width:initial;
}
</style>