Wednesday, December 15, 2010

[Google Maps API v2] Re: When are controls (really) added to the map?

I've had to do exactly this a couple of times myself recently and this
is the soultion i found best.

Let's say in my code i have created a custom control, and it's got an
id of 'myControl'.
I've added it to the map and want to set some CSS styles on it.

function initMyControls(){
if(document.getElementById('myControl')){
// the control exists in the DOM and can be manipulated now
} else {
// the control does not yet exist
setTimeout(initMyControls, 1000);
}
}
// start checking to see if the control exists
initMyControls();

That'll execute until the control exists in the DOM and is ready for
manipulation.

If you have more than one control simply check if that control exists
too:

if(document.getElementById('myControl') &&
document.getElementById('myOtherControl')){
// etc

And of course you can experiment with different timeout periods to
find what's best.

Martin.


On Dec 15, 6:35 pm, "Anthony (GISCOE)" <gts.onta...@gmail.com> wrote:
> I am trying to make a map with some additional controls that align
> with the GMapTypeControl, which comes up with a different width
> depending on the browser. I can get the <div> for the control easily
> enough after it is added (via addControl), but it apparently doesn't
> get populated (i.e. sized) until later.
>
> Is there some event that will tell me when this 'later' is? I can get
> the correct size using a timeout, but not reliably (unless the timeout
> is large). I've tried some of the map events, but nothing seems to
> work properly for this case.

--
You received this message because you are subscribed to the Google Groups "Google Maps API V2" group.
To post to this group, send email to google-maps-api@googlegroups.com.
To unsubscribe from this group, send email to google-maps-api+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate