map.nvue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view>
  3. <map id="map1" :scale="1" ref="map1" style="width: 100%; height: 600rpx;" :latitude="latitude" :longitude="longitude" :markers="markers" :enable-zoom="true"></map>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. list: {
  10. type: Array,
  11. default: []
  12. }
  13. },
  14. data() {
  15. return {
  16. latitude: null,
  17. longitude: null,
  18. mainmap: null,
  19. markers: [],
  20. imgUrl: this.$mConfig.staticUrl
  21. };
  22. },
  23. computed: {},
  24. watch: {
  25. list(n) {
  26. if (n) {
  27. this.getMap();
  28. }
  29. }
  30. },
  31. created() {
  32. this.mainmap = uni.createMapContext('map1', this);
  33. },
  34. onShow() {},
  35. methods: {
  36. getMap() {
  37. let that = this
  38. this.longitude = this.list[0].tx_longitude;
  39. this.latitude = this.list[0].tx_latitude;
  40. let markers = [];
  41. this.list.forEach((val, index) => {
  42. markers.push({
  43. id: index,
  44. latitude: Number(val.tx_latitude),
  45. longitude: Number(val.tx_longitude),
  46. iconPath: that.imgUrl+'/map.png',
  47. width: 20,
  48. height: 20
  49. });
  50. });
  51. this.markers = markers;
  52. }
  53. }
  54. };
  55. </script>
  56. <style></style>