Leaflet Polyline Update – Live Tracking Methods

google mapsgoogle-maps-apijqueryleafletPHP

        var ColorVar = '#bd0026'; 
        var firstpolyline = new L.Polyline(polyList, {
        color:ColorVar,
        weight: 8,
        opacity:0.8,
        smoothFactor: 1
        } 
        );
        focusId.addLayer(firstpolyline);  
        }

On the page load , i have using the above code after that i want to update the polyline based on the new data without page refreshing for Live Tracking Concept.

Best Answer

not sure if this is what you are after:

// get data using ajax. Might be triggered by a button, some other user interaction, or polling remote tracking data
$.get(url, {params}, function(response, {
   // on success, remove the old polyline
   focusId.removeLayer(firstpolyline); 

   // refresh the Polyline
   polylist = response.polylist;
   var firstpolyline = new L.Polyline(polyList, {...} );

   // then add the new polyline back to the map 
   focusId.addLayer(firstpolyline);
})
Related Question