Binding problem in infoWindow with Marker

449 views
Skip to first unread message

kiang

unread,
Jun 8, 2010, 8:20:30 AM6/8/10
to Google Maps JavaScript API v3
1) Create a Marker
2) Create a InfoWindow
3) addListener to Marker.click to open the InfoWindow
4) Click on the Marker. As expected, the InfoWindow opened.
5) Remove the marker from the map through Marker.setMap(null)
6) Well, InfoWindow is still opening there ...

I'm not sure if there's another way to bind InfoWindow with the map
property of Marker. I've tried some solutions with no luck ~

1) InfoWindow.bindTo('map', Marker) ~~ not work when
Marker.setMap(null)
2) Marker.map_changed = function() { InfoWindow.close(); }
~~ It's fun that the InfoWindow be closed. But the Marker keep stay
there when Marker.setMap(null)

I could remove them without binding. Just want to know if there's any
way to bind them together.

---
kiang

Finjon Kiang

unread,
Sep 6, 2010, 8:18:50 PM9/6/10
to Francisco Ramos, google-map...@googlegroups.com
Hi Francisco,

Thanks for sharing your tips with me. I think it would be better to
have the information back to group. Hope you won't mind if I c.c. the
group.

I did use some similar way to resolve the problem. Just hope somebody
could fix the issue to make binding feature work as expected. I'm not
sure if it's a bug or a feature, so I just open a topic instead
opening an issue. ;)

--
Finjon Kiang

On Mon, Sep 6, 2010 at 6:09 PM, Francisco Ramos <jscrip...@gmail.com> wrote:
> Hi Kiang
>
> I came up with something that works for me. Have a look at this
> snippet, it might give you an idea:
>
> function openInfoWindow(map, marker) {
>    infowin.set("marker", marker); // associate marker to the
> infoWindow
>    infowin.open(map, marker);
> }
>
> function closeInfoWindowMarker (marker) {
>    // let's check whether the infoWindow is associated to the marker
> we are either hiding or removing from the map
>    if (infowin.get("marker") == marker) {
>        closeInfoWindow();
>    }
> }
>
> function closeInfoWindow() {
>    infowin.set("marker", null); // remove association
>    infowin.close();
> }
>
> // we want to close infoWindow when hiding marker
> google.maps.event.addListener(marker, "visible_changed", function () {
>    if (this.getVisible() == false) {
>        closeInfoWindowMarker(this);
>    }
> });
>
> // also when removing from the map
> google.maps.event.addListener(marker, "map_changed", function () {
>    if (this.get("map") == null) {
>        closeInfoWindowMarker(this);
>    }
> });
>
> As I said this is working for me and it could be a solution for you.
>
> Fran
>
> On Jun 8, 1:20 pm, kiang <kia...@gmail.com> wrote:
>> 1) Create aMarker
>> 2) Create aInfoWindow
>> 3) addListener toMarker.click to open theInfoWindow
>> 4) Click on theMarker. As expected, theInfoWindowopened.
>> 5) Remove themarkerfrom the map throughMarker.setMap(null)
>> 6) Well,InfoWindowis still opening there ...


>>
>> I'm not sure if there's another way to bindInfoWindowwith the map

>> property ofMarker. I've tried some solutions with no luck ~


>>
>> 1)InfoWindow.bindTo('map',Marker) ~~ not work whenMarker.setMap(null)

>> 2)Marker.map_changed = function() {InfoWindow.close(); }


>> ~~ It's fun that theInfoWindowbe closed. But theMarkerkeep stay
>> there whenMarker.setMap(null)
>>

>> I could remove them withoutbinding. Just want to know if there's any

Reply all
Reply to author
Forward
0 new messages