<?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/2008/12/making-separate-components-wor.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,2008://34.34534-</id>
  <updated>2009-11-16T15:23:02Z</updated>
  <title>Comments for Making Components Work Together (http://www.insideria.com/2008/12/making-separate-components-wor.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.34534</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.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=34534" title="Making Components Work Together" />
    <published>2008-12-05T02:18:45Z</published>
    <updated>2008-12-05T03:30:38Z</updated>
    <title>Making Components Work Together</title>
    <summary>This post is for anyone who has found themselves in the situation where they have an existing Flash component that they can&apos;t embed in their Flash/Flex application, although they still want/need to use them together.   </summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[This post is for anyone who has found themselves in the situation where they have an existing Flash component that they can't embed in their Flash/Flex application, although they still want/need to use them together.   
<br/><br/>

In this example, we'll create a Flex application that uses the <a href="http://code.google.com/apis/maps/documentation/flash/">Google Maps API for Flash</a>, which communicates with the <a target="_blank" href="http://code.google.com/apis/maps/documentation/reference.html#GStreetviewOverlay">Google Street View API</a> to create a seamless experience.
<br/><br/>
The Google Street View components are available directly in the Google Maps javascript API, however they are not directly available through the Flash API.  Even though they aren't available directly in the Flash API, that doesn't mean that you can't use them together.   Through ExternalInterface, you can still make those the two work together seamlessly.
<br/><br/>
Take a look at this example.   Any time you click on the Flash-based map, the street view below it will update to show the location that you clicked on.   Go ahead and try it out... If you click on an area that doesn't support street view, then you'll get a message stating that the panorama is not available.
<br/><br/>
<iframe src="http://www.tricedesigns.com/portfolio/googlestreetview/main.html" frameborder="1" height="600" width="525"></iframe>
<br/><br/>
Now, let's take a look at how it all works together.   I started with some simple examples from the <a target="_blank" href="http://code.google.com/apis/maps/documentation/examples/index.html">Google Maps API examples page</a>.
<br/><br/>
The Flex application is pretty simple.  There's just a map instance.  When the map loads, the map navigation controls are added, and the map is centered on the lat/lon coordinate (38.900218,-77.036562), which is directly in front of the <a target="_blank" href="http://www.whitehouse.gov/">white house</a> in Washington, DC, and a marker is added at that position. 

<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:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>" 
  layout="<span class="quote">vertical</span>"
  paddingBottom="<span class="quote">0</span>"
  paddingLeft="<span class="quote">0</span>"
  paddingRight="<span class="quote">0</span>"
  paddingTop="<span class="quote">0</span>"
  verticalGap="<span class="quote">0</span>" 
  viewSourceURL="<span class="quote">srcview/index.html</span>"&gt;

  &lt;mx:Script&gt;
      &lt;![CDATA[
        <span class="category1">import</span> com.google.maps.overlays.Marker;
        <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.InfoWindowOptions;
        <span class="category1">import</span> com.google.maps.MapMouseEvent;
     
        <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> marker : Marker;
  
      <span class="category1">private</span> <span class="category1">function</span> onMapReady(event:Event):<span class="category1">void</span> 
      {
         <span class="category1">var</span> centerLL : LatLng = <span class="category1">new</span> LatLng(38.900218,-77.036562);
          
         map.setCenter( centerLL, 18, 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());
         map.addEventListener(MapMouseEvent.CLICK, onMapClick);
         
         marker = <span class="category1">new</span> Marker( centerLL );
         map.addOverlay( marker );
       }
      
      <span class="category1">private</span> <span class="category1">function</span> onMapClick(event:MapMouseEvent):<span class="category1">void</span> 
      {
         marker.setLatLng( event.latLng );
         ExternalInterface.<span class="category2">call</span>( "<span class="quote">setPanorama</span>", event.latLng.lat(), event.latLng.lng() );
       }
      
      ]]&gt;
  &lt;/mx:Script&gt;

  &lt;maps:Map 
    xmlns:maps="<span class="quote">com.google.maps.*</span>" 
    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_here</span>"
    /&gt;
       
  &lt;mx:ApplicationControlBar <span class="category2">width</span>="<span class="quote">100%</span>" cornerRadius="<span class="quote">0</span>"&gt;
    
    &lt;mx:Text 
      <span class="category2">x</span>="<span class="quote">5</span>" <span class="category2">y</span>="<span class="quote">4</span>" <span class="category2">width</span>="<span class="quote">100%</span>" <span class="category2">height</span>="<span class="quote">100%</span>" 
      <span class="category2">text</span>="<span class="quote">Click anywhere on the map to update the street view.</span>" 
      <span class="category2">selectable</span>="<span class="quote">false</span>"  fontWeight="<span class="quote">bold</span>" fontSize="<span class="quote">12</span>"/&gt;
    
  &lt;/mx:ApplicationControlBar&gt; 
  
&lt;/mx:<span class="category2">Application</span>&gt;
  </pre>
</code>

</div></div> 

Whenever a MapMouseEvent.Click event happens on the mouse (the user clicks on the map), the marker moves to the click position, and the street view panorama is updated to show that click location.   
<br/><br/>
Below, you'll find the additions to the HTML page that contains the Flex application instance.  You can see that when the page initializes, then the street view panorama is created and is centered to display the <a target="_blank" href="http://www.whitehouse.gov/">white house</a>.
<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;script src="<span class="quote">http://maps.google.com/maps?file=api&amp;amp;v=2.x&amp;amp;key=api_key_here</span>" <span class="category2">type</span>="<span class="quote">text/javascript</span>"&gt;&lt;/script&gt;
&lt;script <span class="category2">type</span>="<span class="quote">text/javascript</span>"&gt; 

<span class="category1">var</span> myPano;   
<span class="category1">var</span> panoClient;
<span class="category1">var</span> nextPanoId;


<span class="category1">function</span> <span class="category2">initialize</span>()
{
   <span class="category1">var</span> whiteHouse = <span class="category1">new</span> GLatLng(38.900218,-77.036562);
   <span class="category1">var</span> whiteHousePOV = {yaw:180,pitch:0};
   
   panoClient = <span class="category1">new</span> GStreetviewClient();      
   
   myPano = <span class="category1">new</span> GStreetviewPanorama(document.getElementById("<span class="quote">pano</span>"));
   myPano.setLocationAndPOV(whiteHouse, whiteHousePOV);
   GEvent.<span class="category2">addListener</span>(myPano, "<span class="quote">error</span>", handleNoFlash);  
   panoClient.getNearestPanorama(whiteHouse, showPanoData);
}


<span class="category1">function</span> showPanoData(panoData) 
{
   <span class="category1">if</span> (panoData.code != 200) {
      GLog.write('<span class="quote">showPanoData: Server rejected with code: </span>' + panoData.code);
      <span class="category1">return</span>;
    }
   
   myPano.setLocationAndPOV(panoData.location.latlng);
}

<span class="category1">function</span> handleNoFlash(errorCode) 
{
   <span class="category1">if</span> (errorCode == 603) {
      alert("<span class="quote">Error: Flash doesn't appear to be supported by your browser</span>");
      <span class="category1">return</span>;
    }
}  

<span class="category1">function</span> setPanorama( lat, lon ) 
{
    panoClient.getNearestPanorama(<span class="category1">new</span> GLatLng(lat, lon), showPanoData);
}

&lt;/script&gt;

&lt;!-- 
And the flex application embed statements would go here
--&gt;

&lt;div id="<span class="quote">pano</span>" style="<span class="quote">width:100%;height:100%</span>" &gt;&lt;/div&gt;</pre>
</code>

</div></div> 



The Flex application communicates with the street view panorama through the ExternalInterface class, which allows us to invoke a javascript method.
<br/><br/>
<pre>ExternalInterface.call( "setPanorama", event.latLng.lat(), event.latLng.lng() );</pre>
<br/>
This calls into the setPanorama javascript function shown below, which calls into the panoClient.getNearestPanorama() function.  The callback of this method is the showPanoData() function.   If panorama data is available for the current location, then the panorama gets updated.  If not, then a message is displayed in the error log.

<br/><br/>
Hopefully this post shows you how you can make separate components work together in your own applications.  

<br/><br/>

<strong>Related Links:</strong>
<br/><br/>
Launch Demo:<br/>
<a target="_blank" href="http://www.tricedesigns.com/portfolio/googlestreetview/main.html">http://www.tricedesigns.com/portfolio/googlestreetview/main.html</a>
<br/><br/>
Source Code:<br/>
<a target="_blank" href="http://www.tricedesigns.com/portfolio/googlestreetview/srcview/index.html">http://www.tricedesigns.com/portfolio/googlestreetview/srcview/index.html</a>
<br/><br/>
Google Maps Flash API:<br/>
<a target="_blank" href="http://code.google.com/apis/maps/documentation/flash/">http://code.google.com/apis/maps/documentation/flash/</a>
<br/><br/>
Google Street View API:<br/>
<a target="_blank" href="http://code.google.com/apis/maps/documentation/reference.html#GStreetviewOverlay">http://code.google.com/apis/maps/documentation/reference.html#GStreetviewOverlay</a>
<br/><br/>
Google Maps JavaScript API:<br/>
<a target="_blank" href="http://code.google.com/apis/maps/">http://code.google.com/apis/maps/</a>
<br/><br/>
___________________________________<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><br/><br/>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2048217</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2048217" />
    <title>Comment from Gady on 2008-12-05</title>
    <author>
        <name>Gady</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>This is excellent information. Also useful would be to embed StreetView within the Flex app using ExternalInterface, like displaying it in a TitleWindow. Is this possible, or do we have to continue waiting for the Flash API to support StreetView?</p>]]>
    </content>
    <published>2008-12-05T14:29:56Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2048218</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2048218" />
    <title>Comment from Andrew Trice on 2008-12-05</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>Thanks!</p>

<p>It has to be in a separate HTML container.  You can't embed it directly within a Flash/Flex application yet.  You can layer it using the html iframe trick, but that has layering/wmode issues on different platforms and browsers... This isn't a shortcoming of the API, but rather how some browser implementations render layered plugin-based content.</p>]]>
    </content>
    <published>2008-12-05T14:37:50Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2048271</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2048271" />
    <title>Comment from Forrest on 2008-12-06</title>
    <author>
        <name>Forrest</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Andrew,<br />
thanks much for the demo! ...</p>

<p>I was bugging Pamela Fox for just this on the google-groups (http://groups.google.com/group/google-maps-api-for-flash) for just this demo.</p>

<p>Note that I'm doing some work with SAP (yes, that large clunky <br />
German Enterprise Resource Planning software package) and have somewhat succesfully integrated Maps & Google StreetView with SAP CRM (ref my youtube: <br />
<a href="http://www.youtube.com/watch?v=VzfpdlrNw3Q)">http://www.youtube.com/watch?v=VzfpdlrNw3Q)</a> </p>

<p>...using Google Maps is an alternative to using the ESRI implementation where I work...and note:   Municipal infrastructure support entities, cities, counties, etc across the world have a keen interest in Street View...pot hole locations, street signs & lights, man hole covers, location of dead-animals, etc, etc can be previewed from Street View without first rolling a truck and crew to simply asses the situation...I've first saw Street View being used in Mineapolis MN at their 311 call center.</p>]]>
    </content>
    <published>2008-12-06T23:20:37Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2048368</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2048368" />
    <title>Comment from IB* on 2008-12-08</title>
    <author>
        <name>IB*</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Awesome post!</p>

<p>However, I keep getting a 1046 error on the "onMapClick" function line: </p>

<p>"1046: Type was not found or was not a compile-time constant: MapMouseEvent."</p>

<p>Any idea on how to work around this issue?</p>

<p>Thx,</p>

<p>IB*</p>]]>
    </content>
    <published>2008-12-08T16:16:39Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2048373</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2048373" />
    <title>Comment from Andrew Trice on 2008-12-08</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>Make sure you have the map_flex_1_8a.swc (or newer) file in your project compile path.  It should either be in the "libs" folder, or set in the project properties (if you are in flex builder).  This error only happens if the compiler can't find the source/swc.</p>]]>
    </content>
    <published>2008-12-08T16:44:57Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2051707</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2051707" />
    <title>Comment from John Middendorf on 2009-01-25</title>
    <author>
        <name>John Middendorf</name>
        <uri>http://www.lynxgeos.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.lynxgeos.com">
        <![CDATA[<p>Hi Andrew-</p>

<p>You mentioned that the Streetview had to be in a separate html container.  Is it possible to have the specific streetview scene appear in a separate browser window originating from a Flash action?  Any hints on doing this within the context of the external interface calls would be appreciated. </p>

<p>cheers</p>]]>
    </content>
    <published>2009-01-25T20:44:52Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2057192</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2057192" />
    <title>Comment from creek on 2009-04-08</title>
    <author>
        <name>creek</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Andrew, I have built a stand-alone diagramming tool(with basic functions like drawing lines, circles, placing objects, etc). I want to have google map as the background for the tool. Is it possible that I can integrate my swf of diagramming tool google maps using flex ? Any pointers to relevant material is greatly appreciated ! <br />
Thanks.</p>]]>
    </content>
    <published>2009-04-08T18:41:15Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2057242</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2057242" />
    <title>Comment from Fernando on 2009-04-09</title>
    <author>
        <name>Fernando</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Using maven to install swc library. I cant find a place for downloading with maven this library. Do you know anything about it?</p>]]>
    </content>
    <published>2009-04-09T07:58:37Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2067795</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2067795" />
    <title>Comment from This work for v2. But it doesn&apos;t work for v3. on 2009-07-05</title>
    <author>
        <name>This work for v2. But it doesn&apos;t work for v3.</name>
        <uri>http://club.khmer.org/headline2.php</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://club.khmer.org/headline2.php">
        <![CDATA[<p>I am working with google map api v3. I am trying to find document that show me how to hook up with GStreetviewPanorama of map api 3.</p>

<p>Do you know where I can get this documentation?</p>]]>
    </content>
    <published>2009-07-05T16:01:44Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34534-comment:2152830</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34534" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/making-separate-components-wor.html#comment-2152830" />
    <title>Comment from Chris on 2009-10-23</title>
    <author>
        <name>Chris</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Andrew,</p>

<p>This is a great tutorial. I followed your example and have the Street View displaying in my Flex project. </p>

<p>Unfortunately, the Street View is always visible because it is in a DIV in the HTML wrapper. However, my map is visible only after the user clicks a button. I'm not experienced with Javascript at all. Is there a way of dynamically creating and removing the div in the HTML wrapper? What's the best way to make the Street View visible only when my map is visible? My map is only visible when it's selected from the ViewStack.</p>

<p>If you can point me in the right direction, I'd really appreciate it. Any suggestions would be great.</p>

<p>Again, thank you for your excellent work.</p>

<p>Thank you!</p>

<p>-Chris</p>]]>
    </content>
    <published>2009-10-23T21:21:19Z</published>
  </entry>

</feed
