Google maps api 3 更改2个航路点之间的线路颜色

Google maps api 3 更改2个航路点之间的线路颜色,google-maps-api-3,Google Maps Api 3,我使用此功能通过航路点阵列绘制A和Z之间的路线。 是否可以在某些航路点之间更改线路颜色(默认为蓝色) 我的意思是我想要A和B之间的蓝色,C和D之间的红色。。。。 我发现了如何改变线条的颜色 var directionsDisplay = new google.maps.DirectionsRenderer({polylineOptions: { strokeColor: "#8b0013" }, 但是我找不到在航路点怎么做 谢谢你的帮助 function calcRoute(origin_la

我使用此功能通过航路点阵列绘制A和Z之间的路线。 是否可以在某些航路点之间更改线路颜色(默认为蓝色)

我的意思是我想要A和B之间的蓝色,C和D之间的红色。。。。 我发现了如何改变线条的颜色

var directionsDisplay = new google.maps.DirectionsRenderer({polylineOptions: { strokeColor: "#8b0013" },
但是我找不到在航路点怎么做

谢谢你的帮助

function calcRoute(origin_lat,origin_lng,destination_lat,destination_lng) {
   console.log ("Entrée CALC ROUTE");

   var origin = new google.maps.LatLng(origin_lat,origin_lng);
   var destination = new google.maps.LatLng(destination_lat,destination_lng);
   var waypointsArray = document.getElementById('waypoints').value.split("|");

   var waypts = [];

   for (i = 0; i < waypointsArray.length; i++) { 
   if (waypointsArray[i]!="") {
        var waypoint = waypointsArray[i];
        var waypointArray = waypoint.split(",");
        var waypointLat = waypointArray[0]; 
        var waypointLng = waypointArray[1];
        console.log("waypts lat " + waypointLat);
        console.log("waypts lng " + waypointLng);

            waypts.push({
            location: new google.maps.LatLng(waypointLat,waypointLng),
            stopover: true
            }) 
        }
   }
   console.log("waypts " + waypts.length);

        var request = {
          origin:origin,
          destination:destination,
          travelMode: google.maps.TravelMode.DRIVING,
          waypoints: waypts,
          provideRouteAlternatives: true
        };
           console.log ("Calc request "+JSON.stringify(request));

        directionsService.route(request, function(result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(result);
        }
     });
    }   
功能计算(起点、起点、终点、终点){
console.log(“Entrée CALC ROUTE”);
var origin=new google.maps.LatLng(origin\u lat,origin\u lng);
var destination=new google.maps.LatLng(destination\u lat,destination\u lng);
var waypointsArray=document.getElementById('waypoints').value.split(“|”);
var-waypts=[];
对于(i=0;i
您不能只修改
DirectionsRenderer
输出的一个片段。您可以使用单独的
DirectionsRenderer
渲染每个线段,也可以创建自己的自定义渲染器,该渲染器允许您为管线的每个步骤创建单独的多段线,并对每个多段线分别着色

代码片段:

var映射;
var定向服务;
var方向显示;
函数初始化(){
map=新建google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
directionsService=new google.maps.directionsService();
directionsDisplay=新建google.maps.DirectionsRenderer({
地图:地图,
抑制多段线:真
});
//美国马里兰州巴尔的摩(39.2903848,-76.61218930000001)
//美国马萨诸塞州波士顿(42.3600825,-71.05888010000001)
//美国宾夕法尼亚州费城(39.9525839,-75.16522150000003)
//美国纽约州纽约市(40.7127837,-74.0059413000002)
卡尔克劳特(39.2903848,-76.6121893,42.3600825,-71.05888);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
功能计算(起点、起点、终点、终点){
控制台日志(“入口计算路线”);
var origin=new google.maps.LatLng(origin\u lat,origin\u lng);
var destination=new google.maps.LatLng(destination\u lat,destination\u lng);
var waypointsArray=document.getElementById('waypoints').value.split(“|”);
var-waypts=[];
对于(i=0;i
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}

相关问题:相关问题: