Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have one function which creates poly line & adds that polyline to map

function makeRoute(e)
{
    if(pointsSelection.length > 0)
    {
        pointsSelection.push(e.target.getLatLng());
        var firstpolyline = new L.Polyline(pointsSelection, {
        color: 'blue',
        weight: 5,
        smoothFactor: 1
        });

        firstpolyline.addTo(map);

        pointsArrayCollection.push(pointsSelection);
        polyArrayCollection.push(firstpolyline);

        selection = [];
        pointsSelection = [];
    }
    else
    {
        alert("Please select more than one point");
    }
}

my problem is that It adds line with same color every time.

I want to add poly lines with different colors every time.

So how can I change color of polyline dynamically.

share|improve this question
You could use something like this function in place of 'blue'. If you want something a little less random, I suggest you define a color palette as an array and select sequentially from that. stackoverflow.com/questions/1484506/… – Snorfalorpagus Mar 12 at 10:49

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.