change the color of the polyline in DirectionsRenderer

前端 未结 4 1059
-上瘾入骨i
-上瘾入骨i 2021-02-09 17:29

i\'ve integrated a map and i want to display the route directions between two locations. everything is working fine and the directions is displayed perfectly , but i want to cha

4条回答
  •  甜味超标
    2021-02-09 17:48

    Using setOptions(options:DirectionsRendererOptions) makes code more readable. The coding would be:

    At global level:

    var directionsDisplay;
    

    Inside initialize() method:

    var polyline = new google.maps.Polyline({
        strokeColor: '#C00',
        strokeOpacity: 0.7,
        strokeWeight: 5
        });
    directionsDisplay = new google.maps.DirectionsRenderer();
    directionsDisplay.setOptions({polylineOptions: polyline}); 
    now directionDisplay can be used in any method with the custom poly line.
    

提交回复
热议问题