Boundary.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div v-if="paths.length">
  3. <bm-polygon v-for="(path, index) of paths" :key="index" :path="path" :stroke-color="strokeColor" :stroke-weight="strokeWeight"
  4. :stroke-opacity="strokeOpacity" :stroke-style="strokeStyle" :fill-opacity="fillOpacity" :fill-color="fillColor" :mass-clear="massClear"
  5. :clicking="clicking" @click="$emit('click', $event)" @dblclick="$emit('dblclick', $event)" @mousedown="$emit('mousedown', $event)"
  6. @mouseup="$emit('mouseup', $event)" @mouseout="$emit('mouseout', $event)" @mouseover="$emit('mouseover', $event)"
  7. @remove="$emit('remove', $event)" />
  8. </div>
  9. </template>
  10. <script>
  11. import BmPolygon from '../overlays/Polygon.vue'
  12. import commonMixin from '../base/mixins/common.js'
  13. // import abstractMixin from '../base/mixins/abstract.js'
  14. export default {
  15. mixins: [
  16. commonMixin('abstract')
  17. ],
  18. emits: ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseout', 'mouseover', 'remove', 'load'],
  19. props: ['name', 'strokeColor', 'strokeWeight', 'strokeOpacity', 'strokeStyle', 'fillColor', 'fillOpacity', 'massClear', 'clicking'],
  20. data() {
  21. return {
  22. paths: []
  23. }
  24. },
  25. components: {
  26. BmPolygon
  27. },
  28. watch: {
  29. name() {
  30. this.reload()
  31. }
  32. },
  33. methods: {
  34. load() {
  35. const { BMap, name } = this
  36. const bd = new BMap.Boundary()
  37. bd.get(name, data => {
  38. const paths = data.boundaries.map(boundary => (boundary || []).split(';')
  39. .map(point => (([lng, lat]) => ({ lng, lat }))(point.split(',').map(p => +p))))
  40. this.paths = paths;
  41. this.$emit('load', { boundaries: data.boundaries, paths: [...paths] });
  42. })
  43. }
  44. }
  45. }
  46. </script>