开发者

Set colour of a Polyline in Google Maps v3?

开发者 https://www.devze.com 2023-03-09 08:31 出处:网络
How can I set the colour of a Google Maps Polyline? var myRoutePath; myRoutePath = new google.maps.Polyline({

How can I set the colour of a Google Maps Polyline?

var myRoutePath;
myRoutePath = new google.maps.Polyline({
  pat开发者_Go百科h: routeCoordinates,
  strokeColor: "#CC33FF",
  strokeWeight: 3
});     
myRoutePath.setMap(map);
// Reset colour
myRoutePath.setOptions({strokeColor: 'blue'});

The above doesn't show up as an error in Firebug, but it doesn't change the color either.

Thanks for your help.


Basically looks correct to me. However, if this is your code verbatim then you immediately overwrite the color. Hence, I guess you are getting a blue polyline from the start. Try setting a timer to see the transition:

setTimeout(function () {
    myRoutePath.setOptions({strokeColor: 'blue'});
}, 3000);


Color names are still not supported as a color, use the hex version instead

myRoutePath.setOptions({strokeColor: '#0000FF'});
0

精彩评论

暂无评论...
验证码 换一张
取 消