By the way I have uploaded the sample here: http://pages.cpsc.ucalgary.ca/~vnasser/tmp/divmouseeventhandler.html
On May 14, 5:48 pm, Valeh <[email protected]> wrote: > Thanks for your useful comments: > I have created an example based on your comments and this > code:http://groups.google.com/group/google-maps-js-api-v3/browse_thread/th... > The code converts the clicked point's coordinates, which is in pixels > to latlng. To do this a dummy overlay is > created.//---------------------------- > Note that there is a bug. If the browser is both zoomed in and > scrolled the position will be wrong. The reason is that I could not > figure out a way to access to browser's zoom factor.If we had the zoom > factor we had to multiply it here: > > var relativeLeft = mEvent.clientX + window.scrollX*zoomfactor - > curElement.offsetLeft; > var relativeTop = mEvent.clientY + window.scrollY*zoomfactor - > curElement.offsetTop; > > Apparantly if the script is certified for firefox we can access the > zoom level (according to this > pagehttp://forums.mozillazine.org/viewtopic.php?f=38&t=688405&start=0&st=...). > //---------------------------- > I have pasted the code below: > > <!DOCTYPE html> > <html> > <head> > <meta http-equiv="content-type" content="text/html; > charset=utf-8" /> > <title>Converting LatLng to Pixel Coordinates</title> > > <style type="text/css"> > #map { > width: 600px; > height: 600px; > } > > #latlng-control { > background: #ffc; > border: 1px solid #676767; > font-family: arial, helvetica, sans-serif; > font-size: 0.7em; > padding: 2px 4px; > position: absolute; > } > </style> > > <script type="text/javascript" src="http://maps.google.com/maps/ > api/js?sensor=false"></script> > > <script type="text/javascript"> > > /** > * Called on the intiial pageload. > */ > function init() { > var centerLatLng = new > google.maps.LatLng(37.748582,-122.418411); > var mapDIV = document.getElementById('map'); > var map = new google.maps.Map(document.getElementById('map'), > { > 'zoom': 10, > 'center': centerLatLng, > 'mapTypeId': google.maps.MapTypeId.ROADMAP > }); > > // Register event listeners > var dummyOverlay = new ProjectionHelperOverlay(map); > > google.maps.event.addDomListener(mapDIV, 'mousedown', > function(mEvent) { > //only handle left mouse button > if (mEvent.button != 0) return; > > var curElement = mapDIV; > var relativeLeft = mEvent.clientX + window.scrollX - > curElement.offsetLeft; > var relativeTop = mEvent.clientY + window.scrollY - > curElement.offsetTop; > > while ( curElement.offsetParent.tagName!="BODY" ) { > curElement = curElement.parentNode; > relativeLeft = relativeLeft - curElement.offsetLeft ; > relativeTop = relativeTop - curElement.offseTop ; > } > var projection = dummyOverlay.getProjection(); > var point = new google.maps.Point(relativeLeft,relativeTop); > var latLng = projection.fromContainerPixelToLatLng(point); > > var marker = new google.maps.Marker({ > position: latLng, > map: map, > }); > }); > } > > function ProjectionHelperOverlay(map) { > this.setMap(map); > } > > ProjectionHelperOverlay.prototype = new google.maps.OverlayView(); > ProjectionHelperOverlay.prototype.draw = function () { > if (!this.ready) { > this.ready = true; > google.maps.event.trigger(this, 'ready'); > } > }; > > google.maps.event.addDomListener(window, 'load', init); > </script> > </head> > <body> > <center> > <h2>Handle mouse down and mouse up event on a map div and > calculate the position of the mouse</h2> > > <table style='background-color:gray; width:650px; height:650px;'> > <tr> > <td> > <center> > <div id="map"></div> > </center> > </td> > </tr> > </table> > </center> > </body> > </html> > > On May 14, 2:27 pm, Ben Appleton <[email protected]> wrote: > > > > > > > You can listen for 'mousedown' / 'mouseup' DOM events on the map div, like > > google.maps.event.addDomListener(yourMapDiv, 'mousedown', alert); > > Does that suffice? > > > - Ben > > > On Fri, May 14, 2010 at 1:23 PM, Rossko <[email protected]> wrote: > > > > Thanks for your reply. The mouseup and mousedown events are not fired > > > > for the map object > > > > There are no documented map events 'mousedown' or 'mouseup' > > >http://code.google.com/apis/maps/documentation/v3/reference.html#Map > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Google Maps JavaScript API v3" group. > > > To post to this group, send email to > > > [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]<google-maps-js-api-v3%2B > > > [email protected]> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/google-maps-js-api-v3?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Google Maps JavaScript API v3" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/google-maps-js-api-v3?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Google Maps JavaScript API v3" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/google-maps-js-api-v3?hl=en. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
