newTMap.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div class="newTMap">
  3. <div id="allmap1" style="height: 100%; width: 100%"></div>
  4. <div
  5. style="position: fixed; z-index: 99999; top: 0; width: 100%; background-color: white"
  6. v-if="showmap">
  7. <form action="/">
  8. <van-search
  9. v-model="searchValue"
  10. left-icon="search"
  11. @input="searchFn"
  12. placeholder="请输入搜索关键词">
  13. </van-search>
  14. </form>
  15. <div style="height: 200px; overflow: hidden" v-if="searchSHow">
  16. <div style="height: 100px; min-height: 200px; overflow-y: scroll; padding: 12px">
  17. <div
  18. v-for="(itme, index) in mapsearchlist"
  19. :key="index"
  20. style="border-bottom: 1px solid #eee"
  21. @click="addressFn(itme)">
  22. <p>{{ itme.title }}</p>
  23. <p>{{ itme.address }}</p>
  24. <p>距离:{{ itme._distance }}米</p>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="mapaddress" v-if="showmap">
  30. <div class="title">
  31. <span @click="showmap = false" style="float: left"
  32. ><van-icon name="cross" size="16"
  33. /></span>
  34. <p class="titleText">附近地址信息</p>
  35. <span style="float: right" @click="confirmMap">确定</span>
  36. </div>
  37. <div class="listBox">
  38. <van-radio-group v-model="addresssb" @change="mapselect" v-if="shows">
  39. <van-radio :name="index" v-for="(item, index) in maplist" :key="index"
  40. ><p style="margin: 4px 0; font-weight: bold">
  41. {{ item.title }}
  42. </p>
  43. <p style="margin: 4px 0">{{ item.address }}</p>
  44. <p style="margin: 4px 0">距离:{{ item._distance }}米</p>
  45. </van-radio>
  46. </van-radio-group>
  47. <br />
  48. <br />
  49. <br />
  50. <br />
  51. </div>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { getMapPoi, getkeywordPoi } from '@/utils/TXApiFun';
  57. export default {
  58. data() {
  59. return {
  60. searchValue: '',
  61. searchSHow: false,
  62. mapsearchlist: [],
  63. showmap: false,
  64. addresssb: '',
  65. shows: true,
  66. maplist: [],
  67. };
  68. },
  69. methods: {
  70. initMap(mapPointlist) {
  71. //创建map对象,初始化地图
  72. let latlng = {
  73. lat: this.pLat,
  74. lon: this.pLot,
  75. };
  76. /* eslint-disable */
  77. let center = new TMap.LatLng(latlng.lat, latlng.lon);
  78. this.map = new TMap.Map('allmap1', {
  79. center: center, //设置地图中心点坐标
  80. zoom: 17, //设置地图缩放级别
  81. // viewMode: "3D",
  82. // pitch: 43.5, //设置俯仰角
  83. // rotation: 45, //设置地图旋转角度
  84. });
  85. this.map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.SCALE); //移除比例尺控件
  86. this.map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.ROTATION); //移除旋转控件
  87. this.map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.ZOOM); //移除控件缩放
  88. /* eslint-enable */
  89. // 添加标记点 初始化中心点
  90. this.initPointMultiMarker(this.map, center);
  91. // 添加搜索出的poi点
  92. this.addMarkerLayer(this.map, mapPointlist);
  93. this.map.on('click', this.clickMap);
  94. },
  95. initPointMultiMarker(mapNode, center) {
  96. let initPoint = {
  97. id: 'marker',
  98. styleId: 'marker',
  99. position: center,
  100. };
  101. /* eslint-disable */
  102. new TMap.MultiMarker({
  103. id: 'pointId',
  104. map: mapNode,
  105. geometries: [initPoint],
  106. styles: {
  107. marker: new TMap.MarkerStyle({
  108. width: 32,
  109. height: 40,
  110. anchor: { x: 16, y: 32 },
  111. src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/marker-pink.png',
  112. }),
  113. },
  114. });
  115. /* eslint-enable */
  116. },
  117. addMarkerLayer(mapNode, mapPointlist) {
  118. /* eslint-disable */
  119. let len = mapPointlist.length;
  120. if (!len) return;
  121. let markerLayerArr = [];
  122. for (let i = 0; i < len; i++) {
  123. markerLayerArr.push({
  124. id: mapPointlist[i].id,
  125. styleId: 'marker',
  126. position: new TMap.LatLng(mapPointlist[i].location.lat, mapPointlist[i].location.lng),
  127. });
  128. }
  129. new TMap.MultiMarker({
  130. id: 'otherPointId',
  131. map: mapNode,
  132. geometries: markerLayerArr,
  133. styles: {
  134. marker: new TMap.MarkerStyle({
  135. width: 32,
  136. height: 40,
  137. anchor: { x: 16, y: 32 },
  138. src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/marker_blue.png',
  139. }),
  140. },
  141. });
  142. // markerLayer.add(markerLayerArr);
  143. /* eslint-enable */
  144. },
  145. // 点击事件处理方法
  146. clickMap(evt) {
  147. var lat = evt.latLng.getLat().toFixed(6);
  148. var lng = evt.latLng.getLng().toFixed(6);
  149. console.log('您点击的的坐标是:' + lat + ',' + lng);
  150. },
  151. mapBindEvent(map) {
  152. // 监听地图平移开始
  153. map.on('pan', () => {
  154. console.log('监听地图平移开始');
  155. });
  156. // 监听地图平移结束
  157. map.on('panend', () => {
  158. console.log('监听地图平移结束');
  159. });
  160. },
  161. searchFn() {
  162. this.searchSHow = false;
  163. console.log(this.searchValue);
  164. getkeywordPoi({ latitude: this.pLat, longitude: this.pLot }, this.searchValue).then((res) => {
  165. // 不显示下拉选择
  166. if (!res.data.length && !this.searchValue) {
  167. this.searchSHow = false;
  168. } else {
  169. this.searchSHow = true;
  170. }
  171. // 联想下拉选
  172. this.mapsearchlist = res.data;
  173. // // 赋值底部列表数据
  174. // this.maplist = res.data;
  175. });
  176. },
  177. addressFn(val) {
  178. var that = this;
  179. setTimeout(() => {
  180. /* eslint-disable */
  181. that.searchSHow = false;
  182. that.map.setCenter(new TMap.LatLng(val.location.lat, val.location.lng));
  183. that.markers1.updateGeometries([
  184. {
  185. id: 'marker',
  186. styleId: 'marker',
  187. position: new TMap.LatLng(val.location.lat, val.location.lng),
  188. },
  189. ]);
  190. that.maplist = [];
  191. // 地点搜索 获取500米范围poi点
  192. getMapPoi({ latitude: this.pLat, longitude: this.pLot }).then((res) => {
  193. console.log(res);
  194. that.maplist = res.data;
  195. that.marker.setGeometries([]);
  196. setTimeout(() => {
  197. for (let p = 0; p < res.data.length; p++) {
  198. that.marker.updateGeometries([
  199. {
  200. id: res.data[p].id,
  201. position: new TMap.LatLng(res.data[p].location.lat, res.data[p].location.lng),
  202. },
  203. ]);
  204. }
  205. });
  206. });
  207. // 清楚选中状态
  208. that.addresssb = -1;
  209. /* eslint-enable */
  210. });
  211. },
  212. confirmMap() {
  213. console.log(this.maplist);
  214. console.log(this.addresssb);
  215. if (this.addresssb > -1) {
  216. this.list.addressLine = this.maplist[this.addresssb].address;
  217. this.lon = this.myLat;
  218. this.lat = this.myLon;
  219. this.poiAddress = this.maplist[this.addresssb].address;
  220. this.poiLat = this.maplist[this.addresssb].location.lat;
  221. this.poiLon = this.maplist[this.addresssb].location.lng;
  222. this.poiId = this.maplist[this.addresssb].id;
  223. this.poiName = this.maplist[this.addresssb].title;
  224. this.showmap = false;
  225. }
  226. },
  227. mapselect(val) {
  228. /* eslint-disable */
  229. this.searchSHow = false;
  230. if (val > -1) {
  231. this.markers.updateGeometries([
  232. {
  233. id: 'markers1',
  234. styleId: 'abc',
  235. position: new TMap.LatLng(
  236. this.maplist[val].location.lat,
  237. this.maplist[val].location.lng
  238. ),
  239. },
  240. ]);
  241. }
  242. /* eslint-enable */
  243. },
  244. },
  245. };
  246. </script>
  247. <style scoped lang="scss"></style>