<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>In usability we trust &#187; Code</title>
	<atom:link href="http://www.svennerberg.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.svennerberg.com</link>
	<description>A blog about web developement and usability.</description>
	<lastBuildDate>Thu, 22 Jul 2010 23:18:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Announcing MapTooltip</title>
		<link>http://www.svennerberg.com/2009/03/announcing-maptooltip/</link>
		<comments>http://www.svennerberg.com/2009/03/announcing-maptooltip/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:28:31 +0000</pubDate>
		<dc:creator>Gabriel Svennerberg</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Library]]></category>

		<guid isPermaLink="false">http://www.svennerberg.com/?p=1695</guid>
		<description><![CDATA[One of the shortcomings in the Google Maps API is that there&#8217;s no easy way to add tooltips to polylines and polygons. That&#8217;s why I felt inclined to build an extension to Google Maps that adds that functionality. MapTooltip makes it possible to add tooltips to any kind of overlay. It&#8217;s even possible to have [...]]]></description>
			<content:encoded><![CDATA[<p>One of the shortcomings in the  Google Maps <acronym title="Application Programming Interface">API</acronym> is that there&#8217;s no easy way to add tooltips to polylines and polygons. That&#8217;s why I felt inclined to build an extension to Google Maps that adds that functionality. MapTooltip makes it possible to add tooltips to any kind of overlay. It&#8217;s even possible to have <acronym title="HyperText Markup Language">HTML</acronym> inside it and to style it to fit your design needs.</p>
<p><img src="http://media.svennerberg.com/2009/03/screenshot1.png" alt="" class="alignnone border" /></p>
<p><span id="more-1695"></span></p>
<h3>About MapTooltip</h3>
<p>In a project I&#8217;m working on there&#8217;s a need to have tooltips on polylines. I have tried to find simple ways of doing this but haven&#8217;t been able to find any. After researching this and eventually coming up with a solution I decided to package it into a small library so that I could share it with fellow Google Maps developers.</p>
<h3>Reference</h3>
<p>The constructor creates an object of the type MapTooltip. It takes two required arguments and one optional.</p>
<p><code>MapTooltip(reference:object, tooltip:string, opts?:object)</code></p>
<h4>reference</h4>
<p>The first argument, <code>reference</code>, is a reference to the overlay that you will attach the tooltip to, for example a GPolyline. </p>
<h4>tooltip</h4>
<p>The second argument, <code>tooltip</code>, is a string containing what will appear inside of the tooltip. You can either provide just a plain text string or some <acronym title="HyperText Markup Language">HTML</acronym>.</p>
<h4>opts</h4>
<p>The third argument which is optional, <code>opts</code>, is an object literal that contains all options on how the tooltip will look and behave. It can have the following settings:</p>
<ul>
<li><strong>width</strong><br />
The width of the tooltip, ex: &#8220;100px&#8221;</li>
<li><strong>padding</strong><br />
The padding around the content of the tooltip<br />
For a 3px padding: &#8220;3px&#8221;<br />
For a 2px top/bottom padding and a 5px left/right padding: &#8220;2px 5px&#8221;</li>
<li><strong>backgroundColor</strong><br />
Backgroundcolor of the tooltip, ex: &#8220;#ff9&#8243;</li>
<li><strong>color</strong><br />
The color of the text inside the tooltip, ex: &#8220;#000&#8243;</li>
<li><strong>border</strong><br />
The styling of the border of the tooltip, ex: &#8220;1px solid green&#8221;</li>
<li><strong>fontSize</strong><br />
The size of the text inside the tooltip, ex: &#8220;1em&#8221;</li>
<li><strong>offsetX</strong><br />
The horizontal distance in pixels from the pointer to the tooltip, ex &#8220;10&#8243;</li>
<li><strong>offsetY</strong><br />
The vertical distance in pixels from the pointer to the tooltip, ex: &#8220;10&#8243;</li>
</ul>
<p>It might for example look like this:</p>
<pre name="code" class="js">
var options = {
    'width': '250px',
    'border': '3px dotted #00f'
}
</pre>
<h3>Using MapTooltip</h3>
<p>To use MapTooltip is pretty easy. First add a Google Map as you normally would. Then follow the steps below to attach a tooltip to an object in the map.</p>
<h4>1. Load the library</h4>
<p>Import the library to the web page with the script tag.</p>
<pre name="code" class="html">
&lt;script src="http://maptooltip.googlecode.com/files/mapTooltip.js" type="text/javascript"&gt;&lt;/script&gt;</code>
</pre>
<h4>2. Attach appropriate events</h4>
<p>Add a mouseover event to the object on your map that you wish to have a tooltip. You will also have to add a mouseout event that removes the tooltip.</p>
<pre name="code" class="js">
// Attach mouseover event to a polyline that will trigger the tooltip
GEvent.addListener(polyline, 'mouseover', function() {
	this.overlay = new MapTooltip(this, 'This is a polyline');
	map.addOverlay(this.overlay);
	// Attach mousout event to the polyline that will delete the tooltip
	GEvent.addListener(polyline, 'mouseout', function() {
		map.removeOverlay(this.overlay);
	});
});
</pre>
<p>That&#8217;s it. Be sure to <a href="http://www.svennerberg.com/examples/maptooltip/"> check out the live demo</a> to see it in action. The demo includes tooltips attached to markers, polylines and polygons. One of the tooltip is styled in a different way using the <code>opts</code> parameter.</p>
<div class="image">
<a href="http://www.svennerberg.com/examples/maptooltip/" title="The live demo page of MapToolTip"><img src="http://media.svennerberg.com/2009/03/demo-410x398.png" alt="" class="alignnone" /></a></p>
<p><a href="http://www.svennerberg.com/examples/maptooltip/">Check out the live demo</a></p>
</div>
<h3>Copyright</h3>
<p>MapTooltip is released under the <a href="http://www.opensource.org/licenses/mit-license.php"><acronym title="Massachusetts Institute of Technology">MIT</acronym> License</a> and is free for any use. </p>
<h3>Downloads</h3>
<p><a href="http://maptooltip.googlecode.com/files/mapTooltip.js">mapTooltip.js</a></p>
<h3> Acknowledgments</h3>
<p>MapTooltip is heavily influenced by the article <a href="http://danmarvelo.us/older/2007/9/10/custom-info-window-for-google/">Custom Info Window / Popup for Google Maps, or Loving the GOverlay</a>. </p>
<h3>Known bugs</h3>
<p>If you import the Google Maps <acronym title="Application Programming Interface">API</acronym> with ver=2.x it&#8217;s not going to work as expected since it seems that it doesn&#8217;t handle mouseover events on GMap2 when the pointer is over an GOverlay quite the same way as in previous versions. I don&#8217;t know if this is a temporary glitch or if it&#8217;s supposed to work this way in the future.</p>
<p class="note"><strong>Update [2009-04-11]:</strong> In the latest release of the Google Maps <acronym title="Application Programming Interface">API</acronym> the above mentioned problems currently occur. I will try to find a way around, but until then you can stick to version 2.151 to make it work correctly.</p>
<p>For ideas on this or for other bugs you might encounter, please contact me either in the comments or through the <a href="http://www.svennerberg.com/contact/">Contact page</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.svennerberg.com/2009/03/announcing-maptooltip/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
