Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery UI Button as Google Maps API (v3) Custom Control
    primarykey
    data
    text
    <p>I'd like to use a jQuery UI button as a custom control in Google Maps API (v3), but I'm having some trouble. All I get on my map is a plain old HTML push button without any jQuery styling. My guess is that when the jQuery UI <code>button()</code> method is called, the 'div' containing my custom control button has not yet been attached to the DOM. Here is a code snippet containing the basic implementation that I'm trying to achieve:</p> <pre><code>&lt;!-- GOOGLE MAPS API --&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;!-- CUSTOM JQUERY UI --&gt; &lt;link type="text/css" href="../jquery-ui-1.8.14.custom/css/ui-lightness/jquery-ui-1.8.14.custom.css" rel="stylesheet" /&gt; &lt;script type="text/javascript" src="../jquery-ui-1.8.14.custom/js/jquery-1.6.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="../jquery-ui-1.8.14.custom/js/jquery-ui-1.8.14.custom.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function() { var map = new google.maps.Map(document.getElementById("map_canvas"), { center: new google.maps.LatLng(0, 0), zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP }); var controlDiv = document.createElement('div'); var controlButton = document.createElement('button'); controlButton.innerHTML = 'Control Button'; controlDiv.appendChild(controlButton); // Add 'div' containing button to MVCArray in desired position on map map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv); $('button').button(); }); &lt;/script&gt; </code></pre> <p>In my Info Windows, I'm building jQuery Tabs after the 'domready' event has been fired. I'm wondering if there's anything similar for building custom map controls. Or is there some other trick to get this to work? Any help or suggestions would be appreciated, thanks!</p> <p><strong>Update 7/22/11</strong></p> <p>I tried fooling around with the MVCArray <code>'insert_at'</code> event by modifying the lines of code from above:</p> <pre><code>map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv); $('button').button(); </code></pre> <p>to the following:</p> <pre><code>google.maps.event.addListener(map.controls[google.maps.ControlPosition.RIGHT_BOTTOM], 'insert_at', function() { $('button').button(); }); map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].insertAt(map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].length, controlDiv); </code></pre> <p>This method is a bit more clumsy, but it seemed like a way to delay calling the jQuery <code>button()</code> method until after the the button element has been inserted into the map and attached to the DOM. Unfortunately, no luck. Still doesn't work. Probably some straightforward solution I'm missing!</p> <p>Documentation for the <code>insertAt()</code> method and <code>'insert_at'</code> event of the MVCArray class can be found here: <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#MVCArray" rel="nofollow">http://code.google.com/apis/maps/documentation/javascript/reference.html#MVCArray</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload