Geolocation.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. import { deleteEmptyKey, getConfig } from '../base/util.js'
  6. export default {
  7. name: 'bm-geolocation',
  8. render() { },
  9. mixins: [commonMixin('control')],
  10. props: {
  11. anchor: {
  12. type: String
  13. },
  14. offset: {
  15. type: Object
  16. },
  17. showAddressBar: {
  18. type: Boolean
  19. },
  20. autoLocation: {
  21. type: Boolean
  22. },
  23. locationIcon: {
  24. type: Object
  25. }
  26. },
  27. watch: {
  28. anchor() {
  29. this.reload()
  30. },
  31. offset() {
  32. this.reload()
  33. },
  34. showAddressBar() {
  35. this.reload()
  36. },
  37. autoLocation() {
  38. this.reload()
  39. },
  40. locationIcon() {
  41. this.reload()
  42. }
  43. },
  44. methods: {
  45. load() {
  46. const { BMap, map, anchor, showAddressBar, autoLocation, locationIcon, offset } = this
  47. let geoLocationOption = {
  48. anchor: window[anchor],
  49. showAddressBar,
  50. enableAutoLocation: autoLocation,
  51. offset: offset && createSize(BMap, offset),
  52. locationIcon: locationIcon && createIcon(BMap, locationIcon)
  53. };
  54. deleteEmptyKey(geoLocationOption);
  55. switch (getConfig().type) {
  56. case 'WebGL':
  57. this.originInstance = new BMap.LocationControl(geoLocationOption)
  58. break;
  59. default:
  60. this.originInstance = new BMap.GeolocationControl(geoLocationOption)
  61. }
  62. bindEvents.call(this, this.originInstance)
  63. map.addControl(this.originInstance)
  64. }
  65. }
  66. }
  67. </script>