routeInfo-getpoint.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <el-dialog
  3. :visible.sync="innerVisible"
  4. title="地图选点"
  5. :modal-append-to-body="true"
  6. :append-to-body="true"
  7. style="text-align: left"
  8. width="905px"
  9. top="5vh"
  10. :close-on-click-modal="false"
  11. >
  12. <el-amap
  13. ref="stationMap"
  14. vid="stationMap"
  15. :amap-manager="amapManager"
  16. :center="pointPosition"
  17. :zoom="zoom"
  18. :events="events"
  19. class="amap-demo"
  20. :plugin="plugins"
  21. style="width: 100%; height: 500px"
  22. >
  23. <!--站点及入口-->
  24. <el-amap-marker
  25. :zIndex="1"
  26. v-for="point in points"
  27. :key="point.id"
  28. :position="point.position"
  29. :title="point.title"
  30. :icon="point.icon"
  31. :events="markerEvents"
  32. :extData="point"
  33. ></el-amap-marker>
  34. </el-amap>
  35. <span slot="footer" class="dialog-footer">
  36. <div style="position: absolute; left: 20px; bottom: 20px">
  37. <el-select size="mini" v-model="selectedValue" @change="pointChange">
  38. <el-option
  39. v-for="point in points"
  40. :key="point.id"
  41. :label="point.title"
  42. :value="point.id">
  43. </el-option>
  44. </el-select>
  45. <el-input
  46. placeholder="当前经纬度"
  47. v-model="selectedPoint.location"
  48. style="width: 320px"
  49. size="mini"
  50. >
  51. <template slot="prepend">经纬度</template>
  52. <el-button slot="append" icon="el-icon-search" @click="handleRegeo" size="mini">定位</el-button>
  53. </el-input>
  54. <el-switch
  55. size="mini"
  56. v-model="ranging"
  57. @change="rangingChange"
  58. active-text="开启测距"
  59. inactive-text="关闭测距">
  60. </el-switch>
  61. </div>
  62. <el-button @click="cancel()">取 消</el-button>
  63. <el-button type="primary" @click="handleSelectPoint()">确 定</el-button>
  64. </span>
  65. </el-dialog>
  66. </template>
  67. <script>
  68. import Constant from "@/constant";
  69. import routeInfoApi from "@/api/bus/routeInfo";
  70. import SelectTree from "@/components/SelectTree";
  71. import companyInfoApi from "@/api/bus/companyInfo";
  72. import dataDictionaryApi from "@/api/sys/dataDictionary";
  73. import regionInfoApi from "@/api/base/regionInfo";
  74. import greenIcon from "@/assets/icons/green.svg";
  75. import redIcon from "@/assets/icons/red.svg";
  76. import stationIcon from "@/assets/icons/station.svg";
  77. import AMap from "vue-amap";
  78. let amapManager = new AMap.AMapManager();
  79. export default {
  80. props: ["visible"],
  81. computed: {
  82. innerVisible: {
  83. get: function() {
  84. return this.visible
  85. },
  86. set: function(val) {
  87. this.$emit('update:visible', val)
  88. }
  89. }
  90. },
  91. data() {
  92. return {
  93. points: [],
  94. selectedValue: "",
  95. selectedPoint: {},
  96. station: {},
  97. plugins: ["AMap.Scale", "AMap.OverView", "AMap.ToolBar", "AMap.MapType","AMap.RangingTool"],
  98. pointPosition: [112.240222, 30.337053],
  99. amapManager,
  100. zoom: 12,
  101. mapRuler: {},
  102. ranging: false,
  103. events: {
  104. init: (map)=>{
  105. const ruler = new window.AMap.RangingTool(map);
  106. this.mapRuler = ruler
  107. },
  108. click: (e) => {
  109. console.log(e);
  110. if(!this.ranging){
  111. var pt = e.lnglat; //点击选择新地址为中心点
  112. console.log(pt);
  113. this.pointPosition = [pt.lng, pt.lat];
  114. if(this.selectedPoint!=null){
  115. this.selectedPoint.position = [pt.lng,pt.lat];
  116. this.selectedPoint.location = pt.lng + "," + pt.lat;
  117. }
  118. }
  119. }
  120. },
  121. markerEvents: {
  122. click: (e) => {
  123. var point = e.target.w.extData;
  124. this.selectedValue = point.id;
  125. this.pointChange(this.selectedValue);
  126. }
  127. }
  128. }
  129. },
  130. methods: {
  131. cancel() {
  132. this.$emit("update:visible", false);
  133. },
  134. rangingChange(value) {
  135. if(value){
  136. this.mapRuler.turnOn();
  137. }
  138. else{
  139. this.mapRuler.turnOff();
  140. }
  141. },
  142. showPoint(row) {
  143. this.station = row;
  144. this.points = [];
  145. if (row.location != null && row.location.length > 0) {
  146. var arr = row.location.split(",");
  147. this.pointPosition = arr;
  148. this.points.push({
  149. id: row.id,
  150. type: "station",
  151. title: row.name,
  152. position: arr,
  153. icon: stationIcon,
  154. location: row.location
  155. });
  156. }
  157. else{
  158. this.points.push({
  159. id: row.id,
  160. type: "station",
  161. title: row.name,
  162. position: this.pointPosition,
  163. icon: stationIcon,
  164. location: this.pointPosition[0] + "," + this.pointPosition[1]
  165. });
  166. }
  167. this.selectedValue = row.id;
  168. this.selectedPoint = this.points[0];
  169. if(row.stationSubInfoList!=null){
  170. row.stationSubInfoList.forEach(subItem=>{
  171. var frontToEnd = subItem.direction=="1";
  172. this.points.push({
  173. id: subItem.id,
  174. type: "sub",
  175. title: row.name + "入口" + (frontToEnd ? "(起)" : "(终)"),
  176. position: [subItem.longitude,subItem.latitude],
  177. icon: frontToEnd ? greenIcon : redIcon,
  178. location: subItem.longitude + ',' + subItem.latitude
  179. });
  180. });
  181. }
  182. },
  183. handleRegeo() {
  184. var row = this.selectedPoint;
  185. if (row.location != null && row.location.length > 0) {
  186. var arr = row.location.split(",");
  187. row.position = arr;
  188. this.pointPosition = arr;
  189. }
  190. },
  191. handleSelectPoint() {
  192. //返回修改的站点及经纬度
  193. this.$emit("yes", this.points);
  194. this.$emit("update:visible", false);
  195. },
  196. pointChange(val) {
  197. console.log(val);
  198. for(var i=0;i<this.points.length;i++){
  199. if(this.points[i].id == val){
  200. this.selectedPoint = this.points[i];
  201. break;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. </script>
  208. <style>
  209. </style>