navigation.js 8.3 KB

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