I used the code http://gmaps-samples-v3.googlecode.com/svn/trunk/infowindow_custom/infowindow-custom.html , which is currently the best example of how to create custom InfoWindow in Maps API v3. I worked on this, and so far I have it close to working, except for one, it is a div container, the text content will not expand to fit the content, so it just crashes, and does not expand the bubble. if I give the content container a fixed pixel width, it works fine, but I cannot make it expand depending on the amount of text in it.
I am stuck on this. Any help would be greatly appreciated!
Here is the HTML page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Gayborhood Map Test</title> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px } #map_canvas { width: 900px; height: 400px; margin: 200px auto 0 auto; } </style> <link rel="stylesheet" type="text/css" href="map.css" /> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <script type="text/javascript" src="InfoBox.js"></script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng(39.947137,-75.161824); var myOptions = { zoom: 16, center: latlng, mapTypeId: google.maps.MapTypeId.HYBRID }; var gayborhood; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var gayborhoodcoords = [ new google.maps.LatLng(39.9492017, -75.1631272), new google.maps.LatLng(39.945423, -75.1639561), new google.maps.LatLng(39.9450064, -75.160579), new google.maps.LatLng(39.9487765, -75.1597468), new google.maps.LatLng(39.9492017, -75.1631272) ]; gayborhood = new google.maps.Polygon({ paths: gayborhoodcoords, strokeColor: "#00ff00", strokeOpacity: 0.8, strokeWeight: 2, fillColor: "#00ff00", fillOpacity: 0.35 }); gayborhood.setMap(map); var image = 'red_icon.png'; var myLatLng = new google.maps.LatLng(39.948883,-75.162246); var redMarker = new google.maps.Marker({ position: myLatLng, map: map, icon: image }); var contentString = '<h4>Woody\ Bar</h4>'; google.maps.event.addListener(redMarker, 'mouseover', function() { var infoBox = new InfoBox({marker: redMarker, map: map}); }); } </script> </head> <body onload="initialize()"> <div id="map_canvas"></div> </body> </html>
Here is InfoBox.js:
function InfoBox(opts) { google.maps.OverlayView.call(this); this.marker_ = opts.marker this.latlng_ = opts.marker.getPosition(); this.map_ = opts.map; this.offsetVertical_ = -65; this.offsetHorizontal_ = -20; this.height_ = 50;
And here is the CSS:
.infobox { border: 0px none; position: absolute; width: auto; height: auto; } .infoboxContent { font-family: arial, helvetica, sans-serif; font-size: 15px; padding: 0px; margin: 9px 0px 0px -24px; position: absolute; z-index: 105; } .infoboxContainer { background: url('infowindow_bg.png') repeat-x; height: 50px; margin-left: 47px; } .bubbleLeftDiv { width: 47px; height: 50px; background: url('infowindow_left.png') no-repeat; position: absolute; z-index: 102; } .bubbleRightDiv { width: 26px; height: 50px; background: url('infowindow_right.png') no-repeat; position: absolute; right: -26px; top: 0px; } .clear { clear: both; }
Thanks!