变量未更新或显示

时间:2017-01-06 12:55:17

标签: angularjs ecmascript-6 leaflet

我使用传单路由机,我想提取总距离和点之间的总时间。但是我没有显示时间和距离,除了我在console.log(这个)时没有更新时间和距离。你能帮我吗?

import L from 'leaflet';

class CarteController {
  /* @ngInject */
  constructor($http) {
    this.name = 'carte';
    this.$http = $http;

    this.map = L.map('map');

    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}{r}.png', {
      attribution: '© OpenStreetMap contributors'
    }).addTo(this.map);

    const control = L.Routing.control({
      waypoints: [
        L.latLng(45.750000, 4.850000),
        L.latLng(45.188529, 5.724523999999974),
        L.latLng(45.00, 5.74)
      ],
      routeWhileDragging: true,
      geocoder: L.Control.Geocoder.photon(),
      lineOptions: {
        styles: [{color: 'blue', opacity: 1, weight: 5}]
      }
    });
    control.addTo(this.map);
    control.on('waypointschanged', function () {
      this.distance = `${Math.round(control._routes[0].summary.totalDistance / 1000)} km`;
      this.temps = this.secondsToHm(control._routes[0].summary.totalTime);
    }.bind(this));

    new L.Routing.Plan({
      geocoderPlaceholder: (i, numberWaypoints) => {
        return i === 0 ?
          'Départ' :
          (i < numberWaypoints - 1 ?
            `Via ${i}` :
            'Arrivée');
      }
    }).addTo(this.map);
  }

  secondsToHm(d) {
    d = Number(d);
    const h = Math.floor(d / 3600);
    const m = Math.floor(d % 3600 / 60);
    return ((h > 0 ? h + " h " + (m < 10 ? "0" : "") : "") + m + " min"); // eslint-disable-line
  }
}

export default CarteController;

0 个答案:

没有答案