custom control position BOTTOM_RIGHT & remove custom controls

673 views
Skip to first unread message

Ela

unread,
Sep 13, 2010, 5:58:37 AM9/13/10
to Google Maps JavaScript API v3
Hi,
I need to add a custom control to the BOTTOM_RIGHT corner of the map.

map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(controlDiv);

But this is not working in Google maps V3 because it will be displayed
to the left of the terms of use text every time, regardless if I set
the index of the control or not.

controlDiv.index = 0;
map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(controlDiv);

I couldn't find a solution in this forum but it is not the first time
this question has been asked, so maybe someone has a solution for
this, would be very nice!

By the way, is there a nice and safe way to remove a custom control?
At the moment I iterate the controls[..] collection and check if the
control is the same object or has the same id and then try to remove
the control at the current position/index


map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].forEach(function(element,
index) {
if (element == controlDiv) {

map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].removeAt(index);
}
});
Is this correct? I personally don't like such code in JavaScript... it
is not fail safe at all

Thanks.

Ela

unread,
Sep 13, 2010, 9:03:24 AM9/13/10
to Google Maps JavaScript API v3
just fyi, I found a workaround to put a control in the bottom right
corner above the legal text, I set the style of the div to
top:auto !important;
left:auto !important;
right: 0px !important;
bottom: 20px !important; (20px -> div appears above the legal text and
doesn't hide it)
with !important it overwrites the inline positioning done by the API.
I don't like such solutions, but until the API is not working
properly...
Reply all
Reply to author
Forward
0 new messages