Ground.vue 1.5 KB

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