TransWikia.com

Live waypoints update on Leaflet map

Geographic Information Systems Asked by storedprocedure on July 19, 2021

I have an application that uses my Leaflet map. I want to use it like navigation. But the path is not updated. Where is the problem?

setInterval(livetrack, 5000);
function livetrack() {
  $.get("/xxxx?car_id=" + carid).done(function (data) {
    var xvar = data;
    if (new_marker != "") map.removeLayer(new_marker);

    var b = xvar.split(",");

    new_marker = L.marker([b[1], b[2]], { icon: iconCar }).addTo(map);

    lati = b[1];
    longi = b[2];

    another_func();
  });
}

function another_func() {
  /* etc */
  rotate_update(data);
  /* etc */
}

function rotate_update(data) {
  veriler = L.Routing.control({
    show: false,
    addWaypoints: false,
    draggableWaypoints: false,
    fitSelectedRoutes: false,
    autoRoute: true,
    waypoints: [
      L.latLng(lati, longi),
      L.latLng(data.last_lati, data.last_longi, iconCus),
    ],
    createMarker: function (i, wp, nWps) {
      if (i === 0 || i === nWps + 1) {
        return (mymarker = L.marker(wp.latLng, {
          icon: iconCar,
        }));
      } else {
        return (job_start = L.marker(wp.latLng, {
          icon: iconCus,
        }));
      }
    },
  }).addTo(map);
}

In this way, the code creates 2 car icons and 1 customer icon. The 1st car icon continues on its way live, but does not draw a route to it. The second car creates the route between the icon and the customer, but this car icon is not moving.

How can I delete one of these icons and update the route live?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP