简体   繁体   中英

How can I draw a continuous line on map using leaflet?

I have a map and I have drawn two points and drawn a line between two points using leaflet Polyline method Leaflet Polyline As of now, my code works fine but how I want to show is like a line between Point A to Point B then from Point B to Point C.. so on. Here is my current code my current code which draws line between 2 points perfects but its always between Point A and Point B.

Any help would be appreciated. Thanks a lot.

Note: Map may not be visible due to some issues but you can click on map to pick points

Add _firstLatLng = _secondLatLng when you add the polyline:

  if (_firstLatLng && _secondLatLng) {
    // draw the line between points
    L.polyline([_firstLatLng, _secondLatLng], {
      color: 'red'
    }).addTo(_map);
    _firstLatLng = _secondLatLng;
    
    refreshDistanceAndLength();
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM