I have two markers with a polyline connecting the two. I have click events on the markers and the polyline, but i was trying to make the polyline easier to click without placing a new marker or increasing it's strokeWeight. So I created a circular icon and placed on the polyline, but I can't make it clickable. Is it possible?
Saw this thread but doesn't give any specifics on how the icon is clickable. I searched it's code source but he adds a KML layer. I didn't want to do that. Google Maps: Attaching events on polyline icons
Searched the google maps overlay API but didn't find any interface to listen to click events. https://developers.google.com/maps/documentation/javascript/overlays#Polylines
I also tried to attach an event listener but didn't work. I suspect it can't be done without adding an actual marker or an object but if someone else had a similar problem i would appreciate any tips :)
Thanks in advance!
My code:
var pathSymbol = {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: '#228B22'
};
var conPath = new google.maps.Polyline({
path: conCoord,
strokeColor: "#228B22",
strokeOpacity: 0.7,
icons: [{
icon: pathSymbol,
offset: '50%'
}],
strokeWeight: 2
});
conPath.setMap(map);
google.maps.event.addListener(conPath, 'click', (function(l,conCoord) {
return function() {
infowindowPath.setContent("<b>Ligação "+connections[l].id);
infowindowPath.setPosition(new google.maps.LatLngBounds(conCoord[1], conCoord[0]).getCenter());
infowindowPath.open(map);
}
})(l,conCoord));