<?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/"
	>

<channel>
	<title>Fetched from hammerspace</title>
	<atom:link href="http://hammerspace.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://hammerspace.co.uk</link>
	<description>Web, Words and Photography</description>
	<lastBuildDate>Sat, 06 Apr 2013 22:36:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The problem with responsive design</title>
		<link>http://hammerspace.co.uk/2012/07/the-problem-with-responsive-design</link>
		<comments>http://hammerspace.co.uk/2012/07/the-problem-with-responsive-design#comments</comments>
		<pubDate>Tue, 10 Jul 2012 23:27:38 +0000</pubDate>
		<dc:creator>David Jonathan Marland</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[media queries]]></category>
		<category><![CDATA[responsive design]]></category>
		<category><![CDATA[responsive images]]></category>

		<guid isPermaLink="false">http://hammerspace.co.uk/?p=192</guid>
		<description><![CDATA[Ok that title is a little hostile. Really this is just a problem with responsive design, or a suggestion for improvement. The problem is that although we can now make pages fluid and adaptable to the browser/device width they are still just &#8220;pages.&#8221; There is a basic canvas on which we lay everything out, a [...]]]></description>
			<content:encoded><![CDATA[<p>Ok that title is a little hostile. Really this is just <strong>a</strong> problem with <a href="http://www.alistapart.com/articles/responsive-web-design/" title="responsive design">responsive design</a>, or a suggestion for improvement.</p>
<p>The problem is that although we can now make pages fluid and adaptable to the browser/device width they are still just &#8220;pages.&#8221; There is a basic canvas on which we lay everything out, a paradigm still left over from the world of print. Things get better with a responsive grid but it needs to be more granular.</p>
<p><strong>A case study</strong><br />
I have an item with an image and some text. The image is a particular width (or percentage) and is floated left. To the right is the related text which fills the remaining space and does <strong>NOT</strong> wrap.<br />
<img src="http://hammerspace.co.uk/wp-content/uploads/2012/07/image1.png" alt="Item with floated text" title="Item with floated text" class="alignnone size-full wp-image-194" /></p>
<p>This is fairly easy to make flexible:<br />
<code>
<pre class="wp-code-highlight prettyprint">
&lt;div class=&quot;item&quot;&gt;
&lt;div class=&quot;image&quot;&gt;&lt;img src=&quot;img.png&quot; /&gt;&lt;/div&gt;
&lt;div class=&quot;text&quot;&gt;&lt;p&gt;Bacon ipsum....&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p></code><br />
<code>
<pre class="wp-code-highlight prettyprint">
.image {
   float: left;
   width: 19%;
   margin-right: 1%
}
.text {
   float: left;
   width: 80%;
}
</pre>
<p></code><br />
The flaw here is that in order to create the layout that doesn&#8217;t wrap the text container must have a width. This means both the image and the text have to have percentage widths or the float will break.<br />
Of course as the page gets thinner the 19% width image is going to get smaller and smaller and become unclear. So let&#8217;s add a media query. When things get too small let&#8217;s stack them but have the image fill the whole width:</p>
<p><img src="http://hammerspace.co.uk/wp-content/uploads/2012/07/image2.png" alt="Stacked version of image and text" title="Stacked version of image and text" class="alignnone size-full wp-image-203" /></p>
<p><code>
<pre class="wp-code-highlight prettyprint">
@media only all and (max-width: 320px) {
    .image {
        float: none;
        width: 100%;
        display: block;
        margin: 0 0 4px 0;
    }
    .text {
        float: none;
        width: 100%;
        display: block;
    }
}
</pre>
<p></code></p>
<p>This is all well and good when the item fills the whole page. But this is not print. This is the web, and on the web we like to reuse code. So what happens when I want to put the same module here:<br />
<img src="http://hammerspace.co.uk/wp-content/uploads/2012/07/image3.png" alt="" title="Module in main page area" width="515" height="309" class="alignnone size-full wp-image-206" /><br />
Or here:<br />
<img src="http://hammerspace.co.uk/wp-content/uploads/2012/07/image4.png" alt="" title="Module on right hand side" width="515" height="309" class="alignnone size-full wp-image-207" /></p>
<p>Media queries only target the &#8216;media&#8217; and therefore the browser window. When I put the same module into a smaller container I would like the media query to kick in, but unfortunately the browser window is still bigger.<br />
Surely there is a need for context specific query. When this module is this size on the page, do this, irrelevant of the wider page.</p>
<p>This brings me onto the current debate around the <a href="http://www.w3.org/community/respimg/2012/05/11/respimg-proposal/" title="Responsive Image Element">Responsive Image Element</a></p>
<p>There is certainly a need to be able to swap out images for larger versions. This way when taking the <a href="http://www.abookapart.com/products/mobile-first/" title="mobile first">mobile first</a> approach you can set the img src to a low resolution, low kilobyte image by default and have a bigger one download instead when required.<br />
The current proposal by WHATAG is the &lt;picture&gt; element:<br />
<code>
<pre class="wp-code-highlight prettyprint">
&lt;picture alt=&quot;&quot;&gt;
&lt;source src=&quot;mobile.jpg&quot; /&gt;
&lt;source src=&quot;large.jpg&quot; media=&quot;min-width: 600px&quot; /&gt;
&lt;source src=&quot;large_1.5x-res.jpg&quot; media=&quot;min-width: 600px, min-device-pixel-ratio: 1.5&quot; /&gt;
&lt;img src=&quot;mobile.jpg&quot; /&gt;
&lt;/picture&gt;
</pre>
<p></code><br />
This uses recognisable syntax with the media attribute and elements similar to the &lt;video&gt; element. The issue is the use of media will put us into the same trap as before; the size of the browser is not necessarily related to the size of the image. Take a look at the layout of boxes on my <a href="http://hammerspace.co.uk/" title="homepage">homepage</a>. As you make your browser window smaller the boxes adjust from three columns to one column. The images in those columns get smaller, then bigger, then smaller again. The &lt;picture&gt; element doesn&#8217;t cater for this scenario in a very scalable manner.<br />
The alternative proposal is adding a set attribute to the &lt;img&gt; element:<br />
<code>
<pre class="wp-code-highlight prettyprint">
&lt;img src=&quot;face-600-200@1.jpg&quot; alt=&quot;&quot; set=&quot;face-600-200@1.jpg 600w 200h 1x, face-600-200@2.jpg 600w 200h 2x, face-icon.png 200w 200h&quot;/&gt;
</pre>
<p></code><br />
Although the syntax is unusual, if the widths/heights declared in the attribute are the current width of the rendered element and are not relevant to the screen width then this could work out to be a more useful way of doing responsive images.</p>
<p>I shall be watching the outcome of the debate with much interest.</p>
]]></content:encoded>
			<wfw:commentRss>http://hammerspace.co.uk/2012/07/the-problem-with-responsive-design/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Responsive Design in Internet Explorer 10 / Windows 8</title>
		<link>http://hammerspace.co.uk/2012/04/responsive-design-in-internet-explorer-10-windows-8</link>
		<comments>http://hammerspace.co.uk/2012/04/responsive-design-in-internet-explorer-10-windows-8#comments</comments>
		<pubDate>Tue, 10 Apr 2012 22:18:09 +0000</pubDate>
		<dc:creator>David Jonathan Marland</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[responsive design]]></category>
		<category><![CDATA[windows 8]]></category>

		<guid isPermaLink="false">http://hammerspace.co.uk/?p=170</guid>
		<description><![CDATA[UPDATE 17/01/2013: Adding the piece of CSS recommended in this article will break responsive pages on the latest Windows Phone 8 with IE 10.0. It is recommended not to use this &#8220;fix&#8221; until that bug has been sorted. Follow this thread for more information. You&#8217;re probably well aware of responsive web design; a principle where [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE 17/01/2013:</strong> Adding the piece of CSS recommended in this article will break responsive pages on the latest Windows Phone 8 with IE 10.0. It is recommended not to use this &#8220;fix&#8221; until that bug has been sorted. Follow <a href="https://github.com/h5bp/html5-boilerplate/pull/1243">this thread</a> for more information.</p>
<p>You&#8217;re probably well aware of <a href="http://www.alistapart.com/articles/responsive-web-design/" title="Responsive web design">responsive web design</a>; a principle where you no longer build your website to a fixed 960 pixels wide, but allow it to adapt and flex to fit wherever it happens to be.</p>
<p>There is a massive range of screen sizes from phone to smart phone to tablet to desktop and even black and white devices like the Amazon Kindle. Each of these comes with their own set of challenges but it looks like there is a new kid coming up on the block.</p>
<p><img src="https://lh6.googleusercontent.com/-W_ATBC9jgUM/T4SrEinHYtI/AAAAAAAAANk/MCY2o09kVYM/s800/Windows_8_Consumer_Preview_Start_Screen.png" alt="Windows 8 Start screen" /><br />
<a href="http://windows.microsoft.com/en-US/windows-8/consumer-preview" title="Windows 8">Windows 8</a> offers a radically new desktop/tablet experience and will support a range of hardware devices. Application developers for windows 8 will need to be aware of <a href="http://blogs.msdn.com/b/b8/archive/2012/03/21/scaling-to-different-screens.aspx" title="Scaling to different screens">scaling for different screens</a>.</p>
<p>Note: At the time of writing Windows 8 is still in Consumer preview so any of this is subject to change before general release.</p>
<h2>Internet Explorer 10</h2>
<p>In testing Internet Explorer 10 on Windows 8 I noticed that when you snap a site to the side the page was simply zooming out making it unreadable. It was quite a challenge to discover why but it appears that Internet Explorer 10 <a href="http://msdn.microsoft.com/library/ie/hh708740.aspx#Example_usage__Opting_out_of_automatic_scaling" title="Device adaptation">zooms the page out</a> when the width is less than 1024px. This may also affect portrait orientation but I am unable to confirm at present as I have the preview on my standard laptop.</p>
<p>This effect is irritating for those who spent a fair bit of time and effort working on their responsively designed pages. You can see the effect on <a href="http://hammerspace.co.uk/projects/ie10responsive/" title="Demo 1">this demo page</a>. A picture of what happens is shown below:</p>
<p><img src="https://lh3.googleusercontent.com/-NXiG5TjcC40/T4SrElwIALI/AAAAAAAAANk/A0QYB3vU-Us/s800/1.jpg" alt="Screenshot 1" /><br />
<em>Excuse the photograph; I couldn&#8217;t get a screenshot in Windows 8 + Mac keyboard.</em></p>
<p>The site on the left is zoomed out and unusable.</p>
<h2>Solution</h2>
<p>As I discovered buried in the <a href="http://msdn.microsoft.com/library/ie/hh708740.aspx#Example_usage__Opting_out_of_automatic_scaling" title="Device adaptation">device adaptation</a> page there is a simple solution that tells Internet Explorer 10 to disable its automatic scaling and adhere to your responsive designs. Simply add the following to your CSS file:</p>
<pre class="wp-code-highlight prettyprint">
@-ms-viewport { width: device-width; }
</pre>
<p>You can see this in action in <a href="http://hammerspace.co.uk/projects/ie10responsive/fixed.html" title="Demo 2">the second demo page</a>. The change has produced the desired effect in a snapped window (on the left):<br />
<img src="https://lh4.googleusercontent.com/-_G-maUwelGQ/T4SrE9REKII/AAAAAAAAANk/BxknczcB9Gk/s800/2.jpg" alt="Screenshot 2" /></p>
<p><strong>Update:</strong> <a href="https://github.com/h5bp/html5-boilerplate/issues/1047#issuecomment-5071828">necolas</a> makes a good point that it is not optimal to have to do this and it should be considered an IE10 bug. <a href="https://github.com/h5bp/html5-boilerplate/issues/1047">Further discussion here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://hammerspace.co.uk/2012/04/responsive-design-in-internet-explorer-10-windows-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS3 gradients with transparency</title>
		<link>http://hammerspace.co.uk/2012/02/css3-gradients-with-transparency</link>
		<comments>http://hammerspace.co.uk/2012/02/css3-gradients-with-transparency#comments</comments>
		<pubDate>Sat, 11 Feb 2012 20:47:39 +0000</pubDate>
		<dc:creator>David Jonathan Marland</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[alpha transparent]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[gradients]]></category>
		<category><![CDATA[rgba]]></category>

		<guid isPermaLink="false">http://hammerspace.co.uk/?p=155</guid>
		<description><![CDATA[As you are probably aware CSS3 introduces gradient backgrounds allowing some quite creative designs. However I&#8217;ve been bitten by an interesting quirk when using transparency in gradients. You&#8217;d expect that to create a gradient which fades out from a certain colour you&#8217;d just use: background: linear-gradient(top,#FFFFFF 0%,transparent 100%); See Example 2 for a working demo. [...]]]></description>
			<content:encoded><![CDATA[<p>As you are probably aware CSS3 introduces <a href="http://gradients.glrzad.com/" title="Gradient Background Generator">gradient</a> <a href="http://hallofhavoc.com/2011/08/how-to-use-css3-gradients-for-various-browsers/">backgrounds</a> allowing some quite creative designs.</p>
<p>However I&#8217;ve been bitten by an interesting quirk when using transparency in gradients. You&#8217;d expect that to create a gradient which fades out from a certain colour you&#8217;d just use:</p>
<pre class="wp-code-highlight prettyprint">
background: linear-gradient(top,#FFFFFF 0%,transparent 100%);
</pre>
<p>See <a href="/projects/gradient/">Example 2</a> for a working demo.</p>
<p><img src="http://hammerspace.co.uk/wp-content/uploads/2012/02/Screen-Shot-2012-02-11-at-20.35.09-300x147.png" alt="" title="Ugly Grey" width="300" height="147" class="alignnone size-medium wp-image-158" /></p>
<p>The effect is not as desired as browsers do not treat the value [transparent] as you might intuitively expect. The CSS3 colour spec <a href="http://www.w3.org/TR/css3-color/#transparent-def">states</a> that [transparent] can be considered a shorthand for transparent black, rgba(0,0,0,0).</p>
<p>Therefore the browsers are actually fading from white to black independently to fading from opaque to transparent. If you are not aware of this then it&#8217;s easy to end up with the ugly grey in the middle of your gradient. The <a href="http://dev.w3.org/csswg/css3-images/#color-stop-syntax">CSS3 Images spec</a> (Last Call Working Draft as of 11th Feb 2012) shows how this should not be the case. At present only Opera appears to use premultiplied values and behave correctly, fading out without going via black.</p>
<p><strong>Update: </strong>IE10 (the first version of IE to support gradients) also behaves correctly for this. <strong>End Update</strong></p>
<p><strong>Workaround</strong><br />
Until the browsers support the correct implementation the simple (obvious) workaround is to resort to rgba. This isn&#8217;t too much of a drawback as rgba is supported in all the browsers that support gradient backgrounds. You just need to remember that the red,green and blue values are the same in both stops and the alpha value changes from 1 to 0.</p>
<pre class="wp-code-highlight prettyprint">
background: linear-gradient(top,rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
</pre>
<p><img src="http://hammerspace.co.uk/wp-content/uploads/2012/02/Screen-Shot-2012-02-11-at-20.37.06.png" alt="" title="Cleaner fade out" width="266" height="155" class="alignnone size-full wp-image-160" /></p>
<p>See <a href="/projects/gradient/">example 3 on the demo page</a> for a live example</p>
]]></content:encoded>
			<wfw:commentRss>http://hammerspace.co.uk/2012/02/css3-gradients-with-transparency/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Truncate at space, Zend View Helper</title>
		<link>http://hammerspace.co.uk/2011/10/truncate-at-space-zend-view-helper</link>
		<comments>http://hammerspace.co.uk/2011/10/truncate-at-space-zend-view-helper#comments</comments>
		<pubDate>Wed, 19 Oct 2011 23:19:19 +0000</pubDate>
		<dc:creator>David Jonathan Marland</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[truncate]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://hammerspace.co.uk/?p=121</guid>
		<description><![CDATA[When writing web applications you may frequently find the need to truncate strings. In php you could just use substr but that could be dangerous. Therefore the safest idea is to truncate back to the nearest space. The code below is a Zend View Helper, constructed in a way to read cleanly in the page. [...]]]></description>
			<content:encoded><![CDATA[<p>When writing web applications you may frequently find the need to <a href="http://www.thefreedictionary.com/truncate" data-mce-href="http://www.thefreedictionary.com/truncate">truncate</a> strings. In php you <strong>could</strong> just use <a href="http://php.net/manual/en/function.substr.php" data-mce-href="http://php.net/manual/en/function.substr.php">substr</a> but that could be <a href="http://picchore.com/funny/carrots-glazed-with-what/" data-mce-href="http://picchore.com/funny/carrots-glazed-with-what/">dangerous</a>.</p>
<p>Therefore the safest idea is to truncate back to the nearest space. The code below is a Zend View Helper, constructed in a way to read cleanly in the page. It&#8217;s use in a Zend View is as follows:</p>
<pre class="wp-code-highlight prettyprint">&lt; ?$string = 'Hello People';?&gt;
&lt; ?=$this-&gt;truncate($string)-&gt;toLength(10)?&gt;
&lt; ?=$this-&gt;truncate($string)-&gt;toLength(10)-&gt;withPostfix('--')?&gt;
&lt; ?=$this-&gt;truncate($string)-&gt;midword()-&gt;toLength(10)-&gt;withPostfix('--')?&gt;</pre>
<p>As each method returns itself they can be chained together. The above outputs;</p>
<pre class="wp-code-highlight prettyprint">Hello…
Hello--
Hello peop--</pre>
<p>Methods</p>
<pre class="wp-code-highlight prettyprint">toLength($int) - the max string length to cut to
midword() - disable the safe truncation (probably not recommended) withPostfix($string) - replace the default postfix (...) with $string</pre>
<h2>Full class code</h2>
<pre class="wp-code-highlight prettyprint">&lt; ?php
class Zend_View_Helper_Truncate extends Zend_View_Helper_Abstract {
        private $_string;
        private $_length;
        private $_postfix;
        private $_cutatspace = true;

        public function truncate($string) {
            $this-&gt;_string = trim($string);
            $this-&gt;_defaultValues();
            return $this;
        }

        private function _defaultValues() {
            $this-&gt;toLength(100);
            $this-&gt;withPostfix('&amp;#0133;');
         }

        public function midword() {
            $this-&gt;_cutatspace = false;
            return $this;
        }

        public function toLength($int) {
            $this-&gt;_length = (int) $int;
            return $this;
        }
        public function withPostfix($str) {
            $this-&gt;_postfix = $str;
            return $this;
        }

        public function render() {
            // Return empty string if max length &lt; 1
            if ($this-&gt;_length &lt; 1) {
                return '';
            }

            // Return full string if max length &gt;= string length
            if ($this-&gt;_length &gt;= strlen($this-&gt;_string)) {
                return $this-&gt;_string;
            }

            // Return truncated string
            if ($this-&gt;_cutatspace) {
                while (strlen($this-&gt;_string) &gt; $this-&gt;_length) {
                    $cutPos = strrpos($this-&gt;_string, ' ', -1);
                    if ($cutPos === false) {
                        // no spaces left, whole string truncated
                        return '';
                    }
                    $this-&gt;_string = trim(substr($this-&gt;_string, 0, $cutPos));
                }
            } else {
                $this-&gt;_string = trim(substr($this-&gt;_string, 0, $this-&gt;_length));
            }
            return $this-&gt;_string . $this-&gt;_postfix;
        }

        public function __toString() {
            return $this-&gt;render();
        }
}</pre>
<p><strong>Update 11/02/2012: </strong><a href="http://www.monkeyhybrid.com/" title="Steve">Steve</a> noted an issue with this helper. I have updated the code above based on his suggestion. Thanks Steve.</p>
]]></content:encoded>
			<wfw:commentRss>http://hammerspace.co.uk/2011/10/truncate-at-space-zend-view-helper/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Google Maps API points in polygons</title>
		<link>http://hammerspace.co.uk/2011/10/google-maps-api-points-in-polygons</link>
		<comments>http://hammerspace.co.uk/2011/10/google-maps-api-points-in-polygons#comments</comments>
		<pubDate>Wed, 19 Oct 2011 21:51:30 +0000</pubDate>
		<dc:creator>David Jonathan Marland</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://hammerspace.co.uk/?p=111</guid>
		<description><![CDATA[Update 27th March 2012: The Google Maps Geometry library now contains a containsLocation method which will achieve the same thing as detailed below. I&#8217;d recommend you use that instead. Discovering whether a point on a map is inside a polygon can be very useful, especially now that modern browsers and phones are location aware. If [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Update 27th March 2012:</strong> The Google Maps <a href="https://developers.google.com/maps/documentation/javascript/geometry">Geometry library</a> now contains a <a href="https://developers.google.com/maps/documentation/javascript/reference#poly">containsLocation</a> method which will achieve the same thing as detailed below. I&#8217;d recommend you use that instead.</p></blockquote>
<p>Discovering whether a point on a map is inside a polygon can be very useful, especially now that modern browsers and phones are location aware. If you can tell if your user is within a specific boundary then you can present them with immediately relevant information. An example I have used is telling the user they are in the coverage area of a local business (<a href="http://gascall.co/map">Gascall</a>).</p>
<p>Assuming you&#8217;ve already <a href="http://code.google.com/apis/maps/documentation/javascript/tutorial.html">set up your map</a>, the <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#Polygon">Google maps API</a> allows you to create polygons using simple code.</p>
<pre class="wp-code-highlight prettyprint">
var path = [
    new google.maps.LatLng(51.73383267274113, -1.03271484375),
    new google.maps.LatLng(51.45400691005984, -1.4501953125),
    new google.maps.LatLng(51.83577752045251, -0.8843994140625)];
    var polygon = new google.maps.Polygon({path:path, clickable:false});
    polygon.setMap(map);
</pre>
<p>You can create a Google maps point from latitude/longitude values or the users location:</p>
<pre class="wp-code-highlight prettyprint">
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
        var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    });
}
</pre>
<h2>Determining if the point is inside the polygon</h2>
<p>The google maps api does not already provide a method for checking points in polygons. Some <a href="http://appdelegateinc.com/blog/2010/05/16/point-in-polygon-checking/">research</a> has already been done on this, but I couldn&#8217;t find a complete solution in Google maps api v3 that also catered for crossing 180 degrees longitude. I would have done a straight translation into Google maps api v3, but decided to actually try to understand what was going on.</p>
<p>After researching a bit I stumbled across the <a href="http://rosettacode.org/wiki/Ray-casting_algorithm">Ray-casting algorithm</a> which will determine if an X-Y coordinate is inside a plotted shape. This will translate to latitude and longitude. The following extends the google.maps.polygon.prototype to use this algorithm. Simply include this code at a point in the code after google.maps has loaded:</p>
<pre class="wp-code-highlight prettyprint">
 google.maps.Polygon.prototype.Contains = function(point) {
        // ray casting alogrithm http://rosettacode.org/wiki/Ray-casting_algorithm
        var crossings = 0,
            path = this.getPath();

        // for each edge
        for (var i=0; i &lt; path.getLength(); i++) {
            var a = path.getAt(i),
                j = i + 1;
            if (j &gt;= path.getLength()) {
                j = 0;
            }
            var b = path.getAt(j);
            if (rayCrossesSegment(point, a, b)) {
                crossings++;
            }
        }

        // odd number of crossings?
        return (crossings % 2 == 1);

        function rayCrossesSegment(point, a, b) {
            var px = point.lng(),
                py = point.lat(),
                ax = a.lng(),
                ay = a.lat(),
                bx = b.lng(),
                by = b.lat();
            if (ay &gt; by) {
                ax = b.lng();
                ay = b.lat();
                bx = a.lng();
                by = a.lat();
            }
            // alter longitude to cater for 180 degree crossings
            if (px &lt; 0) { px += 360 };
            if (ax &lt; 0) { ax += 360 };
            if (bx &lt; 0) { bx += 360 };

            if (py == ay || py == by) py += 0.00000001;
            if ((py &gt; by || py &lt; ay) || (px &gt; Math.max(ax, bx))) return false;
            if (px &lt; Math.min(ax, bx)) return true;

            var red = (ax != bx) ? ((by - ay) / (bx - ax)) : Infinity;
            var blue = (ax != px) ? ((py - ay) / (px - ax)) : Infinity;
            return (blue &gt;= red);

        }

     };
</pre>
<p>Then to check a point:</p>
<pre class="wp-code-highlight prettyprint">
var point = new google.maps.LatLng(52.05249047600099, -0.6097412109375);
var polygon = new google.maps.Polygon({path:[INSERT_PATH_ARRAY_HERE]});
if (polygon.Contains(point)) {
    // point is inside polygon
}
</pre>
<p>I hope this proves useful. Let me know if you have any suggestions/comments. <a href="/projects/maps/">Test page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hammerspace.co.uk/2011/10/google-maps-api-points-in-polygons/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross browser alpha transparent background CSS (rgba)</title>
		<link>http://hammerspace.co.uk/2011/10/cross-browser-alpha-transparent-background-css</link>
		<comments>http://hammerspace.co.uk/2011/10/cross-browser-alpha-transparent-background-css#comments</comments>
		<pubDate>Sun, 09 Oct 2011 16:20:52 +0000</pubDate>
		<dc:creator>David Jonathan Marland</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[alpha transparent]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[rgba]]></category>

		<guid isPermaLink="false">http://hammerspace.co.uk/?p=41</guid>
		<description><![CDATA[In building the BBC Programmes website the design called for various layers of semi-transparent coloured boxes. These colours can change depending on the programme (for example: Never Mind the Buzzcocks) so an alpha transparent PNG is not a maintainable option. Obviously the simplest method is RGBA. #div { background: rgba(0,0,255,0.7); } As elegant as that is, [...]]]></description>
			<content:encoded><![CDATA[<p>In building the <a href="http://www.bbc.co.uk/programmes">BBC Programmes</a> website the design called for various layers of semi-transparent coloured boxes. These colours can change depending on the programme (for example: <a href="http://www.bbc.co.uk/programmes/b006v0dz">Never Mind the Buzzcocks</a>) so an alpha transparent PNG is not a maintainable option.<br />
Obviously the simplest method is <a href="http://www.w3.org/TR/css3-color/">RGBA</a>.</p>
<pre class="wp-code-highlight prettyprint">
#div {
    background: rgba(0,0,255,0.7);
}
</pre>
<p>As elegant as that is, it is not currently an acceptable solution in it&#8217;s own right. RGBA is not supported in Internet Explorer <a href="http://caniuse.com/css3-colors">below version 9</a>. Of course the BBC needs to <a href="http://www.bbc.co.uk/guidelines/futuremedia/technical/browser_support.shtml#support_table">support</a> the majority of it&#8217;s visitors. The phrase &#8220;it doesn&#8217;t need to look the same in every browser&#8221; could be thrown about, but in this case the semi-transparent boxes are quite essential for the look desired.</p>
<p>So, as any good web developer does, I turned to Google. I thought it would be a simple query (expected it to use IE filters) but it took unusually long to find it. Eventually I arrived at <a href="http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/">this blog post</a> which proved helpful.</p>
<p>Alpha-transparent background code (<a href="http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters">quoted</a>)</p>
<pre class="wp-code-highlight prettyprint">
.alpha60 {
	/* Fallback for web browsers that doesn't support RGBa */
	background: rgb(0, 0, 0);
	/* RGBa with 0.6 opacity */
	background: rgba(0, 0, 0, 0.6);
	/* For IE 5.5 - 7*/
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);
	/* For IE 8*/
	-ms-filter: &quot;progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)&quot;;
}
</pre>
<h2>BUT</h2>
<p>There appeared to be a problem with this once we saw it in the wild. First you have to add zoom:1 to make it work in IE6-7 but this isn&#8217;t unusual. Secondly IE8 didn&#8217;t seem to work. As IE8 does support rgb() as a background colour the result is a solid coloured box.</p>
<p>Therefore we need to set the background back to transparent after the rgb rule (just in IE8 and below). After more Googling the answer was the <a href="http://webdood.com/?p=57">backslash 9 hack</a>.</p>
<p>Using that and tweaking (a lot) produced the following block of code. Note the -ms-filter line supported as IE8+ has been removed as it unnecessary. We have to use the non prefixed version anyway (for IE6,7) so the code is no more valid by using it in this scenario</p>
<pre class="wp-code-highlight prettyprint">
#div {
    background:rgb(255,0,0);
    background: transparent\9;
    background:rgba(255,0,0,0.3);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#4cFF0000,endColorstr=#4cFF0000);
    zoom: 1;
}
</pre>
<p>This fixed the transparency problem but there was a new issue. Internet Explorer 9 is capable of displaying rgba <strong>AND</strong> the filter property. This creates a doubling up of the transparency and ruining it&#8217;s effects. It appears there is no CSS attribute hack that targets only IE8 or IE9 and not both (that has been discovered yet).</p>
<p>The ideal solution here is to not use the filter in IE9. The CSS filters are memory intensive and since IE9 is fully capable of rgba, it should be rewarded as such. IE9 is <a href="http://kimblim.dk/css-tests/selectors/">capable of many CSS3 selectors</a> so we&#8217;ll use one here:</p>
<pre class="wp-code-highlight prettyprint">
#div:nth-child(n) {
    filter:none;
}
</pre>
<p>This is a valid CSS selector that will match all elements in the same way as if it was not here. <a href="http://css-tricks.com/5452-how-nth-child-works/">More detail on how nth-child works</a>.</p>
<p><a href="/projects/alpha/test.html">This page shows various test scenarios</a></p>
<h2>Full code</h2>
<pre class="wp-code-highlight prettyprint">
#div{
    background:rgb(255,0,0);
    background: transparent\9;
    background:rgba(255,0,0,0.3);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#4cFF0000,endColorstr=#4cFF0000);
    zoom: 1;
}
#div:nth-child(n) {
    filter: none;
}
</pre>
<p>So that&#8217;s the code required. I&#8217;ve put it here as a complete solution to save other developers having to search and test as much as I had to. Of course it&#8217;s recommended to use <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">conditional classes</a> instead but sometimes that&#8217;s just not possible.</p>
<p>The only other thing that slows down creating alpha transparent backgrounds is the conversion from hex -> rgba and opacity -> hex so below is a handy converter. Enter a hex colour and opacity value and it&#8217;ll spit out the code in the form seen above.</p>
<p>I&#8217;ll accept any tweaks/improvements in the comments.</p>
<p><iframe src="/projects/alpha/" height="400"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://hammerspace.co.uk/2011/10/cross-browser-alpha-transparent-background-css/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Start&#8230;</title>
		<link>http://hammerspace.co.uk/2011/09/start</link>
		<comments>http://hammerspace.co.uk/2011/09/start#comments</comments>
		<pubDate>Sun, 04 Sep 2011 12:32:58 +0000</pubDate>
		<dc:creator>David Jonathan Marland</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[introduction]]></category>

		<guid isPermaLink="false">http://hammerspace.co.uk/?p=31</guid>
		<description><![CDATA[Hello. I&#8217;ve finally created a blog, so hello world &#60;/cliché&#62; Who am I? I am David Jonathan Marland and I am a web developer. My plan is to use this blog to put up snippets of code that may be of interest to others. I will also put up bits of photography as I like to [...]]]></description>
			<content:encoded><![CDATA[<p>Hello. I&#8217;ve finally created a blog, so hello world &lt;/cliché&gt;</p>
<p><strong>Who am I?</strong></p>
<p>I am <a title="rland" href="http://rland.me.uk">David Jonathan Marland</a> and I am a web developer. My plan is to use this blog to put up snippets of code that may be of interest to others. I will also put up bits of photography as I like to play every now and then.</p>
<p>As you can tell this blog is quite plain at the moment and may even be slightly broken in places. I intend to over time evolve it by building a wordpress theme from scratch that is HTML5, responsive design (mobile first). I will document what I learn as I go, so keep following to see the changes.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://hammerspace.co.uk/2011/09/start/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
