Рандомизировать в полилинии цвет карты Google для каждого маршрута - PullRequest
0 голосов
/ 18 мая 2018

Здесь мы пытаемся различить полилинию по цвету, которые происходят из одного источника.Данные, предоставляемые полилинии, содержат широту, lng с другим свойством.Другая опора.будет иметь несколько записей latlng.

// Here we created a map object.
var mapOptions = {
    zoom: 6,
    center: new google.maps.LatLng(20.59, 78.96),
    mapTypeId: google.maps.MapTypeId.TERRAINr
};
// Here we get the map id of the html page.
$scope.map = new google.maps.Map(document.getElementById('map'), 
mapOptions);   
// Here we assign data for the polyline path prop.
var tripdata=[];
tripdata=[
id:1, {lat:23.333, lng:87.777},
id:2, {lat:24.343, lng:78.876}
];
var vehiclePath; // Here we declare a variable of polyline object.
vehiclePath = new google.maps.Polyline({
                 path: tripdata,
                 geodesic: true,
                 strokeColor: '#0000FF',
                 strokeOpacity: 1.0,
                 strokeWeight: 2,                    
                 map: $scope.map                  
             });

1 Ответ

0 голосов
/ 18 мая 2018

Вы можете сделать это:

// Here we created a map object.
var mapOptions = {
    zoom: 6,
    center: new google.maps.LatLng(20.59, 78.96),
    mapTypeId: google.maps.MapTypeId.TERRAINr
};
// Here we get the map id of the html page.
$scope.map = new google.maps.Map(document.getElementById('map'), 
mapOptions);   
// Here we assign data for the polyline path prop.
var tripdata=[];
tripdata=[
id:1, {lat:23.333, lng:87.777},
id:2, {lat:24.343, lng:78.876}
];
var vehiclePath; // Here we declare a variable of polyline object.
vehiclePath = new google.maps.Polyline({
                 path: tripdata,
                 geodesic: true,
                 strokeColor: getRandomColor(),
                 strokeOpacity: 1.0,
                 strokeWeight: 2,                    
                 map: $scope.map                  
             });

var colors = []; // empty array to ensure colours are unique
function getRandomColor(var id) {
  var color;
  do
    var letters = '0123456789ABCDEF';
    color = '#';
    for (var i = 0; i < 6; i++) {
        color += letters[Math.floor(Math.random() * 16)];
    }
  while(!colors.includes(color));
  colors.push(color);
  return color;
  }

Дайте мне знать, если это поможет

Генератор случайных цветов

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...