views:

418

answers:

1

I am using the following code to show a jQuery UI dialog when the mouse is clicked on the map:

GEvent.addListener(map, "click", clicked);

function clicked(overlay, latlng) {
   $('#dialog').show();
};

Both clicked function and show() function works fine on their own but when I want to open dialog box by clicking on the map it does not. Any ideas?

A: 

You may want to check out the following example:

<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps jQuery UI Demo</title> 
   <link type="text/css" href="themes/base/jquery.ui.all.css" rel="stylesheet" /> 
   <script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=false" 
              type="text/javascript"></script>
   <script src="http://code.jquery.com/jquery-1.4.2.min.js" 
           type="text/javascript"></script>
   <script src="jquery-ui-1.8.custom.min.js" type="text/javascript"></script>

</head> 
<body onunload="GUnload()">
   <div id="map" style="width: 450px; height: 300px"></div> 
   <div id="dialog" title="Basic Dialog" style="display: none;">Dialog</div>

   <script type="text/javascript"> 
      var map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(37.4419, -122.1419), 13);

      GEvent.addListener(map, "click", function(overlay, latlng) {
         $('#dialog').dialog();
      });
   </script> 
</body> 
</html>

Screenshot:

alt text

Daniel Vassallo
Well, I think that's what I ve got.
Vafello
@Vafello: I've tested it as is, and the dialog div shows when the map is clicked. I was going to try it with the full jQuery UI dialog, but I assume it would work. Did you check for errors in Firebug?
Daniel Vassallo
Works with alert() but not necessarily with this jquery show() function...
Vafello
Did you try: `$('#dialog').dialog();` instead? ... Check my updated example.
Daniel Vassallo
Yes, but didnt work..
Vafello
Strange it doesn't work for me..
Vafello
Check the live preview on jsBin: http://jsbin.com/apeso/edit. Simply click the Preview button to run it.
Daniel Vassallo
Tested that example in Chrome, Safari, Opera and Firefox (on Mac).
Daniel Vassallo
OK, thanks. This must be something wrong with my code.
Vafello
I had a small issue in that jsBin code in Firefox. Apparently Google Maps has to be included before jQuery UI for it to work correctly. Fixed now... Use this as a reference: http://jsbin.com/ugesi/edit
Daniel Vassallo
I made some progress. I placed UI initialisation code before I call the function and it works. But strangely, there is close button missing...
Vafello
Now it works, but dialog content when the page is initialised is placed in a div on the site as well, not only in the dialog box.
Vafello