• 百度地图 获取某个区域的经纬度 baidu-map 地图绘制


     

    获取方法:

     

    代码:

    1. <template>
    2. <div class="app-container">
    3. <div style="margin-bottom:30px">
    4. <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="str"></el-input>
    5. </div>
    6. <div v-loading="loading" class="map">
    7. <baidu-map
    8. :scroll-wheel-zoom="true"
    9. :center="center"
    10. :zoom="zoom"
    11. @click="paintPolyline"
    12. @mousemove="syncPolyline"
    13. @rightclick="newPolyline"
    14. style="height:100%"
    15. >
    16. <bml-marker-clusterer :averageCenter="true">
    17. <div v-for="(item,index) in points" :key="index">
    18. <bm-marker :position="{lng: item.lng, lat: item.lat}" :dragging="true"></bm-marker>
    19. </div>
    20. </bml-marker-clusterer>
    21. <bm-control>
    22. <button @click="toggle('polyline')">{{ polyline.editing ? '停止绘制' : '开始绘制' }}</button>
    23. </bm-control>
    24. <bm-polyline :path="path" v-for="(path,index ) of polyline.paths" :key="index"></bm-polyline>
    25. </baidu-map>
    26. </div>
    27. </div>
    28. </template>
    29. <script>
    30. import { BaiduMap, BmControl, BmMarker, BmPolygon } from "vue-baidu-map";
    31. export default {
    32. components: {
    33. BaiduMap,
    34. BmControl,
    35. BmMarker,
    36. BmPolygon
    37. },
    38. data() {
    39. return {
    40. points: [],
    41. infoWindow: {},
    42. district: "杨浦区",
    43. // center: { lng: 121.650733, lat: 31.265339 }, //{ lng: 121.534222, lat: 31.290289 },
    44. center: { lng: 121.528622, lat: 31.264408 }, //{ lng: 121.534222, lat: 31.290289 },
    45. loading: false,
    46. companyName: "",
    47. zoom: 16.5,
    48. polyline: {
    49. editing: false,
    50. paths: []
    51. },
    52. str: "",
    53. points: [
    54. { lng: 121.515233, lat: 31.268376 },
    55. { lng: 121.524509, lat: 31.257652 },
    56. { lng: 121.522629, lat: 31.257261 },
    57. { lng: 121.523043, lat: 31.254998 },
    58. { lng: 121.522923, lat: 31.273299 },
    59. { lng: 121.52532, lat: 31.27039 },
    60. { lng: 121.527015, lat: 31.271303 },
    61. { lng: 121.531864, lat: 31.264064 },
    62. { lng: 121.558084, lat: 31.281966 },
    63. { lng: 121.549687, lat: 31.292906 },
    64. { lng: 121.557389, lat: 31.296668 },
    65. { lng: 121.529517, lat: 31.348762 },
    66. { lng: 121.529939, lat: 31.349406 }
    67. ]
    68. };
    69. },
    70. mounted() {},
    71. methods: {
    72. toggle(name) {
    73. this[name].editing = !this[name].editing;
    74. },
    75. syncPolyline(e) {
    76. if (!this.polyline.editing) {
    77. return;
    78. }
    79. const { paths } = this.polyline;
    80. if (!paths.length) {
    81. return;
    82. }
    83. const path = paths[paths.length - 1];
    84. if (!path.length) {
    85. return;
    86. }
    87. if (path.length === 1) {
    88. path.push(e.point);
    89. }
    90. this.$set(path, path.length - 1, e.point);
    91. },
    92. newPolyline(e) {
    93. if (!this.polyline.editing) {
    94. return;
    95. }
    96. const { paths } = this.polyline;
    97. if (!paths.length) {
    98. paths.push([]);
    99. }
    100. const path = paths[paths.length - 1];
    101. path.pop();
    102. if (path.length) {
    103. paths.push([]);
    104. }
    105. },
    106. paintPolyline(e) {
    107. if (!this.polyline.editing) {
    108. return;
    109. }
    110. const { paths } = this.polyline;
    111. !paths.length && paths.push([]);
    112. paths[paths.length - 1].push(e.point);
    113. this.str = JSON.stringify(this.polyline.paths);
    114. }
    115. }
    116. };
    117. </script>
    118. <style scoped lang="scss">
    119. .map {
    120. height: calc(100vh - 84px - 40px);
    121. }
    122. .alignLeft {
    123. text-align: left;
    124. }
    125. .tc {
    126. margin-top: 10px;
    127. }
    128. .tc > .el-row {
    129. border-bottom: 1px solid #ebebeb;
    130. border-left: 1px solid #ebebeb;
    131. border-right: 1px solid #ebebeb;
    132. }
    133. .borderTop {
    134. border-top: 1px solid #ebebeb;
    135. }
    136. .borderRight {
    137. border-right: 1px solid #ebebeb;
    138. }
    139. .borderLeft {
    140. border-left: 1px solid #ebebeb;
    141. }
    142. .el-col-7 {
    143. width: 105px;
    144. padding-left: 5px;
    145. line-height: 36px;
    146. }
    147. .zcdz {
    148. height: 80px;
    149. line-height: 23px !important;
    150. padding-top: 23px !important;
    151. }
    152. .longName {
    153. padding-top: 20px !important;
    154. }
    155. .zcdzname {
    156. height: 80px;
    157. line-height: 80px !important;
    158. }
    159. .lineHeight {
    160. line-height: 20px;
    161. padding-top: 15px;
    162. padding-bottom: 12px;
    163. }
    164. .lineHeight20 {
    165. line-height: 20px;
    166. padding-top: 5px;
    167. padding-bottom: 5px;
    168. padding-left: 5px;
    169. }
    170. .el-col-17 {
    171. line-height: 36px;
    172. padding-left: 5px;
    173. border-left: 1px solid #ebebeb;
    174. }
    175. .el-col-4 {
    176. width: 105px;
    177. padding-left: 5px;
    178. line-height: 36px;
    179. }
    180. .twoRow {
    181. padding-top: 15px;
    182. padding-bottom: 15px;
    183. }
    184. </style>
    185. <style>
    186. .anchorBL {
    187. display: none;
    188. }
    189. </style>

  • 相关阅读:
    OpenAI官方吴达恩《ChatGPT Prompt Engineering 提示词工程师》(5)转换 / Transforming翻译
    2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
    计算机毕设之基于python+django+mysql的影片数据爬取与数据分析(包含源码+文档+部署教程)
    Spring Security 6.1.x 系列 (1)—— 初识Spring Security
    RESTful 接口设计规范-个人总结
    flutter Chip 组件
    Web3空投入门:如何增加空投成功的几率
    继承、多态
    springboot使用多线程处理高并发接口
    【C++】vector的模拟实现 | 使用memcpy拷贝时的问题 | 实现深拷贝
  • 原文地址:https://blog.csdn.net/weixin_50885665/article/details/132870378