123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //logs.js
- let util = require('../../utils/util.js');
- let wechat = require("../../utils/wechat");
- let amap = require("../../utils/amap");
- Page({
- data: {
- cindex: "0",
- types: ["getDrivingRoute", "getWalkingRoute", "getTransitRoute", "getRidingRoute"],
- markers: [],
- polyline: [],
- distance: '',
- cost: '',
- transits: [],
- city: "",
- name: "",
- desc: ""
- },
- onLoad(e) {
- let { latitude, longitude, latitude2, longitude2, city, name, desc } = e;
- let markers = [
- {
- iconPath: "/images/mapicon_navi_s.png",
- id: 0,
- latitude,
- longitude,
- width: 23,
- height: 33
- }, {
- iconPath: "/images/mapicon_navi_e.png",
- id: 1,
- latitude: latitude2,
- longitude: longitude2,
- width: 24,
- height: 34
- }
- ];
- this.setData({
- latitude, longitude, latitude2, longitude2, markers, city, name, desc
- });
- this.getRoute();
- },
- changeType(e) {
- let { id } = e.target.dataset;
- let { cindex } = this.data;
- if (id == cindex) return;
- this.setData({ cindex: id });
- this.getRoute();
- },
- getRoute() {
- let { latitude, longitude, latitude2, longitude2, types, cindex, city } = this.data;
- let type = types[cindex];
- let origin = `${longitude},${latitude}`;
- let destination = `${longitude2},${latitude2}`;
- amap.getRoute(origin, destination, type, city)
- .then(d => {
- // console.log(d);
- this.setRouteData(d, type);
- })
- .catch(e => {
- console.log(e);
- })
- },
- setRouteData(d, type) {
- if (type != "getTransitRoute") {
- let points = [];
- if (d.paths && d.paths[0] && d.paths[0].steps) {
- let steps = d.paths[0].steps;
- wx.setStorageSync("steps", steps);
- steps.forEach(item1 => {
- let poLen = item1.polyline.split(';');
- poLen.forEach(item2 => {
- let obj = {
- longitude: parseFloat(item2.split(',')[0]),
- latitude: parseFloat(item2.split(',')[1])
- }
- points.push(obj);
- })
- })
- }
- this.setData({
- polyline: [{
- points: points,
- color: "#0091ff",
- width: 6
- }]
- });
- }
- else {
- if (d && d.transits) {
- let transits = d.transits;
- transits.forEach(item1 => {
- let { segments } = item1;
- item1.transport = [];
- segments.forEach((item2, j) => {
- if (item2.bus && item2.bus.buslines && item2.bus.buslines[0] && item2.bus.buslines[0].name) {
- let name = item2.bus.buslines[0].name;
- if (j !== 0) {
- name = '--' + name;
- }
- item1.transport.push(name);
- }
- })
- })
- this.setData({ transits });
- }
- }
- if (type == "getDrivingRoute") {
- if (d.paths[0] && d.paths[0].distance) {
- this.setData({
- distance: d.paths[0].distance + '米'
- });
- }
- if (d.taxi_cost) {
- this.setData({
- cost: '打车约' + parseInt(d.taxi_cost) + '元'
- });
- }
- }
- else if (type == "getWalkingRoute" || type == "getRidingRoute") {
- if (d.paths[0] && d.paths[0].distance) {
- this.setData({
- distance: d.paths[0].distance + '米'
- });
- }
- if (d.paths[0] && d.paths[0].duration) {
- this.setData({
- cost: parseInt(d.paths[0].duration / 60) + '分钟'
- });
- }
- }
- },
- goDetail() {
- let url = `/pages/info/info`;
- wx.navigateTo({ url });
- },
- nav() {
- let { latitude2, longitude2, name, desc } = this.data;
- wx.openLocation({
- latitude: +latitude2,
- longitude: +longitude2,
- name,
- address: desc
- });
- }
- });
|