<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2009://34.36342-</id>
  <updated>2009-11-16T14:59:00Z</updated>
  <title>Comments for Having Fun With Google Maps Flash API (http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.36342</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=36342" title="Having Fun With Google Maps Flash API" />
    <published>2009-05-27T02:47:32Z</published>
    <updated>2009-05-27T14:31:44Z</updated>
    <title>Having Fun With Google Maps Flash API</title>
    <summary>Here&apos;s a trick combining graphics filters with Google maps for some interesting effects.   They don&apos;t necessarily make it easier to read the maps, nor do they have a lot of value, but they look interesting, and are fun to play with.   I can&apos;t claim this idea as my own.   I just randomly stumbled across this post on axismaps.com, and figured I&apos;d throw together a Flex example showing how to do it. </summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[Here's a silly post that contains a trick combining <a href="http://www.insideria.com/2008/02/flex-graphics-tricks-part-3-gr.html" target="_blank">graphics filters</a> with Google maps for some interesting effects.   They don't necessarily make it easier to read the maps, nor do they have a lot of value, but they look interesting, and are fun to play with.   
<br/><br/>

I can't claim this idea as my own.   I just randomly stumbled across <a href="http://www.axismaps.com/blog/2009/02/spicing-up-google-maps-in-flash/" target="_blank">this post on axismaps.com</a>, and figured I'd throw together a Flex example showing how to do it.   
<br/><br/>

The effects are applied directly to the map tiles, not the entire map component, so all of the other controls still look like normal.  Let's take a look at it in action... You can either select a preset, or adjust the slider values to change the filters applied to the map instance.
<br/><br/>

<iframe width="100%" height="500" src="http://www.tricedesigns.com/portfolio/googlefilters/"></iframe>
<br/><br/>

The original post has some other interesting effects which can be achieved through various permutations of the input array for the ColorMatrixFilter instance.   This example is pretty basic, and only manipulates the red, green, and blue channels independently.
<br/><br/>

Here's how to make it all work.   It's really pretty simple.  This example just creates color matrix filters and applies them to the mapping components.   I started with the <a href="http://code.google.com/apis/maps/documentation/flash/examples/index.html" target="_blank">samples for the Google Maps API</a>, and just started applying different filters.
<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;mx:<span class="category2">Application</span> 
   xmlns:maps="<span class="quote">com.google.maps.*</span>" 
   xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>" 
   layout="<span class="quote">absolute</span>"&gt;
   
   &lt;mx:Style&gt;
      <span class="category2">Application</span> {
          <span class="category2">backgroundColor</span>: #999999;
          themeColor: #cccc00;
       }
      
      Panel {
          <span class="category2">borderColor</span>: #cccccc;
          borderAlpha: 0.85;
          borderThicknessLeft: 1;
          borderThicknessTop: 0;
          borderThicknessBottom: 1;
          borderThicknessRight: 1;
          cornerRadius: 3;
          backgroundAlpha: 0.92;
          highlightAlphas: 0.26, 0;
       }
   &lt;/mx:Style&gt;
   
   &lt;mx:Script&gt;
       &lt;![CDATA[
         <span class="category1">import</span> com.google.maps.services.ClientGeocoder;
         <span class="category1">import</span> mx.controls.Alert;
         <span class="category1">import</span> com.google.maps.MapMouseEvent;
         <span class="category1">import</span> com.google.maps.services.GeocodingEvent;
         <span class="category1">import</span> com.google.maps.controls.MapTypeControl;
         <span class="category1">import</span> com.google.maps.controls.PositionControl;
         <span class="category1">import</span> com.google.maps.controls.ZoomControl;
         <span class="category1">import</span> com.google.maps.LatLng;
         <span class="category1">import</span> com.google.maps.Map;
         <span class="category1">import</span> com.google.maps.MapEvent;
         <span class="category1">import</span> com.google.maps.MapType;
         
         <span class="category1">private</span> <span class="category1">var</span> geocoder : ClientGeocoder;
         
         <span class="category1">private</span> <span class="category1">function</span> onMapReady(event:Event):<span class="category1">void</span> 
         {
             map.setCenter( <span class="category1">new</span> LatLng( 38.895108,-77.035961 ), 14, MapType.NORMAL_MAP_TYPE);
             map.addControl(<span class="category1">new</span> ZoomControl());
             map.addControl(<span class="category1">new</span> PositionControl());
             map.addControl(<span class="category1">new</span> MapTypeControl());
             geocoder = <span class="category1">new</span> ClientGeocoder();
             geocoder.addEventListener( GeocodingEvent.GEOCODING_SUCCESS, onGeocodeSuccess);
             geocoder.addEventListener( GeocodingEvent.GEOCODING_FAILURE, onGeocodeFault );
          }
         
         <span class="category1">private</span> <span class="category1">function</span> doGeocode():<span class="category1">void</span> 
         {
             geocoder.geocode(searchString.<span class="category2">text</span>);
          }
         
         <span class="category1">private</span> <span class="category1">function</span> onGeocodeSuccess( event : GeocodingEvent ) : <span class="category1">void</span>
         {
             <span class="category1">var</span> placemarks:<span class="category2">Array</span> = event.response.placemarks;
             <span class="category1">if</span> (placemarks.<span class="category2">length</span> &gt; 0)
                map.setCenter(placemarks[0].point);
          }
         
         <span class="category1">private</span> <span class="category1">function</span> onGeocodeFault( event : GeocodingEvent ) : <span class="category1">void</span>
         {
             Alert.<span class="category2">show</span>("<span class="quote">Geocoding failed</span>");
             <span class="category2">trace</span>(event);
             <span class="category2">trace</span>(event.<span class="category2">status</span>);
          }
       
          <span class="category1">private</span> <span class="category1">function</span> setFilter() : <span class="category1">void</span>
          {
              <span class="category1">var</span> <span class="category2">filter</span> : ColorMatrixFilter = <span class="category1">new</span> ColorMatrixFilter();
              <span class="category1">var</span> matrix:<span class="category2">Array</span> = <span class="category1">new</span> <span class="category2">Array</span>();
              matrix = matrix.<span class="category2">concat</span>([r.value, 0, 0, 0, 0]); <span class="linecomment">// red</span>
              matrix = matrix.<span class="category2">concat</span>([0, g.value, 0, 0, 0]); <span class="linecomment">// green</span>
              matrix = matrix.<span class="category2">concat</span>([0, 0, b.value, 0, 0]); <span class="linecomment">// blue</span>
              matrix = matrix.<span class="category2">concat</span>([0, 0, 0, a.value, 0]); <span class="linecomment">// alpha</span>
              <span class="category2">filter</span>.matrix = matrix;
              setMapFilter( <span class="category2">filter</span> );
           }
          
          <span class="category1">private</span> <span class="category1">function</span> setFilterPreset() : <span class="category1">void</span>
          {
              <span class="category1">switch</span>  ( preset.selectedIndex )
              {
                  <span class="category1">case</span> 1: <span class="linecomment">// grayscale</span>
                     <span class="category1">var</span> red:<span class="category2">Number</span> = 0.3086; <span class="linecomment">// luminance contrast value for red</span>
                     <span class="category1">var</span> green:<span class="category2">Number</span> = 0.694; <span class="linecomment">// luminance contrast value for green</span>
                     <span class="category1">var</span> blue:<span class="category2">Number</span> = 0.0820; <span class="linecomment">// luminance contrast value for blue</span>
                     <span class="category1">var</span> cmf:ColorMatrixFilter = <span class="category1">new</span> ColorMatrixFilter([red, green, blue, 0, 0, 
                                                                        red, green, blue, 0, 0, 
                                                                        red, green, blue, 0, 0, 
                                                                        0, 0, 0, 1, 0]);
                     setMapFilter( cmf );
                     <span class="category1">return</span>;
                     <span class="category1">break</span>;
                  <span class="category1">case</span> 2: <span class="linecomment">// Blood</span>
                     r.value = .97;
                     g.value = .05;
                     b.value = .05;
                     a.value = .9;
                     <span class="category1">break</span>;
                  <span class="category1">case</span> 3: <span class="linecomment">// Green</span>
                     r.value = .05;
                     g.value = .65;
                     b.value = .05;
                     a.value = .9;
                     <span class="category1">break</span>;
                  <span class="category1">case</span> 4: <span class="linecomment">// Yellow</span>
                     r.value = .95;
                     g.value = .95;
                     b.value = .05;
                     a.value = .9;
                     <span class="category1">break</span>;
                  <span class="category1">default</span>:
                     r.value = 1;
                     g.value = 1;
                     b.value = 1;
                     a.value = 1;
                     <span class="category1">break</span>;
               }   
              setFilter();
           }
          
          <span class="category1">private</span> <span class="category1">function</span> setMapFilter( <span class="category2">filter</span> : ColorMatrixFilter ) : <span class="category1">void</span>
          {
              <span class="category1">var</span> s1:Sprite = map.getChildAt(1) as Sprite;
              <span class="category1">var</span> s2:Sprite = s1.getChildAt(0) as Sprite;
              s2.filters = [ <span class="category2">filter</span> ];   
           }
          
       ]]&gt;
   &lt;/mx:Script&gt;

   &lt;mx:ApplicationControlBar dock="<span class="quote">true</span>" defaultButton="<span class="quote">{ searchButton }</span>"&gt;
      
      &lt;mx:TextInput id="<span class="quote">searchString</span>" <span class="category2">width</span>="<span class="quote">150</span>" /&gt;
      &lt;mx:<span class="category2">Button</span> click="<span class="quote">doGeocode()</span>" <span class="category1">label</span>="<span class="quote">Find!</span>" id="<span class="quote">searchButton</span>" /&gt;
      
   &lt;/mx:ApplicationControlBar&gt;

   &lt;maps:Map id="<span class="quote">map</span>" mapevent_mapready="<span class="quote">onMapReady(event)</span>" 
      <span class="category2">width</span>="<span class="quote">100%</span>" <span class="category2">height</span>="<span class="quote">100%</span>" key="<span class="quote">API key goes here</span>"/&gt;

   &lt;mx:Panel 
      top="<span class="quote">50</span>" right="<span class="quote">10</span>" 
      <span class="category2">width</span>="<span class="quote">250</span>" <span class="category2">height</span>="<span class="quote">200</span>"
      layout="<span class="quote">vertical</span>"
      title="<span class="quote">Map Effects</span>"&gt;
      
      &lt;mx:Form <span class="category2">width</span>="<span class="quote">100%</span>" <span class="category2">height</span>="<span class="quote">100%</span>"&gt;
         
         &lt;mx:FormItem <span class="category1">label</span>="<span class="quote">preset:</span>"&gt;
            &lt;mx:ComboBox id="<span class="quote">preset</span>" 
               dataProvider="<span class="quote">[ 'Normal', 'Gray Scale', 'Blood', 'Green', 'Yellow' ]</span>" 
               change="<span class="quote">setFilterPreset()</span>" /&gt;      
         &lt;/mx:FormItem&gt;
         
         
         &lt;mx:FormItem <span class="category1">label</span>="<span class="quote">red:</span>"&gt;
            &lt;mx:HSlider 
               minimum="<span class="quote">0</span>" maximum="<span class="quote">2</span>" value="<span class="quote">1</span>" 
               id="<span class="quote">r</span>" change="<span class="quote">setFilter()</span>" 
               liveDragging="<span class="quote">true</span>"  <span class="category2">width</span>="<span class="quote">140</span>"/&gt;      
         &lt;/mx:FormItem&gt;
         
         
         &lt;mx:FormItem <span class="category1">label</span>="<span class="quote">green:</span>"&gt;
            &lt;mx:HSlider 
               minimum="<span class="quote">0</span>" maximum="<span class="quote">2</span>" value="<span class="quote">1</span>" 
               id="<span class="quote">g</span>" change="<span class="quote">setFilter()</span>" 
               liveDragging="<span class="quote">true</span>"  <span class="category2">width</span>="<span class="quote">140</span>"/&gt;      
         &lt;/mx:FormItem&gt;
         
         
         &lt;mx:FormItem <span class="category1">label</span>="<span class="quote">blue:</span>"&gt;
            &lt;mx:HSlider 
               minimum="<span class="quote">0</span>" maximum="<span class="quote">2</span>" value="<span class="quote">1</span>" 
               id="<span class="quote">b</span>" change="<span class="quote">setFilter()</span>" 
               liveDragging="<span class="quote">true</span>"  <span class="category2">width</span>="<span class="quote">140</span>"/&gt;      
         &lt;/mx:FormItem&gt;
         
         
         &lt;mx:FormItem <span class="category1">label</span>="<span class="quote">alpha:</span>"&gt;
            &lt;mx:HSlider 
               minimum="<span class="quote">0</span>" maximum="<span class="quote">1</span>" value="<span class="quote">1</span>" 
               id="<span class="quote">a</span>" change="<span class="quote">setFilter()</span>" 
               liveDragging="<span class="quote">true</span>"  <span class="category2">width</span>="<span class="quote">140</span>"/&gt;      
         &lt;/mx:FormItem&gt;
         
      &lt;/mx:Form&gt;
      
   &lt;/mx:Panel&gt;
   
&lt;/mx:<span class="category2">Application</span>&gt;</pre>
</code>
 
</div></div> 

___________________________________<br/>
<strong>Andrew Trice</strong><br/>
Principal Architect<br/>
<a href="http://www.cynergysystems.com" target="_blank">Cynergy Systems<br/>
http://www.cynergysystems.com</a>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2060460</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2060460" />
    <title>Comment from DannyT on 2009-05-27</title>
    <author>
        <name>DannyT</name>
        <uri>http://moov2.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://moov2.com">
        <![CDATA[<p>One good use of such a thing is accessibility concerns for those who can't see colours properly. Very cool stuff!</p>]]>
    </content>
    <published>2009-05-27T08:29:23Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2060474</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2060474" />
    <title>Comment from Brent Lamborn on 2009-05-27</title>
    <author>
        <name>Brent Lamborn</name>
        <uri>http://www.brentlamborn.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.brentlamborn.com">
        <![CDATA[<p>Nice. I like  grayscale. For me it makes the map much easier to read.</p>]]>
    </content>
    <published>2009-05-27T13:20:57Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2060517</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2060517" />
    <title>Comment from Krzysztof Kotlarski on 2009-05-27</title>
    <author>
        <name>Krzysztof Kotlarski</name>
        <uri>http://www.kotlarski.net</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.kotlarski.net">
        <![CDATA[<p>Nice one it can realy improve accessibility</p>]]>
    </content>
    <published>2009-05-27T21:11:59Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2060769</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2060769" />
    <title>Comment from Pamela Fox on 2009-05-31</title>
    <author>
        <name>Pamela Fox</name>
        <uri>http://imagine-it.org</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://imagine-it.org">
        <![CDATA[<p>Thanks, Andrew, great post!</p>

<p>Since developers can potentially create un-usable maps with this hack, we are currently requesting that all developers re-coloring their maps formally request permission:<br />
<a href="https://spreadsheets.google.com/viewform?formkey=cm0zMDkzOHZWMjJneEl2RVdkNFZRb0E6MA">https://spreadsheets.google.com/viewform?formkey=cm0zMDkzOHZWMjJneEl2RVdkNFZRb0E6MA</a></p>

<p>We've approved most of the uses so far, we just want to make sure users are getting a good experience.<br />
</p>]]>
    </content>
    <published>2009-05-31T18:45:27Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2068644</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2068644" />
    <title>Comment from shiva on 2009-07-20</title>
    <author>
        <name>shiva</name>
        <uri>http://www.googleeastereggs.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.googleeastereggs.com">
        <![CDATA[<p>Google's mapping services are chock full of secrets. For a while Google Moon had a really great one.<br />
<a href="http://www.googleeastereggs.com/">http://www.googleeastereggs.com/</a></p>]]>
    </content>
    <published>2009-07-20T17:17:15Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2139161</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2139161" />
    <title>Comment from Hitesh Agja on 2009-10-13</title>
    <author>
        <name>Hitesh Agja</name>
        <uri>http://hiteshagja.blogspot.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://hiteshagja.blogspot.com">
        <![CDATA[<p>Dear sir,</p>

<p>I have just tried your example in flex. but does not work. I dont know why filter is not applying on map. please help me.</p>]]>
    </content>
    <published>2009-10-14T06:54:21Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2139166</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2139166" />
    <title>Comment from Hitesh Agja on 2009-10-14</title>
    <author>
        <name>Hitesh Agja</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>I got my answer. I done little change in your code. I have changed setMapFilter function. I removed all three lines and just set "map.filters" property directly. It works fine. </p>

<p>I hope it will helpful to others also !</p>]]>
    </content>
    <published>2009-10-14T07:08:03Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36342-comment:2147079</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36342" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/having-fun-with-google-maps-fl.html#comment-2147079" />
    <title>Comment from Andrew Trice on 2009-10-19</title>
    <author>
        <name>Andrew Trice</name>
        <uri>http://www.tricedesigns.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.tricedesigns.com">
        <![CDATA[<p>Hitesh, this will also change the colors on the Google logo overlay.   With the logic described above, it will not change the overlays.</p>]]>
    </content>
    <published>2009-10-20T01:28:32Z</published>
  </entry>

</feed
