listener on InfoWindow closeclick

801 views
Skip to first unread message

green

unread,
Jul 6, 2009, 4:02:19 PM7/6/09
to Google Maps JavaScript API v3
Hi all,

I've got some questions about a little script.

The link is:
http://www.groenewilg.nl/google_maps_tst1/rondje_v5.html

The questions in the code are marked QUESTION1 to 3
(the question about the listener on closeclick is QUESTION3)


Here the questions :

--- QUESTION1
After setting disableDefaultUI: true I was surpised the map
can still be zoomed-in and out by double clicking.
How can I prevent this ?


--- QUESTION2
A simple one: I would like to use a variable, I tried every
combination of singe and double quotes, brackets, dollar
signs $ in front: nothing seems to work.

I would like something like:
content: '<img src=srcPic></img>',

Where the variable srcPic is:
'625_selectie/dkh_rb_1_IMG_2324.jpg'

--- QUESTION3
This is the major question.
I can't get the following to work:

google.maps.event.addListener(infoWindow, 'closeclick', function()
{
// setTimeout(moveBackToMiddle, 3000);
map.set_center(new google.maps.LatLng(51.61039, 4.735746));
});


Thanks a lot in advance !

Actually I think, if I can get this little script to work, it could
be made in an example (after cleanup) because I can't
imagine I'm the only one with the problem of a shifted map
after opening a large InfoWindow.


greetings,

green



green

unread,
Jul 6, 2009, 9:57:56 PM7/6/09
to Google Maps JavaScript API v3


I found a way around for QUESTION2

In the following example, srcBig is for examle:
"625_selectie/dkh_rb_12_625.jpg";


var conTent = "'<img src=\"" + srcBig + "></img>'";
var infoWindow = new google.maps.InfoWindow({
content: conTent,
pixelOffset: new google.maps.Size(20,0),

size: new google.maps.Size(750,540)
});

green

unread,
Jul 6, 2009, 10:16:21 PM7/6/09
to Google Maps JavaScript API v3

The escaped quote (in "'<img src=\"" ) is nonsense !
(it also seems to do no harm).

Anyway, the new line works as well :

// var conTent = "'<img src=\"" + srcBig + "></img>'";
var conTent = "'<img src=" + srcBig + "></img>'";


It's realy nice to be here with myself in this discussion group.

I like myself ....

green

unread,
Jul 6, 2009, 10:49:44 PM7/6/09
to Google Maps JavaScript API v3


Also the single quotes are redundant (and they do some harm,
firefox doesn't always open the entire InfoWindow

So, the final version is without the ' in "'<img and </
img>'";

//var conTent = "'<img src=" + srcBig + "></img>'";
var conTent = "<img src=" + srcBig + "></img>";
var infoWindow = new google.maps.InfoWindow({
content: conTent,
pixelOffset: new google.maps.Size(20,0),
size: new google.maps.Size(750,540)
});




pamela (Google Employee)

unread,
Jul 9, 2009, 7:54:59 AM7/9/09
to google-map...@googlegroups.com
If you want to, you can escape the quotes inside the string. The
following should work:
var conTent = "<img src=\"" + srcBig + "\"></img>";

- pamela

green

unread,
Jul 9, 2009, 10:08:51 AM7/9/09
to Google Maps JavaScript API v3
Hi Pamela,

Sorry, I already fixed this one, I should have posted this more
clearly.
The not fully opening of the InfoWindow was due to another reason.
(nothing to do with quotes)

I ended up with the following which worked:

var conTent = "<img src=" + srcBig + " width=528 height=396>";
var infoWindow = new google.maps.InfoWindow({
content: conTent,
pixelOffset: new google.maps.Size(20,0)
});

And srcBig is the following:
"625_selectie/dkh_rb_" + numBer + "_625.jpg";


Please refer to:
http://www.groenewilg.nl/regen_besteld/rond_burgst_v2.html


*** not-yet-fixed-problem ***
The only problem I could not fix was the "moving back to the middle"
problem.
I guess there are lot's of people with this problem !

The problem is:
-1- after opening a large InfoWindow, the map is moved.
-2- when closing the InfoWindow, the map is not moved back.
-3- the end-user must pan to the original position again !

In the current version I've commented-out this section, because I
could not get
it to work, see:
// google.maps.event.addListener(infoWindow, 'closeclick', function
() {
// // setTimeout(moveBackToMiddle, 3000);
// map.set_center(new google.maps.LatLng(51.61039, 4.735746));
// });

The function is still there:
function moveBackToMiddle() {
var posMiddleMapRondDkh = new google.maps.LatLng(51.61039,
4.735746);
map.set_center(posMiddleMapRondDkh);
}


*** ONE MORE THING ***
I found out yesterday evening the no Polyline functionality is present
(yet) in V3.
Because I can't do without I've moved to V2.
Can you tell me when Polylines are available in V3 ? (days, weeks,
months ?)

Please note I'm new to all this stuff, therefore I've not answered any
questions of others yet.

greetings

green (Stefan van Oorschot, Breda, The Netherlands)



On Jul 9, 1:54 pm, "pamela (Google Employee)" <pamela...@gmail.com>
wrote:
> If you want to, you can escape the quotes inside the string. The
> following should work:
> var conTent = "<img src=\"" + srcBig + "\"></img>";
>
> - pamela
>

mmdolbow

unread,
Aug 26, 2009, 4:53:49 PM8/26/09
to Google Maps JavaScript API v3
Stefan:
I'm wondering if you found a solution to your large infoWindow yet. I
have the same problem, just wanting to pan the user back to where they
were when they close the window. I have the following, that doesn't
work:
GEvent.addListener(map.getInfoWindow(), 'closeclick', function() {
map.setCenter(point);

It's inside a function where 'point' is already defined as a GLatLng.
I just want to use the currently open window. I'm still using API v2
but the reference appears to still support this.
Cheers,
mike d

mmdolbow

unread,
Aug 31, 2009, 10:19:24 AM8/31/09
to Google Maps JavaScript API v3
Just wanted to post back that I figured out a solution, at least for
API v2. I think in v3 the only thing that will change is the second
parameter of the listener.

Inside my maps' load function, I add this:
//Add listener for window close
GEvent.addListener(map,"infowindowclose", function() {
var iw = map.getInfoWindow();
map.panTo(iw.getPoint()); //just pan to the infoWindow's anchor
}); //end addListener for window close

Seems to work just fine.
mike d
Reply all
Reply to author
Forward
0 new messages