I have a complex stream where I have to attach a mouseover event for each polyline on the map. The code for attaching an event is simple:
google.maps.event.addListener(polyline, "mouseover", function() { console.log('event fired'); });
But the event is associated with several polylines, and not with others. What could be the reason?
Edit
Below is another code that precedes the code above and is used to determine the polyline:
this.polyline = new google.maps.Polyline({ path : [fromPosition, toPosition], strokeColor : '#CCCCCC', strokeOpacity : 1.0, strokeWeight : 2 }); var polyline = this.polyline;
Edit 05-Apr-2012
Below is the code that creates the problem. Please explain why this is happening and recommend any solution. Thanks
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);
JSFiddle Demo: http://jsfiddle.net/wasimbhalli/9bg6x/