show/hide toggle for polygons

846 views
Skip to first unread message

אæα

unread,
Feb 20, 2010, 11:56:59 PM2/20/10
to Google Maps JavaScript API v3
Hello,
I want to make a toggle for polygons with checkboxes, but I can't see
how to make a simple hide/show button:

I have for example:
http://pastebin.com/m70981c1a
http://boxes.x10hosting.com/poly-2.9.html

why can't this work (m7418 is the polygon):

var toggleState = 1;

function toggle() {
if (toggleState == 1) {
m7418.setMap(null);
toggleState = 0;
} else {
m7418.setMap(map);
toggleState = 1;
}
}

I've seen these examples for v2: http://mapperz.googlepages.com/poly_kml_updated.html,
http://www.nn4d.com/site/global/build/manuals/doku6058.jsp?id=ajax:2.0:tutorials:map_objects:polygon;
and this one for v3: http://home.provide.net/~bratliff/polycluster/v3/polygon.html;
I came here by way of this page :
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/de419c64c313bab8
and thought this might work. Thanks for any help.

Esa

unread,
Feb 21, 2010, 2:40:14 PM2/21/10
to Google Maps JavaScript API v3

On Feb 21, 6:56 am, אæα <alephael...@gmail.com> wrote:
>
> why can't this work (m7418 is the polygon):
>

The function looks fine but <input onClick="toggle();" ...
tries to find function toggle() from global scope. Now the function is
local to initialize() function.

You should take the function outside initialize(). Also I would
recommend using a browser with a javascript error console.

אæα

unread,
Feb 22, 2010, 3:10:06 AM2/22/10
to Google Maps JavaScript API v3
Thanks Esa for your reply; I do think that scope is the problem, I'll
rework it, thanks for your help.

אæα

unread,
Feb 26, 2010, 4:17:26 AM2/26/10
to Google Maps JavaScript API v3

I found a solution: actually it only worked for me within the
initialization, and with the function labeled first; e.g, toggle =
function() {...}.
Reply all
Reply to author
Forward
0 new messages