Copyright.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <script>
  2. import commonMixin from '../base/mixins/common.js'
  3. import {createSize} from '../base/factory.js'
  4. export default {
  5. name: 'bm-copyright',
  6. render () {},
  7. mixins: [commonMixin('control')],
  8. props: ['anchor', 'offset', 'copyright'],
  9. watch: {
  10. anchor () {
  11. this.reload()
  12. },
  13. offset () {
  14. this.reload()
  15. },
  16. copyright () {
  17. this.reload()
  18. }
  19. },
  20. methods: {
  21. load () {
  22. const {BMap, map, offset, anchor, updateCopyrightList} = this
  23. this.originInstance = new BMap.CopyrightControl({
  24. anchor: global[anchor],
  25. offset: offset && createSize(BMap, offset)
  26. })
  27. updateCopyrightList()
  28. map.addControl(this.originInstance)
  29. },
  30. updateCopyrightList () {
  31. const {BMap, map} = this
  32. const {removeCopyright, getCopyrightCollection} = this.originInstance
  33. const copyrightList = getCopyrightCollection()
  34. copyrightList && copyrightList.forEach(item => {
  35. removeCopyright(item.id)
  36. })
  37. this.copyright && this.copyright.forEach(item => {
  38. const bounds = item.bounds
  39. ? new BMap.Bounds(new BMap.Point(item.bounds.sw.lng, item.bounds.sw.lat), new BMap.Point(item.bounds.ne.lng, item.bounds.ne.lat))
  40. : map.getBounds()
  41. this.originInstance.addCopyright({
  42. id: item.id,
  43. content: item.content,
  44. bounds
  45. })
  46. this.originInstance.getCopyrightCollection()
  47. })
  48. }
  49. }
  50. }
  51. </script>