У меня сложный поток, в котором я должен прикрепить событие mouseover для каждой полилинии на карте. Код для прикрепления события прост:
google.maps.event.addListener(polyline, "mouseover", function() {
console.log('event fired');
});
Но это событие касается нескольких полилиний, а не других. В чем может быть причина?
Редактировать
Ниже приведен еще один код, который находится перед кодом выше и используется для определения ломаной линии:
this.polyline = new google.maps.Polyline({
path : [fromPosition, toPosition],
strokeColor : '#CCCCCC',
strokeOpacity : 1.0,
strokeWeight : 2
});
var polyline = this.polyline;
Редактировать 05 апреля 2012
Ниже приведен код, который создает проблему. Пожалуйста, объясните, почему это происходит, и порекомендуйте любое решение. Спасибо
function Link(from, to) {
this.from = from;
this.to = to;
}
Link.prototype.show = function() {
this.line = new google.maps.Polyline({
path : [this.from, this.to],
strokeColor : "#0000FF",
strokeOpacity : 0.5,
strokeWeight : 6
});
this.line.setMap(map);
google.maps.event.addListener(this.line, 'mouseover', function() {
this.line.setOptions({
strokeOpacity : 1
});
});
google.maps.event.addListener(this.line, 'mouseout', function() {
this.line.setOptions({
strokeOpacity : 0.5
});
});
}
var links = [];
var link2 = new Link(new google.maps.LatLng(-3.5999999999999996, 23.4), new google.maps.LatLng(-4.5, 23.4)), link1 = new Link(new google.maps.LatLng(-3.5999999999999996, 23.4), new google.maps.LatLng(-3.5999999999999996, 18));
links.push(link1);
links.push(link2);
// I've a long list of links, so I'll prefer a loop
for(var i = 0; i < links.length; i++) {
links[i].show();
}
JSFiddle Demo: http://jsfiddle.net/wasimbhalli/9bg6x/