navigation.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
  2. var app = getApp();
  3. var http = require("../../utils/config.js");
  4. var qqmapsdk = new QQMapWX({
  5. key: 'JXRBZ-KHK3P-D7SDS-LAU2A-P66QT-BEFYY' // 必填
  6. });
  7. Page({
  8. data: {
  9. longitude: '',
  10. latitude: '',
  11. suggestion:[],
  12. show:false,
  13. value:'',
  14. parking:false,
  15. controls:[],
  16. animationData:{},
  17. address:'',
  18. area:[],
  19. polygons:[],
  20. areaTop:[],
  21. home_polygons: [],
  22. markers:[]
  23. },
  24. onLoad: function(options) {
  25. var that = this;
  26. wx.getLocation({
  27. type: 'gcj02',
  28. success: (res) => {
  29. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  30. var latitude = res.latitude
  31. var longitude = res.longitude
  32. that.setData({
  33. longitude: longitude,
  34. latitude: latitude
  35. })
  36. },
  37. fail: function(err) {
  38. console.log(err)
  39. }
  40. })
  41. that.setData({ home_polygons: wx.getStorageSync('home'), polygons: that.data.polygons.concat(wx.getStorageSync('home'))})
  42. var data = {
  43. 'area_id': wx.getStorageSync('home').id
  44. }
  45. app.request('/parking/stop-sites', data, 'GET').then(res => {
  46. // console.log(res)
  47. if (res.statusCode == 200) {
  48. var data = res.data
  49. that.setData({
  50. polygons: that.data.polygons.concat(data.polygons),
  51. markers: data.centres
  52. })
  53. }
  54. })
  55. },
  56. parkingArea:function(){
  57. var that = this;
  58. wx.getLocation({
  59. type: 'gcj02',
  60. success: function(resp) {
  61. var data = {
  62. 'lat': that.data.latitude,
  63. 'lng': that.data.longitude,
  64. 'area_id': wx.getStorageSync('home').id,
  65. 'location_lat':resp.latitude,
  66. 'location_lng':resp.longitude
  67. }
  68. var markers = that.data.markers;
  69. app.request('/parking/nearby', data, 'GET').then(res => {
  70. console.log(res)
  71. if(res.data.points!=''){
  72. that.setData({area:res.data.points,areaTop:res.data.points[0]})
  73. }
  74. if (res.statusCode == 200) {
  75. var data1 = res.data
  76. if(data1.polygons.length>0){
  77. var array = data1.points;
  78. var marker = {};
  79. marker.latitude = that.data.latitude;
  80. marker.longitude = that.data.longitude;
  81. marker.zIndex = 1111;
  82. marker.width = 15;
  83. marker.height = 27;
  84. marker.type = 3;
  85. marker.iconPath = '/img/map.png';
  86. array = array.concat(marker)
  87. that.setData({ polygons: that.data.polygons.concat(data1.polygons), markers: markers.concat(array), parking:true})
  88. console.log(that.data.polygons)
  89. console.log(that.data.markers)
  90. }else{
  91. wx.showToast({
  92. title: '当前目的地附近暂无还车点',
  93. icon:'none'
  94. })
  95. that.setData({ parking:false})
  96. var marker = {};
  97. marker.latitude = that.data.latitude;
  98. marker.longitude = that.data.longitude;
  99. marker.zIndex = 1111;
  100. marker.width = 15;
  101. marker.height = 27;
  102. marker.type = 3;
  103. marker.iconPath = '/img/map.png';
  104. that.setData({ markers: markers.concat(marker) })
  105. }
  106. }else{
  107. var marker = {};
  108. marker.latitude = that.data.latitude;
  109. marker.longitude = that.data.longitude;
  110. marker.zIndex = 1111;
  111. marker.width = 15;
  112. marker.height = 27;
  113. marker.type = 3;
  114. marker.iconPath = '/img/map.png';
  115. that.setData({ markers: markers.concat(marker) })
  116. }
  117. })
  118. },
  119. })
  120. },
  121. stop(e){
  122. var that = this;
  123. var area = this.data.area;
  124. var markers = that.data.markers;
  125. for (let item of markers) {
  126. // console.log(item)
  127. if (item.id == e.markerId) {
  128. if(item.type==2){
  129. item.iconPath = 'http://resource.weilaigo.l4j.cn/orange-stop.png'
  130. }
  131. if (item.type == 1) {
  132. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png'
  133. }
  134. } else {
  135. if(item.type==2){
  136. if (item.iconPath == '/img/map.png') {
  137. } else {
  138. item.iconPath = 'http://resource.weilaigo.l4j.cn/stop1.png'
  139. }
  140. }
  141. if (item.type == 1) {
  142. item.iconPath = 'http://resource.weilaigo.l4j.cn/ban-stop.png'
  143. }
  144. }
  145. }
  146. that.setData({ markers })
  147. for (let item of area) {
  148. if (item.id == e.markerId) {
  149. if(item.type==2){
  150. that.setData({ areaTop: item })
  151. }
  152. }
  153. }
  154. },
  155. selected(e){
  156. var that = this;
  157. var city = that.data.suggestion;
  158. var index = e.currentTarget.dataset.index;
  159. that.setData({
  160. value:city[index].title,
  161. latitude: city[index].latitude,
  162. longitude:city[index].longitude,
  163. show:false,
  164. address: city[index].addr
  165. })
  166. // this.pointer();
  167. that.parkingArea()
  168. var animation = wx.createAnimation({
  169. duration: 1000,//动画的持续时间
  170. })
  171. this.animation = animation; //将animation变量赋值给当前动画
  172. var time1 = setTimeout(function () {
  173. that.slideIn();//调用动画--滑入
  174. clearTimeout(time1);
  175. time1 = null;
  176. }, 100)
  177. },
  178. slideIn: function () {
  179. this.animation.translateY(0).step() // 在y轴偏移,然后用step()完成一个动画
  180. this.setData({
  181. //动画实例的export方法导出动画数据传递给组件的animation属性
  182. animationData: this.animation.export()
  183. })
  184. },
  185. slideDown: function () {
  186. this.animation.translateY(300).step()
  187. this.setData({
  188. animationData: this.animation.export(),
  189. })
  190. },
  191. bindregionchange() {
  192. },
  193. location:function(e){
  194. console.log(this.data.areaTop)
  195. var latitude = this.data.areaTop.latitude;
  196. var longitude = this.data.areaTop.longitude;
  197. var address = this.data.areaTop.description;
  198. var name = this.data.areaTop.name;
  199. wx.openLocation({//​使用微信内置地图查看位置。
  200. latitude: latitude,//要去的纬度-地址
  201. longitude: longitude,//要去的经度-地址
  202. name: name,
  203. address: address
  204. })
  205. },
  206. input(e) {
  207. var _this = this;
  208. //调用关键词提示接口
  209. if (e.detail.value == '') {
  210. _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
  211. suggestion: [],
  212. show:false,
  213. parking:false
  214. });
  215. return;
  216. }
  217. if (this.data.value != e.detail.value && e.detail.value!='') {
  218. // _this.setData({:false})
  219. var animation = wx.createAnimation({
  220. duration: 1000,//动画的持续时间
  221. })
  222. this.animation = animation; //将animation变量赋值给当前动画
  223. var time1 = setTimeout(function () {
  224. _this.slideDown();//调用动画--滑入
  225. clearTimeout(time1);
  226. time1 = null;
  227. }, 100)
  228. }
  229. _this.setData({ value: e.detail.value })
  230. var location=_this.data.latitude+','+_this.data.longitude
  231. qqmapsdk.getSuggestion({
  232. //获取输入框值并设置keyword参数
  233. keyword: e.detail.value, //用户输入的关键词,可设置固定值,如keyword:'KFC'
  234. page_size:20,
  235. //region:'北京', //设置城市名,限制关键词所示的地域范围,非必填参数
  236. location:location,
  237. region_fix:1,
  238. success: function(res) { //搜索成功后的回调
  239. var sug = [];
  240. for (var i = 0; i < res.data.length; i++) {
  241. sug.push({ // 获取返回结果,放到sug数组中
  242. title: res.data[i].title,
  243. id: res.data[i].id,
  244. addr: res.data[i].address,
  245. city: res.data[i].city,
  246. district: res.data[i].district,
  247. latitude: res.data[i].location.lat,
  248. longitude: res.data[i].location.lng
  249. });
  250. }
  251. _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
  252. suggestion: sug,
  253. show:true
  254. });
  255. }
  256. });
  257. },
  258. onReady: function() {
  259. },
  260. onShow: function() {
  261. },
  262. onHide: function() {
  263. },
  264. onUnload: function() {
  265. },
  266. onPullDownRefresh: function() {
  267. },
  268. onReachBottom: function() {
  269. },
  270. onShareAppMessage: function() {
  271. }
  272. })