route.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view>
  3. <u-tabs :list="tab" name="markerName" active-color="#c74547" :is-scroll="false" :current="current" @change="change"></u-tabs>
  4. <map class="map" v-if="item.shapeType == 'polyline'" :latitude="item.lat" :longitude="item.lng" scale="13" :polyline="polyline" show-compass="true"></map>
  5. <map class="map" v-if="item.shapeType == 'polygon'" :latitude="item.lat" :longitude="item.lng" scale="12" :polygons="polygon" show-compass="true"></map>
  6. <map class="map" v-if="item.shapeType == 'circle'" :latitude="item.lat" :longitude="item.lng" scale="13" :circles="circles" show-compass="true"></map>
  7. <map class="map" v-if="item.shapeType == 'marker'" :latitude="item.lat" :longitude="item.lng" scale="13" :markers="markers" show-compass="true"></map>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. item: {},
  15. tab: [],
  16. current: 0,
  17. markers: [],
  18. polyline: [
  19. {
  20. arrowLine: true,
  21. width: 12,
  22. color: '#4CAF50',
  23. points: []
  24. }
  25. ],
  26. polygon: [
  27. {
  28. strokeWidth: 5,
  29. strokeColor: '#4CAF50',
  30. fillColor: '#03a9f482',
  31. points: []
  32. }
  33. ],
  34. circles: [
  35. {
  36. strokeWidth: 3,
  37. color: '#4CAF50',
  38. fillColor: '#03a9f482'
  39. }
  40. ]
  41. };
  42. },
  43. onLoad(e) {
  44. this.getData(e.id);
  45. },
  46. methods: {
  47. change(index) {
  48. this.current = index;
  49. this.refresh();
  50. },
  51. //获取数据
  52. getData(id) {
  53. this.$http.request({
  54. url: this.$http.urls.getMarkerList + id,
  55. success: res => {
  56. console.log('asd:' + JSON.stringify(res));
  57. this.tab = res.data.data.list;
  58. this.tab.forEach(item => {
  59. item.locationSet = JSON.parse(item.locationSet);
  60. });
  61. this.refresh();
  62. }
  63. });
  64. },
  65. //刷新数据
  66. refresh() {
  67. this.item = this.tab[this.current];
  68. if (this.item.shapeType == 'polyline') {
  69. this.polyline[0].points = [];
  70. this.item.locationSet.forEach(l => {
  71. this.polyline[0].points.push({ latitude: l.lat, longitude: l.lng });
  72. });
  73. }
  74. if (this.item.shapeType == 'polygon') {
  75. this.polygon[0].points = [];
  76. this.item.locationSet.forEach(l => {
  77. this.polygon[0].points.push({ latitude: l.lat, longitude: l.lng });
  78. });
  79. }
  80. if (this.item.shapeType == 'circle') {
  81. this.circles[0].latitude = this.item.locationSet.lat;
  82. this.circles[0].longitude = this.item.locationSet.lng;
  83. this.circles[0].radius = this.item.radius;
  84. }
  85. if (this.item.shapeType == 'marker') {
  86. this.markers = [];
  87. let iconPictures = '';
  88. if (this.item.iconPictures != null && this.item.iconPictures != '') {
  89. iconPictures = this.$http.urls.ip + this.item.iconPictures;
  90. }
  91. this.item.locationSet.forEach(l => {
  92. this.markers.push({
  93. latitude: l.lat,
  94. longitude: l.lng,
  95. width: 45,
  96. height: 65,
  97. iconPath: iconPictures,
  98. callout: {
  99. display: 'ALWAYS',
  100. content: this.tab[this.current].markerName,
  101. padding: 7,
  102. bgColor: '#4CAF50',
  103. borderRadius: 5,
  104. color: '#ffffff'
  105. }
  106. });
  107. });
  108. }
  109. }
  110. }
  111. };
  112. </script>
  113. <style lang="scss">
  114. .map {
  115. position: fixed;
  116. width: 100%;
  117. height: 100%;
  118. top: 40px;
  119. }
  120. </style>