Hide/show polygon

3,322 views
Skip to first unread message

Grapefruit

unread,
Feb 13, 2010, 10:46:48 AM2/13/10
to Google Maps JavaScript API v3
I've drawed 2 polygons on my map;
- poly
- poly1

With the button 'Toggle Visibility' I want to hide/show the polygon
'poly'.

I've seen the examples, but they're all for API V2. I need something
for V3.

I've tried some things with hide() but I'm not good with JS so I can't
make it on my own without some help...

What do I have to do to hide/show the polygons? Or isn't it possible
and do I have to stick to V2?

Marcelo

unread,
Feb 13, 2010, 11:22:38 AM2/13/10
to Google Maps JavaScript API v3
On Feb 13, 4:46 pm, Grapefruit <ando...@gmail.com> wrote:
>
> What do I have to do to hide/show the polygons?

.setMap(null);


> Or isn't it possible
> and do I have to stick to V2?

What could possibly be the reasoning for having polygons that cannot
be removed after being added?


--
Marcelo - http://maps.forum.nu
--

jbogdani

unread,
Feb 13, 2010, 12:06:38 PM2/13/10
to Google Maps JavaScript API v3
> .setMap(null);

.setMap(null) is good if you want to remove the polygon. But is there
any way to hide the polyline/gon?
I mean the equivalent of setVisible(true/false) for marker class.

Thank You

Julian

Marcelo

unread,
Feb 13, 2010, 12:19:39 PM2/13/10
to Google Maps JavaScript API v3
On Feb 13, 6:06 pm, jbogdani <jbogd...@gmail.com> wrote:
> .setMap(null) is good if you want to remove the polygon. But is there
> any way to hide the polyline/gon?

For that, you can add your own methods. See:
"Hiding and Showing an Overlay" in
http://code.google.com/apis/maps/documentation/v3/overlays.html#Polygons

--
Marcelo - http://maps.forum.nu
--

jbogdani

unread,
Feb 13, 2010, 1:07:09 PM2/13/10
to Google Maps JavaScript API v3
thanks, I'll try

Grapefruit

unread,
Feb 13, 2010, 2:54:30 PM2/13/10
to Google Maps JavaScript API v3

On 13 feb, 17:22, Marcelo <marcelo...@hotmail.com> wrote:
> On Feb 13, 4:46 pm, Grapefruit <ando...@gmail.com> wrote:
>
>
>
> > What do I have to do to hide/show the polygons?
>
> .setMap(null);
>
> > Or isn't it possible
> > and do I have to stick to V2?
>
> What could possibly be the reasoning for having polygons that cannot
> be removed after being added?

I use Maps as a map for my company, with different area's of
customers. I want to select different area's therefor.

I've tried this http://code.google.com/intl/nl/apis/maps/documentation/v3/overlays.html#HideShow
but I don't know how to translate this to my map and to my polygons...

Grapefruit

unread,
Feb 13, 2010, 3:07:28 PM2/13/10
to Google Maps JavaScript API v3
wait, .setMap(null); works great! Thanks

Grapefruit

unread,
Feb 13, 2010, 4:08:52 PM2/13/10
to Google Maps JavaScript API v3

On 13 feb, 17:22, Marcelo <marcelo...@hotmail.com> wrote:

> On Feb 13, 4:46 pm, Grapefruit <ando...@gmail.com> wrote:
>
>
>
> > What do I have to do to hide/show the polygons?
>
> .setMap(null);
>

This is working, but only when:

google.maps.event.addListener(poly, 'click', function() {
poly.setMap(null);
});


I want to let it disappear when I click on a button outside of the
map.
What do I need to put in the onClick=""? I can't figure it out...

I've tried onClick="remov()"
with
function remov() {
poly.setMap(null);
}

but then nothing is happening...
Yes, i'm a JS noob :)

Marcelo

unread,
Feb 13, 2010, 4:32:41 PM2/13/10
to Google Maps JavaScript API v3
On Feb 13, 10:08 pm, Grapefruit <ando...@gmail.com> wrote:
>
> but then nothing is happening...
> Yes, i'm a JS noob :)

1. This is not a forum for basic javascript.

2. Please read and follow the group's posting guidelines:
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/2b3f101fd509919e#
http://groups.google.com/group/Google-Maps-API/web/why-including-a-link-is-critical

Grapefruit

unread,
Feb 13, 2010, 4:38:57 PM2/13/10
to Google Maps JavaScript API v3
Yes, I know, but I can't find these things in tutorials (only simple
things with alert () )
I don't know how to refer to the google.maps. A simple link to a
tutorial is enough, I want to do it myself :)

My link is http://www.andorvb.nl/test2.html
If you click on the polygon, it disappears, just like it has to. When
you click on the other one, it appears again. But I want to do that
with the Remove!-link :)

On 13 feb, 22:32, Marcelo <marcelo...@hotmail.com> wrote:
> On Feb 13, 10:08 pm, Grapefruit <ando...@gmail.com> wrote:
>
>
>
> > but then nothing is happening...
> > Yes, i'm a JS noob :)
>
> 1. This is not a forum for basic javascript.
>

> 2. Please read and follow the group's posting guidelines:http://groups.google.com/group/google-maps-js-api-v3/browse_thread/th...http://groups.google.com/group/Google-Maps-API/web/why-including-a-li...
>
> --
> Marcelo -http://maps.forum.nu
> --

Marcelo

unread,
Feb 13, 2010, 5:27:14 PM2/13/10
to Google Maps JavaScript API v3
It's about scope. Unnest your functions and make your var map global:
http://econym.org.uk/gmap/scope.htm

--
Marcelo - http://maps.forum.nu
--

On Feb 13, 10:38 pm, Grapefruit <ando...@gmail.com> wrote:
> Yes, I know, but I can't find these things in tutorials (only simple
> things with alert () )
> I don't know how to refer to the google.maps. A simple link to a
> tutorial is enough, I want to do it myself :)
>

> My link ishttp://www.andorvb.nl/test2.html


> If you click on the polygon, it disappears, just like it has to. When
> you click on the other one, it appears again. But I want to do that
> with the Remove!-link :)
>
> On 13 feb, 22:32, Marcelo <marcelo...@hotmail.com> wrote:
>
>
>
> > On Feb 13, 10:08 pm, Grapefruit <ando...@gmail.com> wrote:
>
> > > but then nothing is happening...
> > > Yes, i'm a JS noob :)
>
> > 1. This is not a forum for basic javascript.
>

> > 2. Please read and follow the group's posting guidelines:http://groups.google.com/group/google-maps-js-api-v3/browse_thread/th......

Grapefruit

unread,
Feb 14, 2010, 7:52:27 AM2/14/10
to Google Maps JavaScript API v3
Thanks, that was the missing key.

BTW, is there a contextmenu available for V3?

On 13 feb, 23:27, Marcelo <marcelo...@hotmail.com> wrote:
> It's about scope. Unnest your functions and make your var map global:http://econym.org.uk/gmap/scope.htm
>
> --

> Marcelo -http://maps.forum.nu

Reply all
Reply to author
Forward
0 new messages