How to make a polyline painted with different colors?

  • 0
    How to make a polyline painted with different colors? The bottom line is that you need to paint a certain percentage of the polyline with a different color, roughly speaking, there will be a load indicator, it must be displayed somehow.
    Any ideas?
    JavaScript Holden Haney, May 11, 2020

  • 2 Answers
  • 0
    Specify a different color when creating a line

    var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);


    Or if it's gejson

    L.geoJSON(states, {
    style: function(feature) {
    switch (feature.properties.party) {
    case 'Republican': return {color: "#ff0000"};
    case 'Democrat': return {color: "#0000ff"};
    }
    }
    }).addTo(map);
    Anonymous

  • 0
    Well, you can change the color, I understand that, but for example I would like to know if there is a method that allows you to paint a polyline, for example, 70 percent of the length in orange and the rest in black ....

    I found an extension like this https://github.com/hgoebl/Leaflet.MultiOptionsPolyline

    but it somehow builds on other data ...
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!