I need to create several polylines, each with its own color, and their markers are connected to each other, I use google map v3.
For example, I have five markers, and they are all connected to each other through red color polylines. Now I want to show this red polyline in several color schemes, the first polyline in green, the second in blue, the third in black, etc.
Here is my code
<script type='text/javascript'>
var poly;
var map;
var path;
var i = parseInt(0, 10);
var marker;
function initialize() {
var chicago = new google.maps.LatLng(41.879535, -87.624333);
var myOptions = {
zoom: 7,
center: chicago,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
var polyOptions = {
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 3
}
poly = new google.maps.Polyline(polyOptions);
poly.setMap(map);
google.maps.event.addListener(map, 'click', addLatLng);
}
function addLatLng(event) {
i++;
path = poly.getPath();
var polyOptions2 = {
strokeColor: '#FFFFFF',
strokeOpacity: 1.0,
strokeWeight: 3
}
if (i == 2) {
poly.setOptions(polyOptions2);
}
else {
polyOptions2.strokeColor = "#FF0000";
poly.setOptions(polyOptions2);
}
path.push(event.latLng);
marker = new google.maps.Marker({
position: event.latLng,
title: '#' + path.getLength(),
map: map
});
}
</script>
source
share