0
        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.

0

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);
})
  • Thanks For your answer. Below code worked. var latLngs =L.latLng(lPolylat, lPolylng); polylineLive.addLatLng(latLngs); – Karthikeyan Oct 1 '15 at 6:42
  • Is it possible get directions on leaflet ? . I have a marker (arrow image) now i want to change the marker position based on co-ordinates. Thanks – Karthikeyan Oct 1 '15 at 6:44
  • there are several leaflet plugins for routing, check out: github.com/perliedman/leaflet-routing-machine – toms Oct 1 '15 at 16:28
0

For ajax receiving @toms has great answer already.

For redrawing polyline, probably addLatLng will suit your need.
Just do polyline = L.polyline([]).addTo(map); and polyline.addLatLng([x, y]); when new data comes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.