Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

directions.vue 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="container">
  3. <div class="row">
  4. <div class="col">
  5. <label v-if="startAddress === null" class="uniSelectLabel" for="weekInfoRegionSelect"
  6. >Select</label
  7. >
  8. <select v-model="startAddress" class="form-control mb-3" @change="calcRoute()">
  9. <optgroup label="Cities">
  10. <option value="-29.087217,26.154898">Bloemfontein</option>
  11. <option value="-33.918861, 18.423300">Cape Town</option>
  12. <option value="-29.883333, 31.049999">Durban</option>
  13. <option value="-33.0153, 27.9116">East London</option>
  14. <option value="-33.977074, 22.457581">George</option>
  15. <option value="-26.195246, 28.034088">Johannesburg</option>
  16. <option value="-25.4745, 30.9703">Nelspruit</option>
  17. <option value="-23.9045, 29.4689">Polokwane</option>
  18. <option value="-33.9180, 25.5701">Port Elizabeth</option>
  19. <option value="-25.731340, 28.218370">Pretoria</option>
  20. <option value="-28.44776, 21.25612">Upington</option>
  21. </optgroup>
  22. <optgroup label="Airports">
  23. <option value="-26.13916667, 28.24611111">OR Tambo</option>
  24. <option value="-29.61444444, 31.11638889">King Shaka</option>
  25. <option value="-33.9843, 25.6170">Port Elizabeth</option>
  26. <option value="-33.96944444, 18.59722222">Cape Town</option>
  27. </optgroup>
  28. </select>
  29. <GmapMap
  30. :center="{ lat: -26.195246, lng: 28.034088 }"
  31. :zoom="7"
  32. map-type-id="terrain"
  33. style="width: 100%; height: 500px"
  34. ref="map"
  35. >
  36. </GmapMap>
  37. <div style="max-height:500px; overflow:auto">
  38. <table class="table table-sm">
  39. <tr>
  40. <td colspan="4">{{ overallRoute }}</td>
  41. </tr>
  42. <tr v-for="(direction, i) in directionSteps" :key="i">
  43. <td></td>
  44. <td>{{ i + 1 + "." }}</td>
  45. <td style="max-width:200px">
  46. <p v-html="direction.instructions" style="font-size:12px"></p>
  47. </td>
  48. <td>
  49. <p style="font-size:12px">{{ direction.distance.text }}</p>
  50. </td>
  51. </tr>
  52. </table>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. /* eslint-disable */
  60. import { gmapApi } from "vue2-google-maps";
  61. export default {
  62. computed: {
  63. google: gmapApi,
  64. directionsRenderer() {
  65. return new google.maps.DirectionsRenderer();
  66. }
  67. },
  68. props: {
  69. resortCoords: {}
  70. },
  71. data() {
  72. return {
  73. directionService: {},
  74. startAddress: null,
  75. directionSteps: [],
  76. overallRoute: ""
  77. };
  78. },
  79. methods: {
  80. calcRoute() {
  81. var resortCoords = this.resortCoords.split(",");
  82. var resortLatLng = new google.maps.LatLng({
  83. lat: parseFloat(resortCoords[1]),
  84. lng: parseFloat(resortCoords[0])
  85. });
  86. var startCoords = this.startAddress.split(",");
  87. var startLatLng = new google.maps.LatLng({
  88. lat: parseFloat(startCoords[0]),
  89. lng: parseFloat(startCoords[1])
  90. });
  91. var LatLng = new google.maps.LatLng({
  92. lat: -29.087217,
  93. lng: 26.154898
  94. });
  95. this.directionsService = new google.maps.DirectionsService();
  96. // var map = this.$refs.map.$mapObject;
  97. // this.directionsRenderer.setMap(map);
  98. // var start = document.getElementById("start").value;
  99. var end = "joplin, mo";
  100. var request = {
  101. origin: startLatLng,
  102. destination: resortLatLng,
  103. travelMode: "DRIVING"
  104. };
  105. this.directionsService.route(request, (result, status) => {
  106. if (status == "OK") {
  107. this.directionSteps = result.routes[0].legs[0].steps;
  108. console.log(result.routes[0].legs[0]);
  109. this.overallRoute =
  110. result.routes[0].legs[0].distance.text +
  111. ". About " +
  112. result.routes[0].legs[0].duration.text;
  113. this.directionsRenderer.setMap(this.$refs.map.$mapObject);
  114. this.directionsRenderer.setDirections(result);
  115. }
  116. });
  117. }
  118. }
  119. };
  120. </script>
  121. <style lang="scss" scoped>
  122. .uniSelectLabel {
  123. position: absolute;
  124. z-index: 2;
  125. margin-left: 15px;
  126. margin-top: 7px;
  127. font-family: "muli";
  128. font-size: 15px;
  129. color: rgb(118, 118, 118);
  130. }
  131. </style>