Drawing multiple polyline with different color using Google map api V3 ASP.net

前端 未结 3 1946
后悔当初
后悔当初 2020-12-09 12:40

I am able to draw multiple polyline in google map and style them, but I want to color each polyline with a different color.

Currently, I have this code:



        
3条回答
  •  星月不相逢
    2020-12-09 12:51

    Certainly. For instance suppose you know what colours you want to go with each line, let's assume you therefore have an array of colours which has a length equal to DrivePath.length - 1.

    var Colors = [
        "#FF0000", 
        "#00FF00", 
        "#0000FF", 
        "#FFFFFF", 
        "#000000", 
        "#FFFF00", 
        "#00FFFF", 
        "#FF00FF"
    ];
    

    Now, instead of drawing one polyline, draw a separate polyline for each coordinate.

    for (var i = 0; i < DrivePath.length-1; i++) {
      var PathStyle = new google.maps.Polyline({
        path: [DrivePath[i], DrivePath[i+1]],
        strokeColor: Colors[i],
        strokeOpacity: 1.0,
        strokeWeight: 2,
        map: map
      });
    }
    

提交回复
热议问题