MattTheHack
MattTheHack

Reputation: 1384

Adding onclick to Polygon Location Label in Google Maps v3

I have the following code where I initialize a Polygon with an onclick listener that displays an alert:

polygon.location = location;

polygon.locationLabel = new LocationLabel(location, latLng, mapProvider.map);

 google.maps.event.addListener(polygon, 'click', function(e) {
            alert('hello');
 });

This is fine, but displays the alert when I click the Polygon but not the actual Label. How would I add a Listener so that the alert would be displayed just when the label is clicked?

Upvotes: 0

Views: 682

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

Try with :

 textToShow = polygon.locationLabel;
 google.maps.event.addListener(polygon, 'click', function(e, textToShow) {
       alert(textToShow);
 });

Upvotes: 1

Related Questions