Geolocation.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <script>
  2. import commonMixin from '../base/mixins/common.js'
  3. import bindEvents from '../base/bindEvent.js'
  4. import {createIcon, createSize} from '../base/factory.js'
  5. export default {
  6. name: 'bm-geolocation',
  7. render () {},
  8. mixins: [commonMixin('control')],
  9. props: {
  10. anchor: {
  11. type: String
  12. },
  13. offset: {
  14. type: Object
  15. },
  16. showAddressBar: {
  17. type: Boolean
  18. },
  19. autoLocation: {
  20. type: Boolean
  21. },
  22. locationIcon: {
  23. type: Object
  24. }
  25. },
  26. watch: {
  27. anchor () {
  28. this.reload()
  29. },
  30. offset () {
  31. this.reload()
  32. },
  33. showAddressBar () {
  34. this.reload()
  35. },
  36. autoLocation () {
  37. this.reload()
  38. },
  39. locationIcon () {
  40. this.reload()
  41. }
  42. },
  43. methods: {
  44. load () {
  45. const {BMap, map, anchor, showAddressBar, autoLocation, locationIcon, offset} = this
  46. this.originInstance = new BMap.GeolocationControl({
  47. anchor: global[anchor],
  48. showAddressBar,
  49. enableAutoLocation: autoLocation,
  50. offset: offset && createSize(BMap, offset),
  51. locationIcon: locationIcon && createIcon(BMap, locationIcon)
  52. })
  53. bindEvents.call(this, this.originInstance)
  54. map.addControl(this.originInstance)
  55. }
  56. }
  57. }
  58. </script>