0

地図に表示される DirectionsResult があります。DirectionsRenderer によって生成されたマーカーをユーザーがダブルクリックしたときに、個々のポリライン (脚) にアクセスして色を変更するにはどうすればよいですか。

4

2 に答える 2

1

現時点では、特定の脚の色を変更する方法はありませんが、非効率的な方法があります。

これが私が試したものです、

function handleResponse(result, status){
    console.log(result);
    var modifiedResult;
    var displayDirection;
    var line;
    var countTotalRoutes = 0;

    var pinkLine = {
        strokeColor: '#ff0089',
        strokeOpacity: 0.5,
        strokeWeight: 5
    };

    var blackLine = {
        strokeColor: '#333',
        strokeOpacity: 0.6,
        strokeWeight: 5
    };

    var whiteLine = {
        strokeColor: '#3367d6',
        strokeOpacity: 0.6,
        strokeWeight: 5
    };

    var lineColor = [pinkLine, blackLine, whiteLine];

    if (status == google.maps.DirectionsStatus.OK) {
        for(var i = 0; i < result.routes[0].legs.length; i++){
            modifiedResult = $.extend(true, {}, result);
            modifiedResult.request = result.request;
            modifiedResult.geocoded_waypoints = [];
            modifiedResult.geocoded_waypoints.push(result.geocoded_waypoints[i]);
            modifiedResult.geocoded_waypoints.push(result.geocoded_waypoints[i+1]);
            modifiedResult.routes[0].legs = [result.routes[0].legs[i]];
            line = lineColor[countTotalRoutes % 3];

            displayDirection = new google.maps.DirectionsRenderer({polylineOptions : line, suppressMarkers : true, preserveViewport : true});

            displayDirection.setMap(map);
            displayDirection.setDirections(modifiedResult);
            countTotalRoutes += 1;

            modifiedResult = null;
        }
    }
}
于 2016-07-31T21:18:27.830 に答える
1

特定の区間に異なる色を使用することはできません。ルートは 1 つのポリラインです。

独自にルートを描画し、脚ごとに別々のポリラインを描画する必要があります。その後、脚に異なる色を適用できます。

于 2013-10-19T21:38:29.323 に答える