Control.vue 914 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <div>
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. import commonMixin from '../base/mixins/common.js'
  8. import { createSize } from '../base/factory.js'
  9. export default {
  10. name: 'bm-control',
  11. mixins: [commonMixin('control')],
  12. props: ['anchor', 'offset'],
  13. watch: {
  14. anchor(val) {
  15. this.originInstance.setAnchor(val)
  16. },
  17. offset(val) {
  18. this.originInstance.setOffset(val)
  19. }
  20. },
  21. methods: {
  22. load() {
  23. const { BMap, map, anchor, offset, $el } = this
  24. const Control = function () {
  25. this.defaultAnchor = window[anchor || 'BMAP_ANCHOR_TOP_LEFT']
  26. this.defaultOffset = createSize(BMap, offset)
  27. }
  28. Control.prototype = new BMap.Control()
  29. Control.prototype.initialize = map => map.getContainer().appendChild($el)
  30. this.originInstance = new Control(anchor, offset)
  31. map.addControl(this.originInstance)
  32. }
  33. }
  34. }
  35. </script>