How do I associate an event handler with a click on the PanControl Google Maps V3 API default event?

This page describes the default set of controls for the Google Maps V3 API: http://code.google.com/apis/maps/documentation/javascript/controls.html#DefaultUI

I'm interested in capturing the PanControl click event and binding it to my custom function.

For example, when a user clicks on a control with the left mouse button (Up / Right / Down), not only changes in the map viewport are changed, but also function A.

As I understand it, one way to do this would be to listen to the event of a click on the map and check its purpose?

Any suggestions / examples (especially helpful) on how this can be done?

+5
source share
1 answer

Your assumption (listening to the event of clicking on the map and checking its purpose) sounds correct, since there is no implementation for accessing the controls.

This works for me (now):

google.maps.event.addDomListener(map.getDiv(),'click', 
             function(e) 
             {
                var t=e.target,
                    a=[null,'left','right','up','down'];

                if(
                    t.parentNode.parentNode.hasAttribute('controlwidth')
                      &&
                    t.parentNode.childNodes.length==5
                      &&
                    t.parentNode.firstChild.tagName=='IMG'
                      &&
                    t.parentNode.firstChild.src
                         =="http://maps.gstatic.com/mapfiles/mapcontrols3d7.png"
                  )
                  {
                    for(var i=1;i<t.parentNode.childNodes.length;++i)
                    {
                      if(t.parentNode.childNodes[i]==t)
                      {
                        alert('You\'ve clicked on \n>>>'+a[i]+
                              '\nyou may call a function now.');
                      }
                    }
                  }
             });

http://jsfiddle.net/doktormolle/fwgMy/

But it only works until Google changes the markup, and that may be tomorrow.

The best approach would be to hide the panorama and create your own control.

+1
source

All Articles