Open InfoWindow from Polygon

315 views
Skip to first unread message

Dave

unread,
Aug 12, 2010, 11:27:14 AM8/12/10
to Google Maps JavaScript API v3
I'm having trouble opening an InfoWindow from a Polygon click event.

I have a loop of polygons (database driven) that load into the map.
during the loop it calls this function passing in the Polygon shape
and the object of data.

from there it adds and eventhandler to add a infowindow?



function conservancyInfoWindow(shape, conservancyobj) {
var thisshape = shape;
var conservancy = conservancyobj;
google.maps.event.addListener(thisshape, 'mousedown', function(event)
{
//clearEnterpriseWindows();
//alert(conservancy.title);
var clickedLocation = new google.maps.LatLng(event.latLng);
var cwindow = new google.maps.InfoWindow({ });
cwindow.setPosition(clickedLocation);
var thiscontent = conservancy.title;
cwindow.setContent(thiscontent);
cwindow.open(map, thisshape);


});

}


But it does not open the InfoWindow. What am i doing wrong?
Any help is appreciated!

geoco...@gmail.com

unread,
Aug 12, 2010, 12:11:49 PM8/12/10
to Google Maps JavaScript API v3
Not enough information. Where is your map where you tried to
implement this?

-- Larry

Dave

unread,
Aug 12, 2010, 12:29:55 PM8/12/10
to Google Maps JavaScript API v3

thanks for the help in advance.

The Map is the global var called map.


the all the data (for each object) is loaded first (in a JSON array)
then the map is initialized. Once the map is ready then the polygons
are created in a loop.

during the loop ( basically a for loop going through the JSON array)
it calls this function to setup the event listener for each Polygon.

thanks









On Aug 12, 9:11 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:

Dave

unread,
Aug 12, 2010, 12:32:56 PM8/12/10
to Google Maps JavaScript API v3
http://namibia.bluemarblecreative.net/map
here is the beta page.



On Aug 12, 9:11 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:

geoco...@gmail.com

unread,
Aug 12, 2010, 1:11:37 PM8/12/10
to Google Maps JavaScript API v3
On Aug 12, 9:32 am, Dave <dave...@gmail.com> wrote:
> http://namibia.bluemarblecreative.net/map
> here is the beta page.

I get an "unspecified error" in IE and don't see any polygons on that
map.

The map tiles are being tiled in strange ways in IE, seems to at least
show the map correctly and the polygons in Firefox.

You have problems with your code. At a minimum, this:
var clickedLocation = new google.maps.LatLng(event.latLng);
doesn't work (event.latLng is a google.maps.LatLng, the constructor,
at least according to the documentations takes as a minimum two
numbers, the latitude and the longitude).

This (with some other modifications) gives me an infowindow:
var clickedLocation = event.latLng;

-- Larry
> >   -- Larry- Hide quoted text -
>
> - Show quoted text -

Dave

unread,
Aug 12, 2010, 1:28:51 PM8/12/10
to Google Maps JavaScript API v3
thanks i will try that...

On Aug 12, 10:11 am, "geocode...@gmail.com" <geocode...@gmail.com>

Dave

unread,
Aug 12, 2010, 4:01:27 PM8/12/10
to Google Maps JavaScript API v3
i have tried other things and i stll can't get the InfoWindows to
open. any ideas? thanks

On Aug 12, 10:11 am, "geocode...@gmail.com" <geocode...@gmail.com>

Dave

unread,
Aug 12, 2010, 1:48:11 PM8/12/10
to Google Maps JavaScript API v3
i tried that and it still does not work.

here is my new function (added your tip) and moved some things around:

function conservancyInfoWindow(shape, conservancyobj) {
//var thisshape = shape;
var conservancy = conservancyobj;
var thiscontent = 'title';//'<h3>'+conservancy.title+'</h3><a
href="http://namibia.bluemarblecreative.net/conservancy/?
id='+conservancy.id+'"><img src="http://namibia.bluemarblecreative.net/
wp-content/uploads/map/conservancy' + conservancy.id + '.png" alt="" /
></a><br>';
var cwindow = new google.maps.InfoWindow({ content: thiscontent });

google.maps.event.addListener(shape, 'click', function(event) {

var clickedLocation = event.latLng;
cwindow.setPosition(clickedLocation);
cwindow.open(map, shape);
enterprisewindows.push(cwindow);

});
}


what other modifications did you do? thank you very much for the help.

geoco...@gmail.com

unread,
Aug 12, 2010, 5:39:06 PM8/12/10
to Google Maps JavaScript API v3
On Aug 12, 10:48 am, Dave <dave...@gmail.com> wrote:
> i tried that and it still does not work.

I don't know what you tried. This is what "worked" for me:
http://www.geocodezip.com/v3_polygon_exampleD.html

-- Larry

geoco...@gmail.com

unread,
Aug 12, 2010, 5:56:15 PM8/12/10
to Google Maps JavaScript API v3
On Aug 12, 2:39 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> On Aug 12, 10:48 am, Dave <dave...@gmail.com> wrote:
>
> > i tried that and it still does not work.
>
> I don't know what you tried.  This is what "worked" for me:

http://www.geocodezip.com/v3_polygon_exampleD.html
The infowindows seem to open in weird places in Chrome though...
Reply all
Reply to author
Forward
0 new messages