change the color of the polyline in DirectionsRenderer

前端 未结 4 1065
-上瘾入骨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:35

    @Seacat, after you update the directionsRenderer with the new polylineOptions, you have to re-render the directions response which is stored inside the renderer object..

    directionsRenderer.setDirections(directionsRenderer.directions);
    
    0 讨论(0)
  • 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.
    
    0 讨论(0)
  • 2021-02-09 17:53

    At global declarations

    var polylineOptionsActual = new google.maps.Polyline({
        strokeColor: '#FF0000',
        strokeOpacity: 1.0,
        strokeWeight: 10
        });
    

    At initialise

    function initialize() {
       directionsDisplay = new google.maps.DirectionsRenderer({polylineOptions: polylineOptionsActual});    
    
    0 讨论(0)
  • 2021-02-09 18:00

    In answer marked as resolved I see that object Polyline used for polylineOptions. In my case I use the next code

    new google.maps.DirectionsRenderer({ suppressMarkers: true, polylineOptions: { strokeColor: '#5cb85c' } });
    

    The difference is that I assign polylineOptions, not Polyline object. Not sure it could be helpful, but decided to add these answer.

    0 讨论(0)
提交回复
热议问题