Ground.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <script>
  2. import commonMixin from '../base/mixins/common.js'
  3. import bindEvents from '../base/bindEvent.js'
  4. import { createBounds } from '../base/factory.js'
  5. import { deleteEmptyKey } from '../base/util.js'
  6. export default {
  7. name: 'bm-ground',
  8. render() { },
  9. mixins: [commonMixin('overlay')],
  10. props: {
  11. bounds: {
  12. type: Object
  13. },
  14. opacity: {
  15. type: Number
  16. },
  17. imageURL: {
  18. type: String
  19. },
  20. displayOnMinLevel: {
  21. type: Number
  22. },
  23. displayOnMaxLevel: {
  24. type: Number
  25. }
  26. },
  27. watch: {
  28. bounds: {
  29. handler(val) {
  30. const { BMap } = this
  31. this.originInstance.setBounds(createBounds(BMap, val))
  32. },
  33. deep: true
  34. },
  35. opacity(val) {
  36. this.originInstance.setOpacity(val)
  37. },
  38. imageURL(val) {
  39. this.originInstance.setImageURL(val)
  40. },
  41. displayOnMinLevel(val) {
  42. this.originInstance.setDisplayOnMinLevel(val)
  43. },
  44. displayOnMaxLevel(val) {
  45. this.originInstance.setDisplayOnMaxLevel(val)
  46. }
  47. },
  48. methods: {
  49. load() {
  50. const { BMap, map, bounds, opacity, imageURL, displayOnMinLevel, displayOnMaxLevel } = this
  51. let groundOption = {
  52. opacity,
  53. imageURL,
  54. displayOnMaxLevel,
  55. displayOnMinLevel
  56. };
  57. deleteEmptyKey(groundOption);
  58. const overlay = new BMap.GroundOverlay(bounds && createBounds(BMap, bounds), groundOption)
  59. // option 中配置 https 协议地址无法加载
  60. overlay.setImageURL(imageURL)
  61. this.originInstance = overlay
  62. bindEvents.call(this, overlay)
  63. map.addOverlay(overlay)
  64. }
  65. }
  66. }
  67. </script>