Можно ли обновить расчет стоимости в сегменте маршрута? - PullRequest
0 голосов
/ 04 ноября 2019

Я бы хотел обновить сегмент маршрута после ввода значения в поле со списком. Обновите расчет.

HTML

<div id="map"></div>
<div id="right-panel">
  <select id="lorrytype">
<option name="1"value="1.6">1</option>
<option name="2"value="2.6">2</option>
<option name="3"value="3.6">3</option>
</select>
<div>
<b>Start:</b><br>
<input id="start"  placeholder="Start point" type="text" class="form-control">
<br>
<b>Waypoints:</b> <br>
<input id="waypoints" class="waypoints" placeholder="Waypoint" type="text" class="form-control">
<input id="waypoints1" class="waypoints" placeholder="Waypoint" type="text" class="form-control">
<br>
<b>End:</b><br>
<input id="end"  placeholder="End point" type="text" class="form-control">
<br>

</div>
<div id="directions-panel"></div>
</div>

Javascript

      function(response, status) {
        if (status === 'OK') {
          me.directionsRenderer.setDirections(response);
          var route = response.routes[0];
          var summaryPanel = document.getElementById('directions-panel');


          summaryPanel.innerHTML = '';
      // For each route, display summary information.
      for (var i = 0; i < route.legs.length; i++) {
        var lorrytype = document.getElementById('lorrytype').value;
        var routeSegment = i + 1;
        //calculate the one way price using the klms
        var kms = route.legs[i].distance.value/1000;
        var price_1 = (kms > 0) ? 3 : 0; kms =  (kms > 0)? kms - 1 :  0;
        var price_2 = (kms - 14) > 0 ? (14 * 1.60) : (kms * lorrytype); kms = (kms-14)>0 ? kms - 14 : 0;
        var price_3 = (kms - 15) > 0 ? (15 * 1.40) : (kms * lorrytype); kms = (kms-15)>0 ? kms - 15 : 0;
        var price_4 = (kms > 0) ? (kms * lorrytype) : 0;
        var total = price_1 + price_2 + price_3 + price_4;
        var totaldecimal = total.toFixed(2);

        summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
            '</b><br>';
        summaryPanel.innerHTML += route.legs[i].start_address + '<br> to <br>';
        summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
        summaryPanel.innerHTML += route.legs[i].duration.text + '<br>';
        summaryPanel.innerHTML += "the one way price is: RM " + totaldecimal + "<br>";
        summaryPanel.innerHTML += "lorry price" + lorrytype + "<br>";
        summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
        console.log();


      }

        } else {
          window.alert('Directions request failed due to ' + status);
        }
      });
};

Пример: If we change the the value in combo-box,the calculation doesn't refresh,I have to re-enter the destination address Если мы изменим значение в комбинированномполе, расчет не обновляется, я должен повторно ввести адрес назначения для обновления.

...