<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"><generator uri="http://www.habariproject.org/" version="0.9.2">Habari</generator><id>tag:looseideas.co.uk,2015-01-29:atom/dd035d9c8b92fbaa2315aab5f351e1cb3f863bbc</id><title>Looseideas.co.uk - Ryan Mitchell</title><updated>2014-08-20T12:35:57+01:00</updated><link rel="alternate" href="http://looseideas.co.uk/"/><link rel="self" href="http://looseideas.co.uk/atom/1"/><link rel="first" href="http://looseideas.co.uk/atom/1/page/1" type="application/atom+xml" title="First Page"/><link rel="next" href="http://looseideas.co.uk/atom/1/page/2" type="application/atom+xml" title="Next Page"/><link rel="last" href="http://looseideas.co.uk/atom/1/page/8" type="application/atom+xml" title="Last Page"/><entry><title>Using MarkerClusterer and MarkerWithLabel with Google Maps</title><link rel="alternate" href="http://looseideas.co.uk/using-markerclusterer-markerwithlabel"/><link rel="edit" href="http://looseideas.co.uk/using-markerclusterer-markerwithlabel/atom"/><author><name>Ryan Mitchell</name><uri>http://looseideas.co.uk</uri></author><id>tag:www.looseideas.co.uk,2014:using-markerclusterer-markerwithlabel/1408531952</id><updated>2014-08-20T12:35:57+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2014-08-21T11:31:16+01:00</app:edited><published>2014-08-20T11:48:44+01:00</published><category term="javascript"/><category term="markerclusterer"/><category term="markerwithlabel"/><category term="google-maps"/><content type="html">&lt;p&gt;Both MarkerClusterer and MarkerWithLabel are great libraries, but they do have their quirks;&lt;/p&gt;&#xD;
&#xD;
&lt;h2&gt;MarkerClusterer&lt;/h2&gt;&#xD;
&#xD;
&lt;dl&gt;&#xD;
	&lt;dt&gt;What is a cluster marker?&lt;/dt&gt;&#xD;
	&lt;dd&gt;MarkerClusterer doesn't use Google Markers or pin styles, it takes an image path and creates HTML on a layer. The resultant markup is given a class of 'cluster' that you can target in your CSS.&lt;/dd&gt;&#xD;
	&lt;dt&gt;Do I have to pass set an image path for the marker?&lt;/dt&gt;&#xD;
	&lt;dd&gt;Yes. You can amend that in the source code*, just check for the image path where the IMG tag is created and only add it if the path is defined.&lt;/dd&gt;&#xD;
	&lt;dt&gt;How do I set the zoom level where clusters become active?&lt;/dt&gt;&#xD;
	&lt;dd&gt;The minimum level at which clusters are visible is set through the maxZoom property. &lt;b&gt;Note:&lt;/b&gt; This property also affects the click action of the clusters, if you click on a cluster pin and the zoom level exceeds the maxZoom, the zoom is reset. Again, you can amend this in the source code*, it's not configurable.&lt;/dd&gt;&#xD;
	&lt;dt&gt;On a small screen clicking a cluster doesn't zoom in&lt;/dt&gt;&#xD;
	&lt;dd&gt;When setting Google Maps to show a boundary it tries to maintain spacing between that boundary and the edge of the container. This can be a pain on small screens because we're short on screen space already, to work around this for the cluster markers we again need to go into the source code*, we need to store the maps current zoom level and then test it once the boundary has been set. If the zoom level has not been changed then increase the zoom level manually.&lt;/dd&gt;&#xD;
	&lt;dt&gt;Clicking on a cluster of a single pin zooms in too far&lt;/dt&gt;&#xD;
	&lt;dd&gt;The easiest way to avoid this is to set the maximum zoom level of the Google Map.&lt;/dd&gt;&#xD;
	&lt;dt&gt;Can I set the line-height of a ClusterMarker?&lt;/dt&gt;&#xD;
	&lt;dd&gt;Weirdly, no. The line-height is being used to vertically align the counter so is set to match the height. If you want to change that you have to got into the source. For the other options you can pass in inherit to override defaults.&lt;/dd&gt;&#xD;
&lt;/dl&gt;&#xD;
&#xD;
&lt;p&gt;*&lt;a href="https://github.com/ryanand26/markerclustererplus"&gt;Amended source code (GitHub)&lt;/a&gt;&#xD;
&#xD;
&lt;h2&gt;MarkerWithLabel&lt;/h2&gt;&#xD;
&#xD;
&lt;dl&gt;&#xD;
	&lt;dt&gt;Can I set the pin background images / hover states though CSS?&lt;/dt&gt;&#xD;
	&lt;dd&gt;Pin images can be null, this allows us to set the images through CSS and set hover states. When doing this you might want to set a background size property to enforce the pin sizes. &lt;b&gt;Note:&lt;/b&gt; IE11 does not render SVG markers correctly.&lt;/dd&gt;&#xD;
	&lt;dt&gt;Why do marker labels show through other markers?&lt;/dt&gt;&#xD;
	&lt;dd&gt;The labels do not exist in the same layer as their Google Markers so do not obey the same z-index values as their partner. If you must enforce the z-index order then apply the pin styling to the marker label using background images.&lt;/dd&gt;&#xD;
	&lt;dt&gt;Setting a markers z-index puts it under other markers&lt;/dt&gt;&#xD;
	&lt;dd&gt;Markers have a zIndex already set, if you want to amend this position you probably should use the original z-index value as the start point using marker.getZIndex().&lt;/dd&gt;&#xD;
	&lt;dt&gt;Why are the pins too big on iOS?&lt;/dt&gt;&#xD;
	&lt;dd&gt;Pins size and scaledSize must be integers, strings will cause hard to debug issues with click regions.&lt;/dd&gt;&#xD;
&lt;/dl&gt;&#xD;
&#xD;
&lt;h2&gt;Centering a boundary on a point&lt;/h2&gt;&#xD;
&lt;p&gt;As mentioned markerClusterer uses boundaries to show the markers, we need a custom function to center a boundary. I've written a Gist to enable this, it's had limited testing as it didn't go into the production version but you can find it at: &lt;a href="https://gist.github.com/ryanand26/1cf83f474a1ec8774c8e"&gt;Center a boundary on a point&lt;/a&gt;.&lt;/p&gt;</content></entry><entry><title>Using jQuery.ajax rather than jQuery.load</title><link rel="alternate" href="http://looseideas.co.uk/using-ajax-rather-than-jquery-load"/><link rel="edit" href="http://looseideas.co.uk/using-ajax-rather-than-jquery-load/atom"/><author><name>Ryan Mitchell</name><uri>http://looseideas.co.uk</uri></author><id>tag:looseideas.co.uk,2014:using-ajax-rather-than-jquery-load/1391602941</id><updated>2014-02-05T12:35:43+00:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2014-02-05T12:35:43+00:00</app:edited><published>2014-02-04T17:06:20+00:00</published><category term="ajax"/><category term="jquery"/><category term="jqueryload"/><content type="html">&lt;p&gt;jQuery.load is an incredibly useful method, but if you want to do more with the returned source than put it into a div then you may want to use jQuery.ajax directly with your own callback.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;The &lt;a href="https://github.com/jquery/jquery/blob/master/src/ajax/load.js"&gt;source code for the load method&lt;/a&gt; is a great starting point for writing your own callback, in particular how the 'done' callback selects the items to append;&lt;/p&gt;&#xD;
&#xD;
&lt;code&gt;jQuery("&amp;lt;div&amp;gt;").append( jQuery.parseHTML( responseText ) ).find( selector );&lt;/code&gt;&#xD;
&#xD;
&lt;p&gt;This is most likely what you're looking to amend by using your own callback. The parseHTML method creates an HTML fragment and then appends it to a div (this div is an orphan, it is never inserted into the DOM).&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;You may, for example want to run two selects;&lt;/p&gt;&#xD;
&#xD;
&lt;code&gt;tempDiv = jQuery("&amp;lt;div&amp;gt;").append(jQuery.parseHTML( responseText ));&#xD;
&#xD;
someResult = tempDiv.find( selector1 );&#xD;
someOtherResult = tempDiv.find( selector2 );&lt;/code&gt;</content></entry><entry><title>iOS 7 and 412 precondition failed</title><link rel="alternate" href="http://looseideas.co.uk/ios-7-412-precondition-failed"/><link rel="edit" href="http://looseideas.co.uk/ios-7-412-precondition-failed/atom"/><author><name>Ryan Mitchell</name><uri>http://looseideas.co.uk</uri></author><id>tag:looseideas.co.uk,2014:ios-7-412-precondition-failed/1389872102</id><updated>2014-01-16T11:35:02+00:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2014-08-21T10:42:07+01:00</app:edited><published>2014-01-16T11:35:02+00:00</published><category term="ajax"/><category term="ios7"/><category term="safari"/><content type="html">&lt;p&gt;With every release of iOS there tend to be some gremlins lurking in Safari, iOS 7 was no different.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;When first testing the site I've been building in iOS 7 I was getting a failure when resubmitting an AJAX POST request, the response was 412 (Precondition Failed).&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Eventually I found &lt;a href="http://freestyle-developments.co.uk/blog/?p=11"&gt;this issue explained related to a MooTools issue&lt;/a&gt;.&lt;/p&gt;&#xD;
&#xD;
&lt;blockquote cite="http://freestyle-developments.co.uk/blog/?p=11"&gt; &#xD;
&lt;p&gt;"Safari responds to etags properly and adds "If-None-Match" and "If-Modified-Since" headers to another request for the same file. This makes Apache respond with a 412 status (Precondition Failed) as it should do for "post" requests (according to RFC 2616)."&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;"Unfortunately Safari doesn't then deal with the 412 as it does with a 304 (Not Modified). It doesn't grab what it has in the cache and put it in the response, it gives you nothing."&lt;/p&gt;&#xD;
&lt;/blockquote&gt; &#xD;
&#xD;
&lt;p&gt;The date on that blog post is 04/12/2009! There is no sign of this issue in iOS6 so maybe it's slipped through the iOS cracks and will be patched&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;&lt;strong&gt;The Fix?&lt;/strong&gt; Switch to GET and Safari will deal with the request correctly.&lt;/p&gt;</content></entry><entry><title>Using Bing Maps with Require.js</title><link rel="alternate" href="http://looseideas.co.uk/bing-maps-requirejs"/><link rel="edit" href="http://looseideas.co.uk/bing-maps-requirejs/atom"/><author><name>Ryan Mitchell</name><uri>http://looseideas.co.uk</uri></author><id>tag:looseideas.co.uk,2013:bing-maps-requirejs/1382364089</id><updated>2013-10-21T15:01:29+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2014-08-19T12:06:43+01:00</app:edited><published>2013-10-20T12:00:00+01:00</published><category term="bing-maps"/><category term="requirejs"/><content type="html">&lt;p&gt;Recently I've been doing quite a lot of work with Bing Maps. Not every page on the site requires the map API so we've been attempting to use require.js, which we already have, to maintain that dependancy.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;As usual it's more complicated than we'd hoped. Bing Maps provides a callback hook that we can use with the async plugin of require.js, however the callback fires before the maps are actually ready to use. The Microsoft object is defined but the Maps and Location objects are not. This led us to implement polling to check for these properties before resolving a deferred.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;&lt;strong&gt;Why this is bad:&lt;/strong&gt; The require module is now returning a promise rather than the maps declaration that you might expect to be returned. In practice this is manageable because by using the deferred our code can continue regardless of the Maps loaded state.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;I've created a sample Gist of how this can work, although for production you may also want to handle the failure case and reject the deferred.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;&lt;a href="https://gist.github.com/ryanand26/7084108"&gt;Gist: https://gist.github.com/ryanand26/7084108&lt;/a&gt;&lt;/p&gt;</content></entry><entry><title>An alternative to jQuery.load</title><link rel="alternate" href="http://looseideas.co.uk/alternative-to-jquery-load"/><link rel="edit" href="http://looseideas.co.uk/alternative-to-jquery-load/atom"/><author><name>Ryan Mitchell</name><uri>http://looseideas.co.uk</uri></author><id>tag:looseideas.co.uk,2013:post/1373024984</id><updated>2013-07-08T10:52:37+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2014-08-19T12:06:34+01:00</app:edited><published>2013-07-05T12:44:14+01:00</published><category term="ajax"/><category term="iframe"/><category term="jquery-load"/><content type="html">&lt;hr /&gt;&#xD;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;a href="/using-ajax-rather-than-jquery-load"&gt;Are you looking to use jquery.ajax rather than jquery.load? Click here. &lt;/a&gt; The post below talks about using an iFrame as an alternative to AJAX.&lt;/p&gt;&#xD;
&lt;hr /&gt;&#xD;
&#xD;
&lt;p&gt;A very long time ago, 2010 maybe, I was asked to build a site with an "app like feel", which seemed to mean "we don't like page refreshes". At the time we used AJAX, we had control over the HTML generation so could strip everything but the HTML server-side. More recently however I was asked to do a similar thing, but without the ability to change the skeleton markup.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;The primary issue with adding a full set of markup into an existing page is that the script tags will automatically be executed. The jQuery load method gets around this by removing the script tags from the HTML string, but everything else is added to the document. If you specify an ID then jQuery will add this HTML into the DOM and then select the element.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;It's a very useful function but can we do the same thing with an iFrame, and are there any advantages in doing so?&lt;/p&gt;&#xD;
&#xD;
&lt;h2&gt;How&lt;/h2&gt;&#xD;
&lt;p&gt;We commonly use iFrames for showing content from another domain. This commonly limits the communication between the parent and child pages due to the cross-domain policies. However pages on the same domain don't have that limitation, we can access the content of the child frame directly from the parent page.&lt;/p&gt;&#xD;
&#xD;
&lt;code&gt;&#xD;
frame = document.getElementsByTagName('iframe');&#xD;
innerDoc = frame.contentDocument || frame.contentWindow.document;&#xD;
// example select in the child frame&#xD;
elem = innerDoc.getElementById('anElementsId');&#xD;
&lt;/code&gt;&#xD;
&#xD;
&lt;h2&gt;Why&lt;/h2&gt;&#xD;
&lt;p&gt;But why might we want to use an iFrame rather than jQuery.load or a similar AJAX method? To my mind there are &lt;strong&gt;very few reasons to do this&lt;/strong&gt; but biggest benefit is that you're able to to run more complex and multiple selects rather than being limited to the ID selector.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;In this method the child frame will load fully, all scripts will execute. The analytics scripts will run and the page would be rendered fully. This makes it more expensive in bandwidth and memory so remove the iFrames when you're done (watch out for leaks) and this memory should be released...&lt;/p&gt;</content></entry></feed>
