與@JerryDuwall的答案的幫助下,我已經做到了這一點
中,當然這不是一個梯度,但有些不是單一的顏色線多麼誘人
$.each(flightPlanCoordinates,function(k,v){
i++;
curLatLang = new google.maps.LatLng(v[0],v[1]);
if(prevLatLang == ""){
prevLatLang = curLatLang;
}else{
var strokeColor = makeGradientColor({r:0, g:255, b:204}, {r:255, g:0, b:0}, ((i/coordinatelog.length)*100));
var flightPath = new google.maps.Polyline({
path: [prevLatLang,curLatLang],
geodesic: true,
strokeColor: strokeColor.cssColor,
strokeOpacity: 1.0,
strokeWeight: 2
});
prevLatLang = curLatLang;
flightPath.setMap(map);
}
}):
而且makeGradientColor
declartion如下
function makeGradientColor(color1, color2, percent) {
var newColor = {};
function makeChannel(a, b) {
return(a + Math.round((b-a)*(percent/100)));
}
function makeColorPiece(num) {
num = Math.min(num, 255); // not more than 255
num = Math.max(num, 0); // not less than 0
var str = num.toString(16);
if (str.length < 2) {
str = "0" + str;
}
return(str);
}
newColor.r = makeChannel(color1.r, color2.r);
newColor.g = makeChannel(color1.g, color2.g);
newColor.b = makeChannel(color1.b, color2.b);
newColor.cssColor = "#" +
makeColorPiece(newColor.r) +
makeColorPiece(newColor.g) +
makeColorPiece(newColor.b);
return(newColor);
}
謝謝你的建議,它真的幫了我很多 – vimal1083