polygon: setoptions clickable=false doesn't seem to work?

1,706 views
Skip to first unread message

CarlEd

unread,
Jun 15, 2010, 6:36:27 PM6/15/10
to Google Maps JavaScript API v3
I have two quick and easy functions called by a link:

function setEditGeo() {
document.getElementById("spanSetGeoEdit").innerHTML = '<a href="#"
onclick="setNoEditGeo();">edit geo mode off<\/a>';
for (var i = 0; i < geoFenceArray.length; i++) {
polyListenerArray.push
(google.maps.event.addListener(geoFenceArray[i], 'click',
showArrays));
geoFenceArray[i].setOptions({ clickable: true });
}
}

function setNoEditGeo() {
document.getElementById("spanSetGeoEdit").innerHTML = '<a href="#"
onclick="setEditGeo();">edit geo mode on<\/a>';
for (var i = 0; i < geoFenceArray.length; i++) {
google.maps.event.removeListener(polyListenerArray[i]);
geoFenceArray[i].setOptions({ clickable: false });
}
}

The first successfully sets the polygons as clickable and I see the
infowindow when I click. however when I click on the link to run the
second function (setNoEditGeo) the code runs, I can step through with
debug, the eventhandler removal works, but the polygons remain
clickable (hand changes to pointing finger when on mouseover) - the
infowindow doesn't appear on clicking though, so some of the function
is working.

I presume that I have the syntax right for setting clickable to false?

Nathan Raley

unread,
Jun 16, 2010, 2:20:37 PM6/16/10
to google-map...@googlegroups.com
I'm not 100% sure if you can change the clickable options after creation of the polygon.  From what you describe it is turning off the event handling for the click event of the polygon, but since it was initialized as clickable you are still getting the cursor change when moving over it.
 
You may have to destroy the polygon and recreate it with the clickable option being turned off in order of it to work.  
 
Did you try that yet?

CarlEd

unread,
Jun 16, 2010, 3:21:23 PM6/16/10
to Google Maps JavaScript API v3
No - I create the polygons like this:

function createPoly(polyName, polyPath) {

p = new google.maps.Polygon({
paths: polyPath,
strokeColor: "#FF0000",
strokeOpacity: 0.7,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.20,
clickable: false
});

p.setMap(map);
return p;

...and I then do: geoFenceArray[i].setOptions({ clickable: true });
which works. However, I cannot then turn "clickable" back off again,
which I am starting to believe is a bug? "setOptions" has to be there
to allow these options to be set, surely?

CarlEd

unread,
Jun 18, 2010, 2:34:05 AM6/18/10
to Google Maps JavaScript API v3
Bumped in the hope of any knowledgeable people taking a look at this.
Does this seem like a bug?

CarlEd

unread,
Jun 19, 2010, 4:50:34 AM6/19/10
to Google Maps JavaScript API v3
Bumping again. Google people... should it be possible to toggle
"clickable" on a polygon please?

Rossko

unread,
Jun 19, 2010, 5:40:08 AM6/19/10
to Google Maps JavaScript API v3
> Bumping again.  Google people... should it be possible to toggle
> "clickable" on a polygon please?

Time for a live demonstrator ?

CarlEd

unread,
Jun 20, 2010, 4:59:59 AM6/20/10
to Google Maps JavaScript API v3
Indeed: http://www.csurf.co.uk/mapTest.htm

On load, mouseover the polygons - no change, right? Then click on
"set clickable on" and mouseover again - you get a pointy finger over
the polygons and you get an infowindow on click.

Now click on "set clickable off" and mouseover again. You STILL get
the pointy finger, but the click handler has gone and no infowindow
appears.

Fine that no infowindow appears, but the pointy finger should also be
gone, surely?

William

unread,
Jun 20, 2010, 5:52:40 AM6/20/10
to Google Maps JavaScript API v3
yeah also there seems something wrong if you create the polygon as
"clickable:false" it still receives click events:

clickable: true, cursor: pointer, receives click events:
http://www.william-map.com/20100620/1/map_clickable_true.htm

clickable: false, cursor: open hand, but still receives click events:
http://www.william-map.com/20100620/1/map_clickable_false.htm

...

Chad Killingsworth

unread,
Jun 20, 2010, 8:13:42 AM6/20/10
to Google Maps JavaScript API v3
Always receiving mouse events is probably a side effect of the fact
that SVG elements are opaque. See Marc Ridey's I/O session:
http://code.google.com/events/io/2010/sessions/maps-api-v3-api.html
(He mentions it at around the 22:00 min into the video).

Chad Killingsworth

CarlEd

unread,
Jun 20, 2010, 9:38:25 AM6/20/10
to Google Maps JavaScript API v3
That's odd, as on my example it doesn't fire the click event as far as
I can tell (until I set clickable true) so I wonder why on yours it
still triggers the event?

Rossko

unread,
Jun 20, 2010, 9:54:33 AM6/20/10
to Google Maps JavaScript API v3
> That's odd, as on my example it doesn't fire the click event as far as
> I can tell (until I set clickable true) so I wonder why on yours it
> still triggers the event?

The 'click' event is one thing, setting up an event listener is
another.
There is nothing to stop one setting up listeners for events that
"should never happen" e.g. William's poly-click listener.

You specifically make your own code remove the listener ; the event
could still happen but there is nothing to indicate that it has.

CarlEd

unread,
Jun 20, 2010, 4:07:44 PM6/20/10
to Google Maps JavaScript API v3
With respect Rossko, I think you're missing the point. It's not me
that's responsible for the hand changing to a finger pointer once the
polygons are made clickable, that is something that's happening inside
the google js script. If the polygons are unclickable and the mouse
does not change to a pointing finger on mouseover then that HAS to be
the state that the system returns to as soon as clickable is set to
"false" again. You can see in my original post that I remover the
listener, this post is about why the mouse still changes to a pointer
when the listener is gone AND the "clickable" option has been set to
false.

Rossko

unread,
Jun 20, 2010, 4:19:54 PM6/20/10
to Google Maps JavaScript API v3
> I think you're missing the point.

Probably.
I thought you were wondering why William's 'unclickable' poly still
generated click events, but yours didn't seem to.

You might want add your examples and stars to this issue, looks like
another manifestation of the same problem:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=2497

CarlEd

unread,
Jun 20, 2010, 5:44:05 PM6/20/10
to Google Maps JavaScript API v3
Cheers Rossko, have added my details to that issue.
Reply all
Reply to author
Forward
0 new messages