Open infowindow with anchor MVCobject

502 views
Skip to first unread message

d.bun

unread,
Nov 30, 2009, 3:45:16 AM11/30/09
to Google Maps JavaScript API v3
I'm trying to have a infowindow anchored to a polygon. This is what
the reference says about opening infowindows:

open(map:Map, anchor?:MVCObject):

Opens this InfoWindow on the given map. Optionally, an InfoWindow can
be associated with an anchor. In the core API, the only anchor is the
Marker class. However, an anchor can be any MVCObject that exposes the
position property and optionally pixelBounds for calculating the
pixelOffset (see InfoWindowOptions).

I don't understand what and how to use an MVCObject. Is it possible
to either add position and pixelBounds properties to a polygon inorder
to anchor an infowindow to the polygon like:

polygon = new google.maps.Polygon(... position: position, pixelBounds:
pixelBounds)
infowindow.open(map, polygon)

- or is there someway of making a polygon out of an MVCObject?

Then the other questions are: the position property is that just
latLng? and pixelBounds, what do they mean and how do I retrieve them?

Esa

unread,
Nov 30, 2009, 7:57:10 PM11/30/09
to Google Maps JavaScript API v3
It used to be getPosition() method that was needed for anchoring the
info window. Like in e.g. Pamela's custom marker in Demo Gallery
http://gmaps-samples-v3.googlecode.com/svn/trunk/overlayview/custommarker.html

Now 'position' property seems to work also.

Just adding a LatLng point as position property should do:

var myPolygon = new google.maps.Polygon(options);
myPolygon.position = anchorPoint;

I haven't tested that.

d.bun

unread,
Dec 1, 2009, 3:36:47 AM12/1/09
to Google Maps JavaScript API v3
It worked! Thanks Esa!
Reply all
Reply to author
Forward
0 new messages