您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mapSection.vue 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div>
  3. <gmap-autocomplete
  4. class="form-control mb-3 uniInput"
  5. @place_changed="setPlace"
  6. :disabled="!canEdit"
  7. >*</gmap-autocomplete>
  8. <GmapMap
  9. :center="mapCenter"
  10. :zoom="mapZoom"
  11. map-type-id="terrain"
  12. style="width: 100%; height: 500px"
  13. ref="map"
  14. >
  15. <GmapMarker
  16. v-if="this.place"
  17. :position="mapCenter"
  18. :clickable="true"
  19. :draggable="false"
  20. :disabled="!canEdit"
  21. />
  22. </GmapMap>
  23. </div>
  24. </template>
  25. <script>
  26. /* eslint-disable */
  27. import { gmapApi } from "vue2-google-maps";
  28. export default {
  29. computed: {
  30. google: gmapApi,
  31. },
  32. props: {
  33. savedCoords: { default: "" },
  34. canEdit: { default: true },
  35. },
  36. data() {
  37. return {
  38. place: null,
  39. mapCenter: { lat: -26.195246, lng: 28.034088 },
  40. mapZoom: 11,
  41. streetNumber: "",
  42. streetName: "",
  43. suburb: "",
  44. city: "",
  45. province: "",
  46. country: "",
  47. postalCode: "",
  48. url: "",
  49. coords: {},
  50. };
  51. },
  52. methods: {
  53. setPlace(place) {
  54. this.place = place;
  55. this.mapCenter = place.geometry.location;
  56. this.mapZoom = 17;
  57. this.streetNumber = "";
  58. this.streetName = "";
  59. this.suburb = "";
  60. this.city = "";
  61. this.province = "";
  62. this.country = "";
  63. this.postalCode = "";
  64. this.url = "";
  65. this.coords = {};
  66. for (let i = 0; i < place.address_components.length; i++) {
  67. if (place.address_components[i].types[0] === "street_number") {
  68. this.streetNumber = place.address_components[i].long_name;
  69. }
  70. if (place.address_components[i].types[0] === "route") {
  71. this.streetName = place.address_components[i].long_name;
  72. }
  73. if (place.address_components[i].types[0] === "sublocality_level_1") {
  74. this.suburb = place.address_components[i].long_name;
  75. }
  76. if (place.address_components[i].types[0] === "locality") {
  77. this.city = place.address_components[i].long_name;
  78. }
  79. if (
  80. place.address_components[i].types[0] === "administrative_area_level_1"
  81. ) {
  82. this.province = place.address_components[i].long_name;
  83. }
  84. if (place.address_components[i].types[0] === "country") {
  85. this.country = place.address_components[i].long_name;
  86. }
  87. if (place.address_components[i].types[0] === "postal_code") {
  88. this.postalCode = place.address_components[i].long_name;
  89. }
  90. this.url = place.url;
  91. }
  92. this.$emit("map-location", {
  93. streetNumber: this.streetNumber,
  94. streetName: this.streetName,
  95. suburb: this.suburb,
  96. city: this.city,
  97. province: this.province,
  98. country: this.country,
  99. postalCode: this.postalCode,
  100. url: this.url,
  101. });
  102. },
  103. },
  104. watch: {
  105. savedCoords: {
  106. immediate: true,
  107. handler(val, oldVal) {
  108. if (val) {
  109. var array = val.split(",");
  110. this.mapCenter = {
  111. lat: Number(array[0]),
  112. lng: Number(array[1]),
  113. };
  114. this.mapZoom = 17;
  115. }
  116. },
  117. },
  118. },
  119. };
  120. </script>
  121. <style lang="scss" scoped></style>